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 using a custom endpoint. Use this 40// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 41func NewSnapshotsClientWithBaseURI(baseURI string, subscriptionID string) SnapshotsClient { 42 return SnapshotsClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// CreateOrUpdate creates or updates a snapshot. 46// Parameters: 47// resourceGroupName - the name of the resource group. 48// snapshotName - the name of the snapshot that is being created. The name can't be changed after the snapshot 49// is created. Supported characters for the name are a-z, A-Z, 0-9 and _. The max name length is 80 characters. 50// snapshot - snapshot object supplied in the body of the Put disk operation. 51func (client SnapshotsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, snapshotName string, snapshot Snapshot) (result SnapshotsCreateOrUpdateFuture, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.CreateOrUpdate") 54 defer func() { 55 sc := -1 56 if result.Response() != nil { 57 sc = result.Response().StatusCode 58 } 59 tracing.EndSpan(ctx, sc, err) 60 }() 61 } 62 if err := validation.Validate([]validation.Validation{ 63 {TargetValue: snapshot, 64 Constraints: []validation.Constraint{{Target: "snapshot.SnapshotProperties", Name: validation.Null, Rule: false, 65 Chain: []validation.Constraint{{Target: "snapshot.SnapshotProperties.CreationData", Name: validation.Null, Rule: true, 66 Chain: []validation.Constraint{{Target: "snapshot.SnapshotProperties.CreationData.ImageReference", Name: validation.Null, Rule: false, 67 Chain: []validation.Constraint{{Target: "snapshot.SnapshotProperties.CreationData.ImageReference.ID", Name: validation.Null, Rule: true, Chain: nil}}}, 68 }}, 69 {Target: "snapshot.SnapshotProperties.EncryptionSettings", Name: validation.Null, Rule: false, 70 Chain: []validation.Constraint{{Target: "snapshot.SnapshotProperties.EncryptionSettings.DiskEncryptionKey", Name: validation.Null, Rule: false, 71 Chain: []validation.Constraint{{Target: "snapshot.SnapshotProperties.EncryptionSettings.DiskEncryptionKey.SourceVault", Name: validation.Null, Rule: true, Chain: nil}, 72 {Target: "snapshot.SnapshotProperties.EncryptionSettings.DiskEncryptionKey.SecretURL", Name: validation.Null, Rule: true, Chain: nil}, 73 }}, 74 {Target: "snapshot.SnapshotProperties.EncryptionSettings.KeyEncryptionKey", Name: validation.Null, Rule: false, 75 Chain: []validation.Constraint{{Target: "snapshot.SnapshotProperties.EncryptionSettings.KeyEncryptionKey.SourceVault", Name: validation.Null, Rule: true, Chain: nil}, 76 {Target: "snapshot.SnapshotProperties.EncryptionSettings.KeyEncryptionKey.KeyURL", Name: validation.Null, Rule: true, Chain: nil}, 77 }}, 78 }}, 79 }}}}}); err != nil { 80 return result, validation.NewError("compute.SnapshotsClient", "CreateOrUpdate", err.Error()) 81 } 82 83 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, snapshotName, snapshot) 84 if err != nil { 85 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "CreateOrUpdate", nil, "Failure preparing request") 86 return 87 } 88 89 result, err = client.CreateOrUpdateSender(req) 90 if err != nil { 91 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "CreateOrUpdate", nil, "Failure sending request") 92 return 93 } 94 95 return 96} 97 98// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 99func (client SnapshotsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, snapshotName string, snapshot Snapshot) (*http.Request, error) { 100 pathParameters := map[string]interface{}{ 101 "resourceGroupName": autorest.Encode("path", resourceGroupName), 102 "snapshotName": autorest.Encode("path", snapshotName), 103 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 104 } 105 106 const APIVersion = "2018-06-01" 107 queryParameters := map[string]interface{}{ 108 "api-version": APIVersion, 109 } 110 111 snapshot.ManagedBy = nil 112 preparer := autorest.CreatePreparer( 113 autorest.AsContentType("application/json; charset=utf-8"), 114 autorest.AsPut(), 115 autorest.WithBaseURL(client.BaseURI), 116 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}", pathParameters), 117 autorest.WithJSON(snapshot), 118 autorest.WithQueryParameters(queryParameters)) 119 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 120} 121 122// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 123// http.Response Body if it receives an error. 124func (client SnapshotsClient) CreateOrUpdateSender(req *http.Request) (future SnapshotsCreateOrUpdateFuture, err error) { 125 var resp *http.Response 126 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 127 if err != nil { 128 return 129 } 130 var azf azure.Future 131 azf, err = azure.NewFutureFromResponse(resp) 132 future.FutureAPI = &azf 133 future.Result = func(client SnapshotsClient) (s Snapshot, err error) { 134 var done bool 135 done, err = future.DoneWithContext(context.Background(), client) 136 if err != nil { 137 err = autorest.NewErrorWithError(err, "compute.SnapshotsCreateOrUpdateFuture", "Result", future.Response(), "Polling failure") 138 return 139 } 140 if !done { 141 err = azure.NewAsyncOpIncompleteError("compute.SnapshotsCreateOrUpdateFuture") 142 return 143 } 144 sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 145 if s.Response.Response, err = future.GetResult(sender); err == nil && s.Response.Response.StatusCode != http.StatusNoContent { 146 s, err = client.CreateOrUpdateResponder(s.Response.Response) 147 if err != nil { 148 err = autorest.NewErrorWithError(err, "compute.SnapshotsCreateOrUpdateFuture", "Result", s.Response.Response, "Failure responding to request") 149 } 150 } 151 return 152 } 153 return 154} 155 156// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 157// closes the http.Response Body. 158func (client SnapshotsClient) CreateOrUpdateResponder(resp *http.Response) (result Snapshot, err error) { 159 err = autorest.Respond( 160 resp, 161 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 162 autorest.ByUnmarshallingJSON(&result), 163 autorest.ByClosing()) 164 result.Response = autorest.Response{Response: resp} 165 return 166} 167 168// Delete deletes a snapshot. 169// Parameters: 170// resourceGroupName - the name of the resource group. 171// snapshotName - the name of the snapshot that is being created. The name can't be changed after the snapshot 172// is created. Supported characters for the name are a-z, A-Z, 0-9 and _. The max name length is 80 characters. 173func (client SnapshotsClient) Delete(ctx context.Context, resourceGroupName string, snapshotName string) (result SnapshotsDeleteFuture, err error) { 174 if tracing.IsEnabled() { 175 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.Delete") 176 defer func() { 177 sc := -1 178 if result.Response() != nil { 179 sc = result.Response().StatusCode 180 } 181 tracing.EndSpan(ctx, sc, err) 182 }() 183 } 184 req, err := client.DeletePreparer(ctx, resourceGroupName, snapshotName) 185 if err != nil { 186 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "Delete", nil, "Failure preparing request") 187 return 188 } 189 190 result, err = client.DeleteSender(req) 191 if err != nil { 192 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "Delete", nil, "Failure sending request") 193 return 194 } 195 196 return 197} 198 199// DeletePreparer prepares the Delete request. 200func (client SnapshotsClient) DeletePreparer(ctx context.Context, resourceGroupName string, snapshotName string) (*http.Request, error) { 201 pathParameters := map[string]interface{}{ 202 "resourceGroupName": autorest.Encode("path", resourceGroupName), 203 "snapshotName": autorest.Encode("path", snapshotName), 204 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 205 } 206 207 const APIVersion = "2018-06-01" 208 queryParameters := map[string]interface{}{ 209 "api-version": APIVersion, 210 } 211 212 preparer := autorest.CreatePreparer( 213 autorest.AsDelete(), 214 autorest.WithBaseURL(client.BaseURI), 215 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}", pathParameters), 216 autorest.WithQueryParameters(queryParameters)) 217 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 218} 219 220// DeleteSender sends the Delete request. The method will close the 221// http.Response Body if it receives an error. 222func (client SnapshotsClient) DeleteSender(req *http.Request) (future SnapshotsDeleteFuture, err error) { 223 var resp *http.Response 224 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 225 if err != nil { 226 return 227 } 228 var azf azure.Future 229 azf, err = azure.NewFutureFromResponse(resp) 230 future.FutureAPI = &azf 231 future.Result = func(client SnapshotsClient) (ar autorest.Response, err error) { 232 var done bool 233 done, err = future.DoneWithContext(context.Background(), client) 234 if err != nil { 235 err = autorest.NewErrorWithError(err, "compute.SnapshotsDeleteFuture", "Result", future.Response(), "Polling failure") 236 return 237 } 238 if !done { 239 err = azure.NewAsyncOpIncompleteError("compute.SnapshotsDeleteFuture") 240 return 241 } 242 ar.Response = future.Response() 243 return 244 } 245 return 246} 247 248// DeleteResponder handles the response to the Delete request. The method always 249// closes the http.Response Body. 250func (client SnapshotsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 251 err = autorest.Respond( 252 resp, 253 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 254 autorest.ByClosing()) 255 result.Response = resp 256 return 257} 258 259// Get gets information about a snapshot. 260// Parameters: 261// resourceGroupName - the name of the resource group. 262// snapshotName - the name of the snapshot that is being created. The name can't be changed after the snapshot 263// is created. Supported characters for the name are a-z, A-Z, 0-9 and _. The max name length is 80 characters. 264func (client SnapshotsClient) Get(ctx context.Context, resourceGroupName string, snapshotName string) (result Snapshot, err error) { 265 if tracing.IsEnabled() { 266 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.Get") 267 defer func() { 268 sc := -1 269 if result.Response.Response != nil { 270 sc = result.Response.Response.StatusCode 271 } 272 tracing.EndSpan(ctx, sc, err) 273 }() 274 } 275 req, err := client.GetPreparer(ctx, resourceGroupName, snapshotName) 276 if err != nil { 277 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "Get", nil, "Failure preparing request") 278 return 279 } 280 281 resp, err := client.GetSender(req) 282 if err != nil { 283 result.Response = autorest.Response{Response: resp} 284 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "Get", resp, "Failure sending request") 285 return 286 } 287 288 result, err = client.GetResponder(resp) 289 if err != nil { 290 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "Get", resp, "Failure responding to request") 291 return 292 } 293 294 return 295} 296 297// GetPreparer prepares the Get request. 298func (client SnapshotsClient) GetPreparer(ctx context.Context, resourceGroupName string, snapshotName string) (*http.Request, error) { 299 pathParameters := map[string]interface{}{ 300 "resourceGroupName": autorest.Encode("path", resourceGroupName), 301 "snapshotName": autorest.Encode("path", snapshotName), 302 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 303 } 304 305 const APIVersion = "2018-06-01" 306 queryParameters := map[string]interface{}{ 307 "api-version": APIVersion, 308 } 309 310 preparer := autorest.CreatePreparer( 311 autorest.AsGet(), 312 autorest.WithBaseURL(client.BaseURI), 313 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}", pathParameters), 314 autorest.WithQueryParameters(queryParameters)) 315 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 316} 317 318// GetSender sends the Get request. The method will close the 319// http.Response Body if it receives an error. 320func (client SnapshotsClient) GetSender(req *http.Request) (*http.Response, error) { 321 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 322} 323 324// GetResponder handles the response to the Get request. The method always 325// closes the http.Response Body. 326func (client SnapshotsClient) GetResponder(resp *http.Response) (result Snapshot, err error) { 327 err = autorest.Respond( 328 resp, 329 azure.WithErrorUnlessStatusCode(http.StatusOK), 330 autorest.ByUnmarshallingJSON(&result), 331 autorest.ByClosing()) 332 result.Response = autorest.Response{Response: resp} 333 return 334} 335 336// GrantAccess grants access to a snapshot. 337// Parameters: 338// resourceGroupName - the name of the resource group. 339// snapshotName - the name of the snapshot that is being created. The name can't be changed after the snapshot 340// is created. Supported characters for the name are a-z, A-Z, 0-9 and _. The max name length is 80 characters. 341// grantAccessData - access data object supplied in the body of the get snapshot access operation. 342func (client SnapshotsClient) GrantAccess(ctx context.Context, resourceGroupName string, snapshotName string, grantAccessData GrantAccessData) (result SnapshotsGrantAccessFuture, err error) { 343 if tracing.IsEnabled() { 344 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.GrantAccess") 345 defer func() { 346 sc := -1 347 if result.Response() != nil { 348 sc = result.Response().StatusCode 349 } 350 tracing.EndSpan(ctx, sc, err) 351 }() 352 } 353 if err := validation.Validate([]validation.Validation{ 354 {TargetValue: grantAccessData, 355 Constraints: []validation.Constraint{{Target: "grantAccessData.DurationInSeconds", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 356 return result, validation.NewError("compute.SnapshotsClient", "GrantAccess", err.Error()) 357 } 358 359 req, err := client.GrantAccessPreparer(ctx, resourceGroupName, snapshotName, grantAccessData) 360 if err != nil { 361 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "GrantAccess", nil, "Failure preparing request") 362 return 363 } 364 365 result, err = client.GrantAccessSender(req) 366 if err != nil { 367 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "GrantAccess", nil, "Failure sending request") 368 return 369 } 370 371 return 372} 373 374// GrantAccessPreparer prepares the GrantAccess request. 375func (client SnapshotsClient) GrantAccessPreparer(ctx context.Context, resourceGroupName string, snapshotName string, grantAccessData GrantAccessData) (*http.Request, error) { 376 pathParameters := map[string]interface{}{ 377 "resourceGroupName": autorest.Encode("path", resourceGroupName), 378 "snapshotName": autorest.Encode("path", snapshotName), 379 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 380 } 381 382 const APIVersion = "2018-06-01" 383 queryParameters := map[string]interface{}{ 384 "api-version": APIVersion, 385 } 386 387 preparer := autorest.CreatePreparer( 388 autorest.AsContentType("application/json; charset=utf-8"), 389 autorest.AsPost(), 390 autorest.WithBaseURL(client.BaseURI), 391 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}/beginGetAccess", pathParameters), 392 autorest.WithJSON(grantAccessData), 393 autorest.WithQueryParameters(queryParameters)) 394 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 395} 396 397// GrantAccessSender sends the GrantAccess request. The method will close the 398// http.Response Body if it receives an error. 399func (client SnapshotsClient) GrantAccessSender(req *http.Request) (future SnapshotsGrantAccessFuture, err error) { 400 var resp *http.Response 401 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 402 if err != nil { 403 return 404 } 405 var azf azure.Future 406 azf, err = azure.NewFutureFromResponse(resp) 407 future.FutureAPI = &azf 408 future.Result = func(client SnapshotsClient) (au AccessURI, err error) { 409 var done bool 410 done, err = future.DoneWithContext(context.Background(), client) 411 if err != nil { 412 err = autorest.NewErrorWithError(err, "compute.SnapshotsGrantAccessFuture", "Result", future.Response(), "Polling failure") 413 return 414 } 415 if !done { 416 err = azure.NewAsyncOpIncompleteError("compute.SnapshotsGrantAccessFuture") 417 return 418 } 419 sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 420 if au.Response.Response, err = future.GetResult(sender); err == nil && au.Response.Response.StatusCode != http.StatusNoContent { 421 au, err = client.GrantAccessResponder(au.Response.Response) 422 if err != nil { 423 err = autorest.NewErrorWithError(err, "compute.SnapshotsGrantAccessFuture", "Result", au.Response.Response, "Failure responding to request") 424 } 425 } 426 return 427 } 428 return 429} 430 431// GrantAccessResponder handles the response to the GrantAccess request. The method always 432// closes the http.Response Body. 433func (client SnapshotsClient) GrantAccessResponder(resp *http.Response) (result AccessURI, err error) { 434 err = autorest.Respond( 435 resp, 436 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 437 autorest.ByUnmarshallingJSON(&result), 438 autorest.ByClosing()) 439 result.Response = autorest.Response{Response: resp} 440 return 441} 442 443// List lists snapshots under a subscription. 444func (client SnapshotsClient) List(ctx context.Context) (result SnapshotListPage, err error) { 445 if tracing.IsEnabled() { 446 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.List") 447 defer func() { 448 sc := -1 449 if result.sl.Response.Response != nil { 450 sc = result.sl.Response.Response.StatusCode 451 } 452 tracing.EndSpan(ctx, sc, err) 453 }() 454 } 455 result.fn = client.listNextResults 456 req, err := client.ListPreparer(ctx) 457 if err != nil { 458 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "List", nil, "Failure preparing request") 459 return 460 } 461 462 resp, err := client.ListSender(req) 463 if err != nil { 464 result.sl.Response = autorest.Response{Response: resp} 465 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "List", resp, "Failure sending request") 466 return 467 } 468 469 result.sl, err = client.ListResponder(resp) 470 if err != nil { 471 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "List", resp, "Failure responding to request") 472 return 473 } 474 if result.sl.hasNextLink() && result.sl.IsEmpty() { 475 err = result.NextWithContext(ctx) 476 return 477 } 478 479 return 480} 481 482// ListPreparer prepares the List request. 483func (client SnapshotsClient) ListPreparer(ctx context.Context) (*http.Request, error) { 484 pathParameters := map[string]interface{}{ 485 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 486 } 487 488 const APIVersion = "2018-06-01" 489 queryParameters := map[string]interface{}{ 490 "api-version": APIVersion, 491 } 492 493 preparer := autorest.CreatePreparer( 494 autorest.AsGet(), 495 autorest.WithBaseURL(client.BaseURI), 496 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/snapshots", pathParameters), 497 autorest.WithQueryParameters(queryParameters)) 498 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 499} 500 501// ListSender sends the List request. The method will close the 502// http.Response Body if it receives an error. 503func (client SnapshotsClient) ListSender(req *http.Request) (*http.Response, error) { 504 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 505} 506 507// ListResponder handles the response to the List request. The method always 508// closes the http.Response Body. 509func (client SnapshotsClient) ListResponder(resp *http.Response) (result SnapshotList, err error) { 510 err = autorest.Respond( 511 resp, 512 azure.WithErrorUnlessStatusCode(http.StatusOK), 513 autorest.ByUnmarshallingJSON(&result), 514 autorest.ByClosing()) 515 result.Response = autorest.Response{Response: resp} 516 return 517} 518 519// listNextResults retrieves the next set of results, if any. 520func (client SnapshotsClient) listNextResults(ctx context.Context, lastResults SnapshotList) (result SnapshotList, err error) { 521 req, err := lastResults.snapshotListPreparer(ctx) 522 if err != nil { 523 return result, autorest.NewErrorWithError(err, "compute.SnapshotsClient", "listNextResults", nil, "Failure preparing next results request") 524 } 525 if req == nil { 526 return 527 } 528 resp, err := client.ListSender(req) 529 if err != nil { 530 result.Response = autorest.Response{Response: resp} 531 return result, autorest.NewErrorWithError(err, "compute.SnapshotsClient", "listNextResults", resp, "Failure sending next results request") 532 } 533 result, err = client.ListResponder(resp) 534 if err != nil { 535 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "listNextResults", resp, "Failure responding to next results request") 536 } 537 return 538} 539 540// ListComplete enumerates all values, automatically crossing page boundaries as required. 541func (client SnapshotsClient) ListComplete(ctx context.Context) (result SnapshotListIterator, err error) { 542 if tracing.IsEnabled() { 543 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.List") 544 defer func() { 545 sc := -1 546 if result.Response().Response.Response != nil { 547 sc = result.page.Response().Response.Response.StatusCode 548 } 549 tracing.EndSpan(ctx, sc, err) 550 }() 551 } 552 result.page, err = client.List(ctx) 553 return 554} 555 556// ListByResourceGroup lists snapshots under a resource group. 557// Parameters: 558// resourceGroupName - the name of the resource group. 559func (client SnapshotsClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result SnapshotListPage, err error) { 560 if tracing.IsEnabled() { 561 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.ListByResourceGroup") 562 defer func() { 563 sc := -1 564 if result.sl.Response.Response != nil { 565 sc = result.sl.Response.Response.StatusCode 566 } 567 tracing.EndSpan(ctx, sc, err) 568 }() 569 } 570 result.fn = client.listByResourceGroupNextResults 571 req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName) 572 if err != nil { 573 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "ListByResourceGroup", nil, "Failure preparing request") 574 return 575 } 576 577 resp, err := client.ListByResourceGroupSender(req) 578 if err != nil { 579 result.sl.Response = autorest.Response{Response: resp} 580 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "ListByResourceGroup", resp, "Failure sending request") 581 return 582 } 583 584 result.sl, err = client.ListByResourceGroupResponder(resp) 585 if err != nil { 586 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "ListByResourceGroup", resp, "Failure responding to request") 587 return 588 } 589 if result.sl.hasNextLink() && result.sl.IsEmpty() { 590 err = result.NextWithContext(ctx) 591 return 592 } 593 594 return 595} 596 597// ListByResourceGroupPreparer prepares the ListByResourceGroup request. 598func (client SnapshotsClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) { 599 pathParameters := map[string]interface{}{ 600 "resourceGroupName": autorest.Encode("path", resourceGroupName), 601 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 602 } 603 604 const APIVersion = "2018-06-01" 605 queryParameters := map[string]interface{}{ 606 "api-version": APIVersion, 607 } 608 609 preparer := autorest.CreatePreparer( 610 autorest.AsGet(), 611 autorest.WithBaseURL(client.BaseURI), 612 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots", pathParameters), 613 autorest.WithQueryParameters(queryParameters)) 614 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 615} 616 617// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the 618// http.Response Body if it receives an error. 619func (client SnapshotsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { 620 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 621} 622 623// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always 624// closes the http.Response Body. 625func (client SnapshotsClient) ListByResourceGroupResponder(resp *http.Response) (result SnapshotList, err error) { 626 err = autorest.Respond( 627 resp, 628 azure.WithErrorUnlessStatusCode(http.StatusOK), 629 autorest.ByUnmarshallingJSON(&result), 630 autorest.ByClosing()) 631 result.Response = autorest.Response{Response: resp} 632 return 633} 634 635// listByResourceGroupNextResults retrieves the next set of results, if any. 636func (client SnapshotsClient) listByResourceGroupNextResults(ctx context.Context, lastResults SnapshotList) (result SnapshotList, err error) { 637 req, err := lastResults.snapshotListPreparer(ctx) 638 if err != nil { 639 return result, autorest.NewErrorWithError(err, "compute.SnapshotsClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request") 640 } 641 if req == nil { 642 return 643 } 644 resp, err := client.ListByResourceGroupSender(req) 645 if err != nil { 646 result.Response = autorest.Response{Response: resp} 647 return result, autorest.NewErrorWithError(err, "compute.SnapshotsClient", "listByResourceGroupNextResults", resp, "Failure sending next results request") 648 } 649 result, err = client.ListByResourceGroupResponder(resp) 650 if err != nil { 651 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request") 652 } 653 return 654} 655 656// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required. 657func (client SnapshotsClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result SnapshotListIterator, err error) { 658 if tracing.IsEnabled() { 659 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.ListByResourceGroup") 660 defer func() { 661 sc := -1 662 if result.Response().Response.Response != nil { 663 sc = result.page.Response().Response.Response.StatusCode 664 } 665 tracing.EndSpan(ctx, sc, err) 666 }() 667 } 668 result.page, err = client.ListByResourceGroup(ctx, resourceGroupName) 669 return 670} 671 672// RevokeAccess revokes access to a snapshot. 673// Parameters: 674// resourceGroupName - the name of the resource group. 675// snapshotName - the name of the snapshot that is being created. The name can't be changed after the snapshot 676// is created. Supported characters for the name are a-z, A-Z, 0-9 and _. The max name length is 80 characters. 677func (client SnapshotsClient) RevokeAccess(ctx context.Context, resourceGroupName string, snapshotName string) (result SnapshotsRevokeAccessFuture, err error) { 678 if tracing.IsEnabled() { 679 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.RevokeAccess") 680 defer func() { 681 sc := -1 682 if result.Response() != nil { 683 sc = result.Response().StatusCode 684 } 685 tracing.EndSpan(ctx, sc, err) 686 }() 687 } 688 req, err := client.RevokeAccessPreparer(ctx, resourceGroupName, snapshotName) 689 if err != nil { 690 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "RevokeAccess", nil, "Failure preparing request") 691 return 692 } 693 694 result, err = client.RevokeAccessSender(req) 695 if err != nil { 696 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "RevokeAccess", nil, "Failure sending request") 697 return 698 } 699 700 return 701} 702 703// RevokeAccessPreparer prepares the RevokeAccess request. 704func (client SnapshotsClient) RevokeAccessPreparer(ctx context.Context, resourceGroupName string, snapshotName string) (*http.Request, error) { 705 pathParameters := map[string]interface{}{ 706 "resourceGroupName": autorest.Encode("path", resourceGroupName), 707 "snapshotName": autorest.Encode("path", snapshotName), 708 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 709 } 710 711 const APIVersion = "2018-06-01" 712 queryParameters := map[string]interface{}{ 713 "api-version": APIVersion, 714 } 715 716 preparer := autorest.CreatePreparer( 717 autorest.AsPost(), 718 autorest.WithBaseURL(client.BaseURI), 719 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}/endGetAccess", pathParameters), 720 autorest.WithQueryParameters(queryParameters)) 721 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 722} 723 724// RevokeAccessSender sends the RevokeAccess request. The method will close the 725// http.Response Body if it receives an error. 726func (client SnapshotsClient) RevokeAccessSender(req *http.Request) (future SnapshotsRevokeAccessFuture, err error) { 727 var resp *http.Response 728 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 729 if err != nil { 730 return 731 } 732 var azf azure.Future 733 azf, err = azure.NewFutureFromResponse(resp) 734 future.FutureAPI = &azf 735 future.Result = func(client SnapshotsClient) (ar autorest.Response, err error) { 736 var done bool 737 done, err = future.DoneWithContext(context.Background(), client) 738 if err != nil { 739 err = autorest.NewErrorWithError(err, "compute.SnapshotsRevokeAccessFuture", "Result", future.Response(), "Polling failure") 740 return 741 } 742 if !done { 743 err = azure.NewAsyncOpIncompleteError("compute.SnapshotsRevokeAccessFuture") 744 return 745 } 746 ar.Response = future.Response() 747 return 748 } 749 return 750} 751 752// RevokeAccessResponder handles the response to the RevokeAccess request. The method always 753// closes the http.Response Body. 754func (client SnapshotsClient) RevokeAccessResponder(resp *http.Response) (result autorest.Response, err error) { 755 err = autorest.Respond( 756 resp, 757 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 758 autorest.ByClosing()) 759 result.Response = resp 760 return 761} 762 763// Update updates (patches) a snapshot. 764// Parameters: 765// resourceGroupName - the name of the resource group. 766// snapshotName - the name of the snapshot that is being created. The name can't be changed after the snapshot 767// is created. Supported characters for the name are a-z, A-Z, 0-9 and _. The max name length is 80 characters. 768// snapshot - snapshot object supplied in the body of the Patch snapshot operation. 769func (client SnapshotsClient) Update(ctx context.Context, resourceGroupName string, snapshotName string, snapshot SnapshotUpdate) (result SnapshotsUpdateFuture, err error) { 770 if tracing.IsEnabled() { 771 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.Update") 772 defer func() { 773 sc := -1 774 if result.Response() != nil { 775 sc = result.Response().StatusCode 776 } 777 tracing.EndSpan(ctx, sc, err) 778 }() 779 } 780 req, err := client.UpdatePreparer(ctx, resourceGroupName, snapshotName, snapshot) 781 if err != nil { 782 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "Update", nil, "Failure preparing request") 783 return 784 } 785 786 result, err = client.UpdateSender(req) 787 if err != nil { 788 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "Update", nil, "Failure sending request") 789 return 790 } 791 792 return 793} 794 795// UpdatePreparer prepares the Update request. 796func (client SnapshotsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, snapshotName string, snapshot SnapshotUpdate) (*http.Request, error) { 797 pathParameters := map[string]interface{}{ 798 "resourceGroupName": autorest.Encode("path", resourceGroupName), 799 "snapshotName": autorest.Encode("path", snapshotName), 800 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 801 } 802 803 const APIVersion = "2018-06-01" 804 queryParameters := map[string]interface{}{ 805 "api-version": APIVersion, 806 } 807 808 preparer := autorest.CreatePreparer( 809 autorest.AsContentType("application/json; charset=utf-8"), 810 autorest.AsPatch(), 811 autorest.WithBaseURL(client.BaseURI), 812 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}", pathParameters), 813 autorest.WithJSON(snapshot), 814 autorest.WithQueryParameters(queryParameters)) 815 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 816} 817 818// UpdateSender sends the Update request. The method will close the 819// http.Response Body if it receives an error. 820func (client SnapshotsClient) UpdateSender(req *http.Request) (future SnapshotsUpdateFuture, err error) { 821 var resp *http.Response 822 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 823 if err != nil { 824 return 825 } 826 var azf azure.Future 827 azf, err = azure.NewFutureFromResponse(resp) 828 future.FutureAPI = &azf 829 future.Result = func(client SnapshotsClient) (s Snapshot, err error) { 830 var done bool 831 done, err = future.DoneWithContext(context.Background(), client) 832 if err != nil { 833 err = autorest.NewErrorWithError(err, "compute.SnapshotsUpdateFuture", "Result", future.Response(), "Polling failure") 834 return 835 } 836 if !done { 837 err = azure.NewAsyncOpIncompleteError("compute.SnapshotsUpdateFuture") 838 return 839 } 840 sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 841 if s.Response.Response, err = future.GetResult(sender); err == nil && s.Response.Response.StatusCode != http.StatusNoContent { 842 s, err = client.UpdateResponder(s.Response.Response) 843 if err != nil { 844 err = autorest.NewErrorWithError(err, "compute.SnapshotsUpdateFuture", "Result", s.Response.Response, "Failure responding to request") 845 } 846 } 847 return 848 } 849 return 850} 851 852// UpdateResponder handles the response to the Update request. The method always 853// closes the http.Response Body. 854func (client SnapshotsClient) UpdateResponder(resp *http.Response) (result Snapshot, err error) { 855 err = autorest.Respond( 856 resp, 857 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 858 autorest.ByUnmarshallingJSON(&result), 859 autorest.ByClosing()) 860 result.Response = autorest.Response{Response: resp} 861 return 862} 863