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