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.EncryptionSettingsCollection", Name: validation.Null, Rule: false, 70 Chain: []validation.Constraint{{Target: "snapshot.SnapshotProperties.EncryptionSettingsCollection.Enabled", Name: validation.Null, Rule: true, Chain: nil}}}, 71 }}}}}); err != nil { 72 return result, validation.NewError("compute.SnapshotsClient", "CreateOrUpdate", err.Error()) 73 } 74 75 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, snapshotName, snapshot) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "CreateOrUpdate", nil, "Failure preparing request") 78 return 79 } 80 81 result, err = client.CreateOrUpdateSender(req) 82 if err != nil { 83 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "CreateOrUpdate", result.Response(), "Failure sending request") 84 return 85 } 86 87 return 88} 89 90// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 91func (client SnapshotsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, snapshotName string, snapshot Snapshot) (*http.Request, error) { 92 pathParameters := map[string]interface{}{ 93 "resourceGroupName": autorest.Encode("path", resourceGroupName), 94 "snapshotName": autorest.Encode("path", snapshotName), 95 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 96 } 97 98 const APIVersion = "2019-03-01" 99 queryParameters := map[string]interface{}{ 100 "api-version": APIVersion, 101 } 102 103 snapshot.ManagedBy = nil 104 preparer := autorest.CreatePreparer( 105 autorest.AsContentType("application/json; charset=utf-8"), 106 autorest.AsPut(), 107 autorest.WithBaseURL(client.BaseURI), 108 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}", pathParameters), 109 autorest.WithJSON(snapshot), 110 autorest.WithQueryParameters(queryParameters)) 111 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 112} 113 114// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 115// http.Response Body if it receives an error. 116func (client SnapshotsClient) CreateOrUpdateSender(req *http.Request) (future SnapshotsCreateOrUpdateFuture, err error) { 117 var resp *http.Response 118 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 119 if err != nil { 120 return 121 } 122 future.Future, err = azure.NewFutureFromResponse(resp) 123 return 124} 125 126// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 127// closes the http.Response Body. 128func (client SnapshotsClient) CreateOrUpdateResponder(resp *http.Response) (result Snapshot, err error) { 129 err = autorest.Respond( 130 resp, 131 client.ByInspecting(), 132 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 133 autorest.ByUnmarshallingJSON(&result), 134 autorest.ByClosing()) 135 result.Response = autorest.Response{Response: resp} 136 return 137} 138 139// Delete deletes a snapshot. 140// Parameters: 141// resourceGroupName - the name of the resource group. 142// snapshotName - the name of the snapshot that is being created. The name can't be changed after the snapshot 143// is created. Supported characters for the name are a-z, A-Z, 0-9 and _. The max name length is 80 characters. 144func (client SnapshotsClient) Delete(ctx context.Context, resourceGroupName string, snapshotName string) (result SnapshotsDeleteFuture, err error) { 145 if tracing.IsEnabled() { 146 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.Delete") 147 defer func() { 148 sc := -1 149 if result.Response() != nil { 150 sc = result.Response().StatusCode 151 } 152 tracing.EndSpan(ctx, sc, err) 153 }() 154 } 155 req, err := client.DeletePreparer(ctx, resourceGroupName, snapshotName) 156 if err != nil { 157 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "Delete", nil, "Failure preparing request") 158 return 159 } 160 161 result, err = client.DeleteSender(req) 162 if err != nil { 163 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "Delete", result.Response(), "Failure sending request") 164 return 165 } 166 167 return 168} 169 170// DeletePreparer prepares the Delete request. 171func (client SnapshotsClient) DeletePreparer(ctx context.Context, resourceGroupName string, snapshotName string) (*http.Request, error) { 172 pathParameters := map[string]interface{}{ 173 "resourceGroupName": autorest.Encode("path", resourceGroupName), 174 "snapshotName": autorest.Encode("path", snapshotName), 175 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 176 } 177 178 const APIVersion = "2019-03-01" 179 queryParameters := map[string]interface{}{ 180 "api-version": APIVersion, 181 } 182 183 preparer := autorest.CreatePreparer( 184 autorest.AsDelete(), 185 autorest.WithBaseURL(client.BaseURI), 186 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}", pathParameters), 187 autorest.WithQueryParameters(queryParameters)) 188 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 189} 190 191// DeleteSender sends the Delete request. The method will close the 192// http.Response Body if it receives an error. 193func (client SnapshotsClient) DeleteSender(req *http.Request) (future SnapshotsDeleteFuture, err error) { 194 var resp *http.Response 195 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 196 if err != nil { 197 return 198 } 199 future.Future, err = azure.NewFutureFromResponse(resp) 200 return 201} 202 203// DeleteResponder handles the response to the Delete request. The method always 204// closes the http.Response Body. 205func (client SnapshotsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 206 err = autorest.Respond( 207 resp, 208 client.ByInspecting(), 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 } 248 249 return 250} 251 252// GetPreparer prepares the Get request. 253func (client SnapshotsClient) GetPreparer(ctx context.Context, resourceGroupName string, snapshotName string) (*http.Request, error) { 254 pathParameters := map[string]interface{}{ 255 "resourceGroupName": autorest.Encode("path", resourceGroupName), 256 "snapshotName": autorest.Encode("path", snapshotName), 257 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 258 } 259 260 const APIVersion = "2019-03-01" 261 queryParameters := map[string]interface{}{ 262 "api-version": APIVersion, 263 } 264 265 preparer := autorest.CreatePreparer( 266 autorest.AsGet(), 267 autorest.WithBaseURL(client.BaseURI), 268 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}", pathParameters), 269 autorest.WithQueryParameters(queryParameters)) 270 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 271} 272 273// GetSender sends the Get request. The method will close the 274// http.Response Body if it receives an error. 275func (client SnapshotsClient) GetSender(req *http.Request) (*http.Response, error) { 276 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 277} 278 279// GetResponder handles the response to the Get request. The method always 280// closes the http.Response Body. 281func (client SnapshotsClient) GetResponder(resp *http.Response) (result Snapshot, err error) { 282 err = autorest.Respond( 283 resp, 284 client.ByInspecting(), 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.Response() != nil { 304 sc = result.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", result.Response(), "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 = "2019-03-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 future.Future, err = azure.NewFutureFromResponse(resp) 362 return 363} 364 365// GrantAccessResponder handles the response to the GrantAccess request. The method always 366// closes the http.Response Body. 367func (client SnapshotsClient) GrantAccessResponder(resp *http.Response) (result AccessURI, err error) { 368 err = autorest.Respond( 369 resp, 370 client.ByInspecting(), 371 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 372 autorest.ByUnmarshallingJSON(&result), 373 autorest.ByClosing()) 374 result.Response = autorest.Response{Response: resp} 375 return 376} 377 378// List lists snapshots under a subscription. 379func (client SnapshotsClient) List(ctx context.Context) (result SnapshotListPage, err error) { 380 if tracing.IsEnabled() { 381 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.List") 382 defer func() { 383 sc := -1 384 if result.sl.Response.Response != nil { 385 sc = result.sl.Response.Response.StatusCode 386 } 387 tracing.EndSpan(ctx, sc, err) 388 }() 389 } 390 result.fn = client.listNextResults 391 req, err := client.ListPreparer(ctx) 392 if err != nil { 393 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "List", nil, "Failure preparing request") 394 return 395 } 396 397 resp, err := client.ListSender(req) 398 if err != nil { 399 result.sl.Response = autorest.Response{Response: resp} 400 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "List", resp, "Failure sending request") 401 return 402 } 403 404 result.sl, err = client.ListResponder(resp) 405 if err != nil { 406 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "List", resp, "Failure responding to request") 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 client.ByInspecting(), 443 azure.WithErrorUnlessStatusCode(http.StatusOK), 444 autorest.ByUnmarshallingJSON(&result), 445 autorest.ByClosing()) 446 result.Response = autorest.Response{Response: resp} 447 return 448} 449 450// listNextResults retrieves the next set of results, if any. 451func (client SnapshotsClient) listNextResults(ctx context.Context, lastResults SnapshotList) (result SnapshotList, err error) { 452 req, err := lastResults.snapshotListPreparer(ctx) 453 if err != nil { 454 return result, autorest.NewErrorWithError(err, "compute.SnapshotsClient", "listNextResults", nil, "Failure preparing next results request") 455 } 456 if req == nil { 457 return 458 } 459 resp, err := client.ListSender(req) 460 if err != nil { 461 result.Response = autorest.Response{Response: resp} 462 return result, autorest.NewErrorWithError(err, "compute.SnapshotsClient", "listNextResults", resp, "Failure sending next results request") 463 } 464 result, err = client.ListResponder(resp) 465 if err != nil { 466 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "listNextResults", resp, "Failure responding to next results request") 467 } 468 return 469} 470 471// ListComplete enumerates all values, automatically crossing page boundaries as required. 472func (client SnapshotsClient) ListComplete(ctx context.Context) (result SnapshotListIterator, err error) { 473 if tracing.IsEnabled() { 474 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.List") 475 defer func() { 476 sc := -1 477 if result.Response().Response.Response != nil { 478 sc = result.page.Response().Response.Response.StatusCode 479 } 480 tracing.EndSpan(ctx, sc, err) 481 }() 482 } 483 result.page, err = client.List(ctx) 484 return 485} 486 487// ListByResourceGroup lists snapshots under a resource group. 488// Parameters: 489// resourceGroupName - the name of the resource group. 490func (client SnapshotsClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result SnapshotListPage, err error) { 491 if tracing.IsEnabled() { 492 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.ListByResourceGroup") 493 defer func() { 494 sc := -1 495 if result.sl.Response.Response != nil { 496 sc = result.sl.Response.Response.StatusCode 497 } 498 tracing.EndSpan(ctx, sc, err) 499 }() 500 } 501 result.fn = client.listByResourceGroupNextResults 502 req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName) 503 if err != nil { 504 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "ListByResourceGroup", nil, "Failure preparing request") 505 return 506 } 507 508 resp, err := client.ListByResourceGroupSender(req) 509 if err != nil { 510 result.sl.Response = autorest.Response{Response: resp} 511 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "ListByResourceGroup", resp, "Failure sending request") 512 return 513 } 514 515 result.sl, err = client.ListByResourceGroupResponder(resp) 516 if err != nil { 517 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "ListByResourceGroup", resp, "Failure responding to request") 518 } 519 520 return 521} 522 523// ListByResourceGroupPreparer prepares the ListByResourceGroup request. 524func (client SnapshotsClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) { 525 pathParameters := map[string]interface{}{ 526 "resourceGroupName": autorest.Encode("path", resourceGroupName), 527 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 528 } 529 530 const APIVersion = "2019-03-01" 531 queryParameters := map[string]interface{}{ 532 "api-version": APIVersion, 533 } 534 535 preparer := autorest.CreatePreparer( 536 autorest.AsGet(), 537 autorest.WithBaseURL(client.BaseURI), 538 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots", pathParameters), 539 autorest.WithQueryParameters(queryParameters)) 540 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 541} 542 543// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the 544// http.Response Body if it receives an error. 545func (client SnapshotsClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { 546 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 547} 548 549// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always 550// closes the http.Response Body. 551func (client SnapshotsClient) ListByResourceGroupResponder(resp *http.Response) (result SnapshotList, err error) { 552 err = autorest.Respond( 553 resp, 554 client.ByInspecting(), 555 azure.WithErrorUnlessStatusCode(http.StatusOK), 556 autorest.ByUnmarshallingJSON(&result), 557 autorest.ByClosing()) 558 result.Response = autorest.Response{Response: resp} 559 return 560} 561 562// listByResourceGroupNextResults retrieves the next set of results, if any. 563func (client SnapshotsClient) listByResourceGroupNextResults(ctx context.Context, lastResults SnapshotList) (result SnapshotList, err error) { 564 req, err := lastResults.snapshotListPreparer(ctx) 565 if err != nil { 566 return result, autorest.NewErrorWithError(err, "compute.SnapshotsClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request") 567 } 568 if req == nil { 569 return 570 } 571 resp, err := client.ListByResourceGroupSender(req) 572 if err != nil { 573 result.Response = autorest.Response{Response: resp} 574 return result, autorest.NewErrorWithError(err, "compute.SnapshotsClient", "listByResourceGroupNextResults", resp, "Failure sending next results request") 575 } 576 result, err = client.ListByResourceGroupResponder(resp) 577 if err != nil { 578 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request") 579 } 580 return 581} 582 583// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required. 584func (client SnapshotsClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result SnapshotListIterator, err error) { 585 if tracing.IsEnabled() { 586 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.ListByResourceGroup") 587 defer func() { 588 sc := -1 589 if result.Response().Response.Response != nil { 590 sc = result.page.Response().Response.Response.StatusCode 591 } 592 tracing.EndSpan(ctx, sc, err) 593 }() 594 } 595 result.page, err = client.ListByResourceGroup(ctx, resourceGroupName) 596 return 597} 598 599// RevokeAccess revokes access to a snapshot. 600// Parameters: 601// resourceGroupName - the name of the resource group. 602// snapshotName - the name of the snapshot that is being created. The name can't be changed after the snapshot 603// is created. Supported characters for the name are a-z, A-Z, 0-9 and _. The max name length is 80 characters. 604func (client SnapshotsClient) RevokeAccess(ctx context.Context, resourceGroupName string, snapshotName string) (result SnapshotsRevokeAccessFuture, err error) { 605 if tracing.IsEnabled() { 606 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.RevokeAccess") 607 defer func() { 608 sc := -1 609 if result.Response() != nil { 610 sc = result.Response().StatusCode 611 } 612 tracing.EndSpan(ctx, sc, err) 613 }() 614 } 615 req, err := client.RevokeAccessPreparer(ctx, resourceGroupName, snapshotName) 616 if err != nil { 617 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "RevokeAccess", nil, "Failure preparing request") 618 return 619 } 620 621 result, err = client.RevokeAccessSender(req) 622 if err != nil { 623 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "RevokeAccess", result.Response(), "Failure sending request") 624 return 625 } 626 627 return 628} 629 630// RevokeAccessPreparer prepares the RevokeAccess request. 631func (client SnapshotsClient) RevokeAccessPreparer(ctx context.Context, resourceGroupName string, snapshotName string) (*http.Request, error) { 632 pathParameters := map[string]interface{}{ 633 "resourceGroupName": autorest.Encode("path", resourceGroupName), 634 "snapshotName": autorest.Encode("path", snapshotName), 635 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 636 } 637 638 const APIVersion = "2019-03-01" 639 queryParameters := map[string]interface{}{ 640 "api-version": APIVersion, 641 } 642 643 preparer := autorest.CreatePreparer( 644 autorest.AsPost(), 645 autorest.WithBaseURL(client.BaseURI), 646 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}/endGetAccess", pathParameters), 647 autorest.WithQueryParameters(queryParameters)) 648 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 649} 650 651// RevokeAccessSender sends the RevokeAccess request. The method will close the 652// http.Response Body if it receives an error. 653func (client SnapshotsClient) RevokeAccessSender(req *http.Request) (future SnapshotsRevokeAccessFuture, err error) { 654 var resp *http.Response 655 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 656 if err != nil { 657 return 658 } 659 future.Future, err = azure.NewFutureFromResponse(resp) 660 return 661} 662 663// RevokeAccessResponder handles the response to the RevokeAccess request. The method always 664// closes the http.Response Body. 665func (client SnapshotsClient) RevokeAccessResponder(resp *http.Response) (result autorest.Response, err error) { 666 err = autorest.Respond( 667 resp, 668 client.ByInspecting(), 669 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 670 autorest.ByClosing()) 671 result.Response = resp 672 return 673} 674 675// Update updates (patches) a snapshot. 676// Parameters: 677// resourceGroupName - the name of the resource group. 678// snapshotName - the name of the snapshot that is being created. The name can't be changed after the snapshot 679// is created. Supported characters for the name are a-z, A-Z, 0-9 and _. The max name length is 80 characters. 680// snapshot - snapshot object supplied in the body of the Patch snapshot operation. 681func (client SnapshotsClient) Update(ctx context.Context, resourceGroupName string, snapshotName string, snapshot SnapshotUpdate) (result SnapshotsUpdateFuture, err error) { 682 if tracing.IsEnabled() { 683 ctx = tracing.StartSpan(ctx, fqdn+"/SnapshotsClient.Update") 684 defer func() { 685 sc := -1 686 if result.Response() != nil { 687 sc = result.Response().StatusCode 688 } 689 tracing.EndSpan(ctx, sc, err) 690 }() 691 } 692 req, err := client.UpdatePreparer(ctx, resourceGroupName, snapshotName, snapshot) 693 if err != nil { 694 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "Update", nil, "Failure preparing request") 695 return 696 } 697 698 result, err = client.UpdateSender(req) 699 if err != nil { 700 err = autorest.NewErrorWithError(err, "compute.SnapshotsClient", "Update", result.Response(), "Failure sending request") 701 return 702 } 703 704 return 705} 706 707// UpdatePreparer prepares the Update request. 708func (client SnapshotsClient) UpdatePreparer(ctx context.Context, resourceGroupName string, snapshotName string, snapshot SnapshotUpdate) (*http.Request, error) { 709 pathParameters := map[string]interface{}{ 710 "resourceGroupName": autorest.Encode("path", resourceGroupName), 711 "snapshotName": autorest.Encode("path", snapshotName), 712 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 713 } 714 715 const APIVersion = "2019-03-01" 716 queryParameters := map[string]interface{}{ 717 "api-version": APIVersion, 718 } 719 720 preparer := autorest.CreatePreparer( 721 autorest.AsContentType("application/json; charset=utf-8"), 722 autorest.AsPatch(), 723 autorest.WithBaseURL(client.BaseURI), 724 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/snapshots/{snapshotName}", pathParameters), 725 autorest.WithJSON(snapshot), 726 autorest.WithQueryParameters(queryParameters)) 727 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 728} 729 730// UpdateSender sends the Update request. The method will close the 731// http.Response Body if it receives an error. 732func (client SnapshotsClient) UpdateSender(req *http.Request) (future SnapshotsUpdateFuture, err error) { 733 var resp *http.Response 734 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 735 if err != nil { 736 return 737 } 738 future.Future, err = azure.NewFutureFromResponse(resp) 739 return 740} 741 742// UpdateResponder handles the response to the Update request. The method always 743// closes the http.Response Body. 744func (client SnapshotsClient) UpdateResponder(resp *http.Response) (result Snapshot, err error) { 745 err = autorest.Respond( 746 resp, 747 client.ByInspecting(), 748 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 749 autorest.ByUnmarshallingJSON(&result), 750 autorest.ByClosing()) 751 result.Response = autorest.Response{Response: resp} 752 return 753} 754