1package compute 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/autorest/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// SnapshotsClient is the compute Client 30type SnapshotsClient struct { 31 BaseClient 32} 33 34// NewSnapshotsClient creates an instance of the SnapshotsClient client. 35func NewSnapshotsClient(subscriptionID string) SnapshotsClient { 36 return NewSnapshotsClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewSnapshotsClientWithBaseURI creates an instance of the SnapshotsClient client. 40func NewSnapshotsClientWithBaseURI(baseURI string, subscriptionID string) SnapshotsClient { 41 return SnapshotsClient{NewWithBaseURI(baseURI, subscriptionID)} 42} 43 44// CreateOrUpdate creates or updates a snapshot. 45// Parameters: 46// resourceGroupName - the name of the resource group. 47// snapshotName - the name of the snapshot that is being created. The name can't be changed after the snapshot 48// is created. Supported characters for the name are a-z, A-Z, 0-9 and _. The max name length is 80 characters. 49// snapshot - snapshot object supplied in the body of the Put disk operation. 50func (client SnapshotsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, snapshotName string, snapshot Snapshot) (result SnapshotsCreateOrUpdateFuture, err error) { 51 if tracing.IsEnabled() { 52 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.CreateOrUpdate") 53 defer func() { 54 sc := -1 55 if result.Response() != nil { 56 sc = result.Response().StatusCode 57 } 58 tracing.EndSpan(ctx, sc, err) 59 }() 60 } 61 if err := validation.Validate([]validation.Validation{ 62 {TargetValue: snapshot, 63 Constraints: []validation.Constraint{{Target: "snapshot.SnapshotProperties", Name: validation.Null, Rule: false, 64 Chain: []validation.Constraint{{Target: "snapshot.SnapshotProperties.CreationData", Name: validation.Null, Rule: true, 65 Chain: []validation.Constraint{{Target: "snapshot.SnapshotProperties.CreationData.ImageReference", Name: validation.Null, Rule: false, 66 Chain: []validation.Constraint{{Target: "snapshot.SnapshotProperties.CreationData.ImageReference.ID", Name: validation.Null, Rule: true, Chain: nil}}}, 67 }}, 68 {Target: "snapshot.SnapshotProperties.EncryptionSettings", Name: validation.Null, Rule: false, 69 Chain: []validation.Constraint{{Target: "snapshot.SnapshotProperties.EncryptionSettings.DiskEncryptionKey", Name: validation.Null, Rule: false, 70 Chain: []validation.Constraint{{Target: "snapshot.SnapshotProperties.EncryptionSettings.DiskEncryptionKey.SourceVault", Name: validation.Null, Rule: true, Chain: nil}, 71 {Target: "snapshot.SnapshotProperties.EncryptionSettings.DiskEncryptionKey.SecretURL", Name: validation.Null, Rule: true, Chain: nil}, 72 }}, 73 {Target: "snapshot.SnapshotProperties.EncryptionSettings.KeyEncryptionKey", Name: validation.Null, Rule: false, 74 Chain: []validation.Constraint{{Target: "snapshot.SnapshotProperties.EncryptionSettings.KeyEncryptionKey.SourceVault", Name: validation.Null, Rule: true, Chain: nil}, 75 {Target: "snapshot.SnapshotProperties.EncryptionSettings.KeyEncryptionKey.KeyURL", Name: validation.Null, Rule: true, Chain: nil}, 76 }}, 77 }}, 78 }}}}}); err != nil { 79 return result, validation.NewError("compute.SnapshotsClient", "CreateOrUpdate", err.Error()) 80 } 81 82 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, snapshotName, snapshot) 83 if err != nil { 84 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "CreateOrUpdate", nil, "Failure preparing request") 85 return 86 } 87 88 result, err = client.CreateOrUpdateSender(req) 89 if err != nil { 90 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "CreateOrUpdate", result.Response(), "Failure sending request") 91 return 92 } 93 94 return 95} 96 97// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 98func (client SnapshotsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, snapshotName string, snapshot Snapshot) (*http.Request, error) { 99 pathParameters := map[string]interface{}{ 100 "resourceGroupName": autorest.Encode("path", resourceGroupName), 101 "snapshotName": autorest.Encode("path", snapshotName), 102 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 103 } 104 105 const APIVersion = "2018-06-01" 106 queryParameters := map[string]interface{}{ 107 "api-version": APIVersion, 108 } 109 110 preparer := autorest.CreatePreparer( 111 autorest.AsContentType("application/json; charset=utf-8"), 112 autorest.AsPut(), 113 autorest.WithBaseURL(client.BaseURI), 114 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}", pathParameters), 115 autorest.WithJSON(snapshot), 116 autorest.WithQueryParameters(queryParameters)) 117 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 118} 119 120// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 121// http.Response Body if it receives an error. 122func (client SnapshotsClient) CreateOrUpdateSender(req *http.Request) (future SnapshotsCreateOrUpdateFuture, err error) { 123 var resp *http.Response 124 resp, err = autorest.SendWithSender(client, req, 125 azure.DoRetryWithRegistration(client.Client)) 126 if err != nil { 127 return 128 } 129 future.Future, err = azure.NewFutureFromResponse(resp) 130 return 131} 132 133// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 134// closes the http.Response Body. 135func (client SnapshotsClient) CreateOrUpdateResponder(resp *http.Response) (result Snapshot, err error) { 136 err = autorest.Respond( 137 resp, 138 client.ByInspecting(), 139 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 140 autorest.ByUnmarshallingJSON(&result), 141 autorest.ByClosing()) 142 result.Response = autorest.Response{Response: resp} 143 return 144} 145 146// Delete deletes a snapshot. 147// Parameters: 148// resourceGroupName - the name of the resource group. 149// snapshotName - the name of the snapshot that is being created. The name can't be changed after the snapshot 150// is created. Supported characters for the name are a-z, A-Z, 0-9 and _. The max name length is 80 characters. 151func (client SnapshotsClient) Delete(ctx context.Context, resourceGroupName string, snapshotName string) (result SnapshotsDeleteFuture, err error) { 152 if tracing.IsEnabled() { 153 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.Delete") 154 defer func() { 155 sc := -1 156 if result.Response() != nil { 157 sc = result.Response().StatusCode 158 } 159 tracing.EndSpan(ctx, sc, err) 160 }() 161 } 162 req, err := client.DeletePreparer(ctx, resourceGroupName, snapshotName) 163 if err != nil { 164 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "Delete", nil, "Failure preparing request") 165 return 166 } 167 168 result, err = client.DeleteSender(req) 169 if err != nil { 170 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "Delete", result.Response(), "Failure sending request") 171 return 172 } 173 174 return 175} 176 177// DeletePreparer prepares the Delete request. 178func (client SnapshotsClient) DeletePreparer(ctx context.Context, resourceGroupName string, snapshotName string) (*http.Request, error) { 179 pathParameters := map[string]interface{}{ 180 "resourceGroupName": autorest.Encode("path", resourceGroupName), 181 "snapshotName": autorest.Encode("path", snapshotName), 182 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 183 } 184 185 const APIVersion = "2018-06-01" 186 queryParameters := map[string]interface{}{ 187 "api-version": APIVersion, 188 } 189 190 preparer := autorest.CreatePreparer( 191 autorest.AsDelete(), 192 autorest.WithBaseURL(client.BaseURI), 193 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}", pathParameters), 194 autorest.WithQueryParameters(queryParameters)) 195 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 196} 197 198// DeleteSender sends the Delete request. The method will close the 199// http.Response Body if it receives an error. 200func (client SnapshotsClient) DeleteSender(req *http.Request) (future SnapshotsDeleteFuture, err error) { 201 var resp *http.Response 202 resp, err = autorest.SendWithSender(client, req, 203 azure.DoRetryWithRegistration(client.Client)) 204 if err != nil { 205 return 206 } 207 future.Future, err = azure.NewFutureFromResponse(resp) 208 return 209} 210 211// DeleteResponder handles the response to the Delete request. The method always 212// closes the http.Response Body. 213func (client SnapshotsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 214 err = autorest.Respond( 215 resp, 216 client.ByInspecting(), 217 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 218 autorest.ByClosing()) 219 result.Response = resp 220 return 221} 222 223// Get gets information about a snapshot. 224// Parameters: 225// resourceGroupName - the name of the resource group. 226// snapshotName - the name of the snapshot that is being created. The name can't be changed after the snapshot 227// is created. Supported characters for the name are a-z, A-Z, 0-9 and _. The max name length is 80 characters. 228func (client SnapshotsClient) Get(ctx context.Context, resourceGroupName string, snapshotName string) (result Snapshot, err error) { 229 if tracing.IsEnabled() { 230 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.Get") 231 defer func() { 232 sc := -1 233 if result.Response.Response != nil { 234 sc = result.Response.Response.StatusCode 235 } 236 tracing.EndSpan(ctx, sc, err) 237 }() 238 } 239 req, err := client.GetPreparer(ctx, resourceGroupName, snapshotName) 240 if err != nil { 241 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "Get", nil, "Failure preparing request") 242 return 243 } 244 245 resp, err := client.GetSender(req) 246 if err != nil { 247 result.Response = autorest.Response{Response: resp} 248 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "Get", resp, "Failure sending request") 249 return 250 } 251 252 result, err = client.GetResponder(resp) 253 if err != nil { 254 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "Get", resp, "Failure responding to request") 255 } 256 257 return 258} 259 260// GetPreparer prepares the Get request. 261func (client SnapshotsClient) GetPreparer(ctx context.Context, resourceGroupName string, snapshotName string) (*http.Request, error) { 262 pathParameters := map[string]interface{}{ 263 "resourceGroupName": autorest.Encode("path", resourceGroupName), 264 "snapshotName": autorest.Encode("path", snapshotName), 265 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 266 } 267 268 const APIVersion = "2018-06-01" 269 queryParameters := map[string]interface{}{ 270 "api-version": APIVersion, 271 } 272 273 preparer := autorest.CreatePreparer( 274 autorest.AsGet(), 275 autorest.WithBaseURL(client.BaseURI), 276 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}", pathParameters), 277 autorest.WithQueryParameters(queryParameters)) 278 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 279} 280 281// GetSender sends the Get request. The method will close the 282// http.Response Body if it receives an error. 283func (client SnapshotsClient) GetSender(req *http.Request) (*http.Response, error) { 284 return autorest.SendWithSender(client, req, 285 azure.DoRetryWithRegistration(client.Client)) 286} 287 288// GetResponder handles the response to the Get request. The method always 289// closes the http.Response Body. 290func (client SnapshotsClient) GetResponder(resp *http.Response) (result Snapshot, err error) { 291 err = autorest.Respond( 292 resp, 293 client.ByInspecting(), 294 azure.WithErrorUnlessStatusCode(http.StatusOK), 295 autorest.ByUnmarshallingJSON(&result), 296 autorest.ByClosing()) 297 result.Response = autorest.Response{Response: resp} 298 return 299} 300 301// GrantAccess grants access to a snapshot. 302// Parameters: 303// resourceGroupName - the name of the resource group. 304// snapshotName - the name of the snapshot that is being created. The name can't be changed after the snapshot 305// is created. Supported characters for the name are a-z, A-Z, 0-9 and _. The max name length is 80 characters. 306// grantAccessData - access data object supplied in the body of the get snapshot access operation. 307func (client SnapshotsClient) GrantAccess(ctx context.Context, resourceGroupName string, snapshotName string, grantAccessData GrantAccessData) (result SnapshotsGrantAccessFuture, err error) { 308 if tracing.IsEnabled() { 309 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.GrantAccess") 310 defer func() { 311 sc := -1 312 if result.Response() != nil { 313 sc = result.Response().StatusCode 314 } 315 tracing.EndSpan(ctx, sc, err) 316 }() 317 } 318 if err := validation.Validate([]validation.Validation{ 319 {TargetValue: grantAccessData, 320 Constraints: []validation.Constraint{{Target: "grantAccessData.DurationInSeconds", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 321 return result, validation.NewError("compute.SnapshotsClient", "GrantAccess", err.Error()) 322 } 323 324 req, err := client.GrantAccessPreparer(ctx, resourceGroupName, snapshotName, grantAccessData) 325 if err != nil { 326 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "GrantAccess", nil, "Failure preparing request") 327 return 328 } 329 330 result, err = client.GrantAccessSender(req) 331 if err != nil { 332 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "GrantAccess", result.Response(), "Failure sending request") 333 return 334 } 335 336 return 337} 338 339// GrantAccessPreparer prepares the GrantAccess request. 340func (client SnapshotsClient) GrantAccessPreparer(ctx context.Context, resourceGroupName string, snapshotName string, grantAccessData GrantAccessData) (*http.Request, error) { 341 pathParameters := map[string]interface{}{ 342 "resourceGroupName": autorest.Encode("path", resourceGroupName), 343 "snapshotName": autorest.Encode("path", snapshotName), 344 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 345 } 346 347 const APIVersion = "2018-06-01" 348 queryParameters := map[string]interface{}{ 349 "api-version": APIVersion, 350 } 351 352 preparer := autorest.CreatePreparer( 353 autorest.AsContentType("application/json; charset=utf-8"), 354 autorest.AsPost(), 355 autorest.WithBaseURL(client.BaseURI), 356 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}/beginGetAccess", pathParameters), 357 autorest.WithJSON(grantAccessData), 358 autorest.WithQueryParameters(queryParameters)) 359 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 360} 361 362// GrantAccessSender sends the GrantAccess request. The method will close the 363// http.Response Body if it receives an error. 364func (client SnapshotsClient) GrantAccessSender(req *http.Request) (future SnapshotsGrantAccessFuture, err error) { 365 var resp *http.Response 366 resp, err = autorest.SendWithSender(client, req, 367 azure.DoRetryWithRegistration(client.Client)) 368 if err != nil { 369 return 370 } 371 future.Future, err = azure.NewFutureFromResponse(resp) 372 return 373} 374 375// GrantAccessResponder handles the response to the GrantAccess request. The method always 376// closes the http.Response Body. 377func (client SnapshotsClient) GrantAccessResponder(resp *http.Response) (result AccessURI, err error) { 378 err = autorest.Respond( 379 resp, 380 client.ByInspecting(), 381 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 382 autorest.ByUnmarshallingJSON(&result), 383 autorest.ByClosing()) 384 result.Response = autorest.Response{Response: resp} 385 return 386} 387 388// List lists snapshots under a subscription. 389func (client SnapshotsClient) List(ctx context.Context) (result SnapshotListPage, err error) { 390 if tracing.IsEnabled() { 391 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.List") 392 defer func() { 393 sc := -1 394 if result.sl.Response.Response != nil { 395 sc = result.sl.Response.Response.StatusCode 396 } 397 tracing.EndSpan(ctx, sc, err) 398 }() 399 } 400 result.fn = client.listNextResults 401 req, err := client.ListPreparer(ctx) 402 if err != nil { 403 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "List", nil, "Failure preparing request") 404 return 405 } 406 407 resp, err := client.ListSender(req) 408 if err != nil { 409 result.sl.Response = autorest.Response{Response: resp} 410 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "List", resp, "Failure sending request") 411 return 412 } 413 414 result.sl, err = client.ListResponder(resp) 415 if err != nil { 416 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "List", resp, "Failure responding to request") 417 } 418 419 return 420} 421 422// ListPreparer prepares the List request. 423func (client SnapshotsClient) ListPreparer(ctx context.Context) (*http.Request, error) { 424 pathParameters := map[string]interface{}{ 425 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 426 } 427 428 const APIVersion = "2018-06-01" 429 queryParameters := map[string]interface{}{ 430 "api-version": APIVersion, 431 } 432 433 preparer := autorest.CreatePreparer( 434 autorest.AsGet(), 435 autorest.WithBaseURL(client.BaseURI), 436 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/snapshots", pathParameters), 437 autorest.WithQueryParameters(queryParameters)) 438 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 439} 440 441// ListSender sends the List request. The method will close the 442// http.Response Body if it receives an error. 443func (client SnapshotsClient) ListSender(req *http.Request) (*http.Response, error) { 444 return autorest.SendWithSender(client, req, 445 azure.DoRetryWithRegistration(client.Client)) 446} 447 448// ListResponder handles the response to the List request. The method always 449// closes the http.Response Body. 450func (client SnapshotsClient) ListResponder(resp *http.Response) (result SnapshotList, err error) { 451 err = autorest.Respond( 452 resp, 453 client.ByInspecting(), 454 azure.WithErrorUnlessStatusCode(http.StatusOK), 455 autorest.ByUnmarshallingJSON(&result), 456 autorest.ByClosing()) 457 result.Response = autorest.Response{Response: resp} 458 return 459} 460 461// listNextResults retrieves the next set of results, if any. 462func (client SnapshotsClient) listNextResults(ctx context.Context, lastResults SnapshotList) (result SnapshotList, err error) { 463 req, err := lastResults.snapshotListPreparer(ctx) 464 if err != nil { 465 return result, autorest.NewErrorWithError(err, "compute.SnapshotsClient", "listNextResults", nil, "Failure preparing next results request") 466 } 467 if req == nil { 468 return 469 } 470 resp, err := client.ListSender(req) 471 if err != nil { 472 result.Response = autorest.Response{Response: resp} 473 return result, autorest.NewErrorWithError(err, "compute.SnapshotsClient", "listNextResults", resp, "Failure sending next results request") 474 } 475 result, err = client.ListResponder(resp) 476 if err != nil { 477 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "listNextResults", resp, "Failure responding to next results request") 478 } 479 return 480} 481 482// ListComplete enumerates all values, automatically crossing page boundaries as required. 483func (client SnapshotsClient) ListComplete(ctx context.Context) (result SnapshotListIterator, err error) { 484 if tracing.IsEnabled() { 485 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.List") 486 defer func() { 487 sc := -1 488 if result.Response().Response.Response != nil { 489 sc = result.page.Response().Response.Response.StatusCode 490 } 491 tracing.EndSpan(ctx, sc, err) 492 }() 493 } 494 result.page, err = client.List(ctx) 495 return 496} 497 498// ListByResourceGroup lists snapshots under a resource group. 499// Parameters: 500// resourceGroupName - the name of the resource group. 501func (client SnapshotsClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result SnapshotListPage, err error) { 502 if tracing.IsEnabled() { 503 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.ListByResourceGroup") 504 defer func() { 505 sc := -1 506 if result.sl.Response.Response != nil { 507 sc = result.sl.Response.Response.StatusCode 508 } 509 tracing.EndSpan(ctx, sc, err) 510 }() 511 } 512 result.fn = client.listByResourceGroupNextResults 513 req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName) 514 if err != nil { 515 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "ListByResourceGroup", nil, "Failure preparing request") 516 return 517 } 518 519 resp, err := client.ListByResourceGroupSender(req) 520 if err != nil { 521 result.sl.Response = autorest.Response{Response: resp} 522 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "ListByResourceGroup", resp, "Failure sending request") 523 return 524 } 525 526 result.sl, err = client.ListByResourceGroupResponder(resp) 527 if err != nil { 528 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "ListByResourceGroup", resp, "Failure responding to request") 529 } 530 531 return 532} 533 534// ListByResourceGroupPreparer prepares the ListByResourceGroup request. 535func (client SnapshotsClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) { 536 pathParameters := map[string]interface{}{ 537 "resourceGroupName": autorest.Encode("path", resourceGroupName), 538 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 539 } 540 541 const APIVersion = "2018-06-01" 542 queryParameters := map[string]interface{}{ 543 "api-version": APIVersion, 544 } 545 546 preparer := autorest.CreatePreparer( 547 autorest.AsGet(), 548 autorest.WithBaseURL(client.BaseURI), 549 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots", pathParameters), 550 autorest.WithQueryParameters(queryParameters)) 551 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 552} 553 554// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the 555// http.Response Body if it receives an error. 556func (client SnapshotsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { 557 return autorest.SendWithSender(client, req, 558 azure.DoRetryWithRegistration(client.Client)) 559} 560 561// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always 562// closes the http.Response Body. 563func (client SnapshotsClient) ListByResourceGroupResponder(resp *http.Response) (result SnapshotList, err error) { 564 err = autorest.Respond( 565 resp, 566 client.ByInspecting(), 567 azure.WithErrorUnlessStatusCode(http.StatusOK), 568 autorest.ByUnmarshallingJSON(&result), 569 autorest.ByClosing()) 570 result.Response = autorest.Response{Response: resp} 571 return 572} 573 574// listByResourceGroupNextResults retrieves the next set of results, if any. 575func (client SnapshotsClient) listByResourceGroupNextResults(ctx context.Context, lastResults SnapshotList) (result SnapshotList, err error) { 576 req, err := lastResults.snapshotListPreparer(ctx) 577 if err != nil { 578 return result, autorest.NewErrorWithError(err, "compute.SnapshotsClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request") 579 } 580 if req == nil { 581 return 582 } 583 resp, err := client.ListByResourceGroupSender(req) 584 if err != nil { 585 result.Response = autorest.Response{Response: resp} 586 return result, autorest.NewErrorWithError(err, "compute.SnapshotsClient", "listByResourceGroupNextResults", resp, "Failure sending next results request") 587 } 588 result, err = client.ListByResourceGroupResponder(resp) 589 if err != nil { 590 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request") 591 } 592 return 593} 594 595// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required. 596func (client SnapshotsClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result SnapshotListIterator, err error) { 597 if tracing.IsEnabled() { 598 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.ListByResourceGroup") 599 defer func() { 600 sc := -1 601 if result.Response().Response.Response != nil { 602 sc = result.page.Response().Response.Response.StatusCode 603 } 604 tracing.EndSpan(ctx, sc, err) 605 }() 606 } 607 result.page, err = client.ListByResourceGroup(ctx, resourceGroupName) 608 return 609} 610 611// RevokeAccess revokes access to a snapshot. 612// Parameters: 613// resourceGroupName - the name of the resource group. 614// snapshotName - the name of the snapshot that is being created. The name can't be changed after the snapshot 615// is created. Supported characters for the name are a-z, A-Z, 0-9 and _. The max name length is 80 characters. 616func (client SnapshotsClient) RevokeAccess(ctx context.Context, resourceGroupName string, snapshotName string) (result SnapshotsRevokeAccessFuture, err error) { 617 if tracing.IsEnabled() { 618 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.RevokeAccess") 619 defer func() { 620 sc := -1 621 if result.Response() != nil { 622 sc = result.Response().StatusCode 623 } 624 tracing.EndSpan(ctx, sc, err) 625 }() 626 } 627 req, err := client.RevokeAccessPreparer(ctx, resourceGroupName, snapshotName) 628 if err != nil { 629 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "RevokeAccess", nil, "Failure preparing request") 630 return 631 } 632 633 result, err = client.RevokeAccessSender(req) 634 if err != nil { 635 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "RevokeAccess", result.Response(), "Failure sending request") 636 return 637 } 638 639 return 640} 641 642// RevokeAccessPreparer prepares the RevokeAccess request. 643func (client SnapshotsClient) RevokeAccessPreparer(ctx context.Context, resourceGroupName string, snapshotName string) (*http.Request, error) { 644 pathParameters := map[string]interface{}{ 645 "resourceGroupName": autorest.Encode("path", resourceGroupName), 646 "snapshotName": autorest.Encode("path", snapshotName), 647 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 648 } 649 650 const APIVersion = "2018-06-01" 651 queryParameters := map[string]interface{}{ 652 "api-version": APIVersion, 653 } 654 655 preparer := autorest.CreatePreparer( 656 autorest.AsPost(), 657 autorest.WithBaseURL(client.BaseURI), 658 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}/endGetAccess", pathParameters), 659 autorest.WithQueryParameters(queryParameters)) 660 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 661} 662 663// RevokeAccessSender sends the RevokeAccess request. The method will close the 664// http.Response Body if it receives an error. 665func (client SnapshotsClient) RevokeAccessSender(req *http.Request) (future SnapshotsRevokeAccessFuture, err error) { 666 var resp *http.Response 667 resp, err = autorest.SendWithSender(client, req, 668 azure.DoRetryWithRegistration(client.Client)) 669 if err != nil { 670 return 671 } 672 future.Future, err = azure.NewFutureFromResponse(resp) 673 return 674} 675 676// RevokeAccessResponder handles the response to the RevokeAccess request. The method always 677// closes the http.Response Body. 678func (client SnapshotsClient) RevokeAccessResponder(resp *http.Response) (result autorest.Response, err error) { 679 err = autorest.Respond( 680 resp, 681 client.ByInspecting(), 682 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 683 autorest.ByClosing()) 684 result.Response = resp 685 return 686} 687 688// Update updates (patches) a snapshot. 689// Parameters: 690// resourceGroupName - the name of the resource group. 691// snapshotName - the name of the snapshot that is being created. The name can't be changed after the snapshot 692// is created. Supported characters for the name are a-z, A-Z, 0-9 and _. The max name length is 80 characters. 693// snapshot - snapshot object supplied in the body of the Patch snapshot operation. 694func (client SnapshotsClient) Update(ctx context.Context, resourceGroupName string, snapshotName string, snapshot SnapshotUpdate) (result SnapshotsUpdateFuture, err error) { 695 if tracing.IsEnabled() { 696 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.Update") 697 defer func() { 698 sc := -1 699 if result.Response() != nil { 700 sc = result.Response().StatusCode 701 } 702 tracing.EndSpan(ctx, sc, err) 703 }() 704 } 705 req, err := client.UpdatePreparer(ctx, resourceGroupName, snapshotName, snapshot) 706 if err != nil { 707 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "Update", nil, "Failure preparing request") 708 return 709 } 710 711 result, err = client.UpdateSender(req) 712 if err != nil { 713 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "Update", result.Response(), "Failure sending request") 714 return 715 } 716 717 return 718} 719 720// UpdatePreparer prepares the Update request. 721func (client SnapshotsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, snapshotName string, snapshot SnapshotUpdate) (*http.Request, error) { 722 pathParameters := map[string]interface{}{ 723 "resourceGroupName": autorest.Encode("path", resourceGroupName), 724 "snapshotName": autorest.Encode("path", snapshotName), 725 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 726 } 727 728 const APIVersion = "2018-06-01" 729 queryParameters := map[string]interface{}{ 730 "api-version": APIVersion, 731 } 732 733 preparer := autorest.CreatePreparer( 734 autorest.AsContentType("application/json; charset=utf-8"), 735 autorest.AsPatch(), 736 autorest.WithBaseURL(client.BaseURI), 737 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}", pathParameters), 738 autorest.WithJSON(snapshot), 739 autorest.WithQueryParameters(queryParameters)) 740 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 741} 742 743// UpdateSender sends the Update request. The method will close the 744// http.Response Body if it receives an error. 745func (client SnapshotsClient) UpdateSender(req *http.Request) (future SnapshotsUpdateFuture, err error) { 746 var resp *http.Response 747 resp, err = autorest.SendWithSender(client, req, 748 azure.DoRetryWithRegistration(client.Client)) 749 if err != nil { 750 return 751 } 752 future.Future, err = azure.NewFutureFromResponse(resp) 753 return 754} 755 756// UpdateResponder handles the response to the Update request. The method always 757// closes the http.Response Body. 758func (client SnapshotsClient) UpdateResponder(resp *http.Response) (result Snapshot, err error) { 759 err = autorest.Respond( 760 resp, 761 client.ByInspecting(), 762 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 763 autorest.ByUnmarshallingJSON(&result), 764 autorest.ByClosing()) 765 result.Response = autorest.Response{Response: resp} 766 return 767} 768