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