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