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