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. 40func NewDisksClientWithBaseURI(baseURI string, subscriptionID string) DisksClient { 41 return DisksClient{NewWithBaseURI(baseURI, subscriptionID)} 42} 43 44// CreateOrUpdate creates or updates a disk. 45// Parameters: 46// resourceGroupName - the name of the resource group. 47// diskName - the name of the managed disk that is being created. The name can't be changed after the disk is 48// created. Supported characters for the name are a-z, A-Z, 0-9 and _. The maximum name length is 80 49// characters. 50// disk - disk object supplied in the body of the Put disk operation. 51func (client DisksClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, diskName string, disk Disk) (result DisksCreateOrUpdateFuture, err error) { 52 if tracing.IsEnabled() { 53 ctx = tracing.StartSpan(ctx, fqdn+"/DisksClient.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: disk, 64 Constraints: []validation.Constraint{{Target: "disk.DiskProperties", Name: validation.Null, Rule: false, 65 Chain: []validation.Constraint{{Target: "disk.DiskProperties.CreationData", Name: validation.Null, Rule: true, 66 Chain: []validation.Constraint{{Target: "disk.DiskProperties.CreationData.ImageReference", Name: validation.Null, Rule: false, 67 Chain: []validation.Constraint{{Target: "disk.DiskProperties.CreationData.ImageReference.ID", Name: validation.Null, Rule: true, Chain: nil}}}, 68 }}, 69 {Target: "disk.DiskProperties.EncryptionSettings", Name: validation.Null, Rule: false, 70 Chain: []validation.Constraint{{Target: "disk.DiskProperties.EncryptionSettings.DiskEncryptionKey", Name: validation.Null, Rule: false, 71 Chain: []validation.Constraint{{Target: "disk.DiskProperties.EncryptionSettings.DiskEncryptionKey.SourceVault", Name: validation.Null, Rule: true, Chain: nil}, 72 {Target: "disk.DiskProperties.EncryptionSettings.DiskEncryptionKey.SecretURL", Name: validation.Null, Rule: true, Chain: nil}, 73 }}, 74 {Target: "disk.DiskProperties.EncryptionSettings.KeyEncryptionKey", Name: validation.Null, Rule: false, 75 Chain: []validation.Constraint{{Target: "disk.DiskProperties.EncryptionSettings.KeyEncryptionKey.SourceVault", Name: validation.Null, Rule: true, Chain: nil}, 76 {Target: "disk.DiskProperties.EncryptionSettings.KeyEncryptionKey.KeyURL", Name: validation.Null, Rule: true, Chain: nil}, 77 }}, 78 }}, 79 }}}}}); err != nil { 80 return result, validation.NewError("compute.DisksClient", "CreateOrUpdate", err.Error()) 81 } 82 83 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, diskName, disk) 84 if err != nil { 85 err = autorest.NewErrorWithError(err, "compute.DisksClient", "CreateOrUpdate", nil, "Failure preparing request") 86 return 87 } 88 89 result, err = client.CreateOrUpdateSender(req) 90 if err != nil { 91 err = autorest.NewErrorWithError(err, "compute.DisksClient", "CreateOrUpdate", result.Response(), "Failure sending request") 92 return 93 } 94 95 return 96} 97 98// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 99func (client DisksClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, diskName string, disk Disk) (*http.Request, error) { 100 pathParameters := map[string]interface{}{ 101 "diskName": autorest.Encode("path", diskName), 102 "resourceGroupName": autorest.Encode("path", resourceGroupName), 103 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 104 } 105 106 const APIVersion = "2018-06-01" 107 queryParameters := map[string]interface{}{ 108 "api-version": APIVersion, 109 } 110 111 preparer := autorest.CreatePreparer( 112 autorest.AsContentType("application/json; charset=utf-8"), 113 autorest.AsPut(), 114 autorest.WithBaseURL(client.BaseURI), 115 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks/{diskName}", pathParameters), 116 autorest.WithJSON(disk), 117 autorest.WithQueryParameters(queryParameters)) 118 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 119} 120 121// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 122// http.Response Body if it receives an error. 123func (client DisksClient) CreateOrUpdateSender(req *http.Request) (future DisksCreateOrUpdateFuture, err error) { 124 var resp *http.Response 125 resp, err = autorest.SendWithSender(client, req, 126 azure.DoRetryWithRegistration(client.Client)) 127 if err != nil { 128 return 129 } 130 future.Future, err = azure.NewFutureFromResponse(resp) 131 return 132} 133 134// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 135// closes the http.Response Body. 136func (client DisksClient) CreateOrUpdateResponder(resp *http.Response) (result Disk, err error) { 137 err = autorest.Respond( 138 resp, 139 client.ByInspecting(), 140 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 141 autorest.ByUnmarshallingJSON(&result), 142 autorest.ByClosing()) 143 result.Response = autorest.Response{Response: resp} 144 return 145} 146 147// Delete deletes a disk. 148// Parameters: 149// resourceGroupName - the name of the resource group. 150// diskName - the name of the managed disk that is being created. The name can't be changed after the disk is 151// created. Supported characters for the name are a-z, A-Z, 0-9 and _. The maximum name length is 80 152// characters. 153func (client DisksClient) Delete(ctx context.Context, resourceGroupName string, diskName string) (result DisksDeleteFuture, err error) { 154 if tracing.IsEnabled() { 155 ctx = tracing.StartSpan(ctx, fqdn+"/DisksClient.Delete") 156 defer func() { 157 sc := -1 158 if result.Response() != nil { 159 sc = result.Response().StatusCode 160 } 161 tracing.EndSpan(ctx, sc, err) 162 }() 163 } 164 req, err := client.DeletePreparer(ctx, resourceGroupName, diskName) 165 if err != nil { 166 err = autorest.NewErrorWithError(err, "compute.DisksClient", "Delete", nil, "Failure preparing request") 167 return 168 } 169 170 result, err = client.DeleteSender(req) 171 if err != nil { 172 err = autorest.NewErrorWithError(err, "compute.DisksClient", "Delete", result.Response(), "Failure sending request") 173 return 174 } 175 176 return 177} 178 179// DeletePreparer prepares the Delete request. 180func (client DisksClient) DeletePreparer(ctx context.Context, resourceGroupName string, diskName string) (*http.Request, error) { 181 pathParameters := map[string]interface{}{ 182 "diskName": autorest.Encode("path", diskName), 183 "resourceGroupName": autorest.Encode("path", resourceGroupName), 184 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 185 } 186 187 const APIVersion = "2018-06-01" 188 queryParameters := map[string]interface{}{ 189 "api-version": APIVersion, 190 } 191 192 preparer := autorest.CreatePreparer( 193 autorest.AsDelete(), 194 autorest.WithBaseURL(client.BaseURI), 195 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks/{diskName}", pathParameters), 196 autorest.WithQueryParameters(queryParameters)) 197 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 198} 199 200// DeleteSender sends the Delete request. The method will close the 201// http.Response Body if it receives an error. 202func (client DisksClient) DeleteSender(req *http.Request) (future DisksDeleteFuture, err error) { 203 var resp *http.Response 204 resp, err = autorest.SendWithSender(client, req, 205 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 autorest.Response, err error) { 216 err = autorest.Respond( 217 resp, 218 client.ByInspecting(), 219 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 220 autorest.ByClosing()) 221 result.Response = resp 222 return 223} 224 225// Get gets information about a disk. 226// Parameters: 227// resourceGroupName - the name of the resource group. 228// diskName - the name of the managed disk that is being created. The name can't be changed after the disk is 229// created. Supported characters for the name are a-z, A-Z, 0-9 and _. The maximum name length is 80 230// characters. 231func (client DisksClient) Get(ctx context.Context, resourceGroupName string, diskName string) (result Disk, err error) { 232 if tracing.IsEnabled() { 233 ctx = tracing.StartSpan(ctx, fqdn+"/DisksClient.Get") 234 defer func() { 235 sc := -1 236 if result.Response.Response != nil { 237 sc = result.Response.Response.StatusCode 238 } 239 tracing.EndSpan(ctx, sc, err) 240 }() 241 } 242 req, err := client.GetPreparer(ctx, resourceGroupName, diskName) 243 if err != nil { 244 err = autorest.NewErrorWithError(err, "compute.DisksClient", "Get", nil, "Failure preparing request") 245 return 246 } 247 248 resp, err := client.GetSender(req) 249 if err != nil { 250 result.Response = autorest.Response{Response: resp} 251 err = autorest.NewErrorWithError(err, "compute.DisksClient", "Get", resp, "Failure sending request") 252 return 253 } 254 255 result, err = client.GetResponder(resp) 256 if err != nil { 257 err = autorest.NewErrorWithError(err, "compute.DisksClient", "Get", resp, "Failure responding to request") 258 } 259 260 return 261} 262 263// GetPreparer prepares the Get request. 264func (client DisksClient) GetPreparer(ctx context.Context, resourceGroupName string, diskName string) (*http.Request, error) { 265 pathParameters := map[string]interface{}{ 266 "diskName": autorest.Encode("path", diskName), 267 "resourceGroupName": autorest.Encode("path", resourceGroupName), 268 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 269 } 270 271 const APIVersion = "2018-06-01" 272 queryParameters := map[string]interface{}{ 273 "api-version": APIVersion, 274 } 275 276 preparer := autorest.CreatePreparer( 277 autorest.AsGet(), 278 autorest.WithBaseURL(client.BaseURI), 279 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks/{diskName}", pathParameters), 280 autorest.WithQueryParameters(queryParameters)) 281 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 282} 283 284// GetSender sends the Get request. The method will close the 285// http.Response Body if it receives an error. 286func (client DisksClient) GetSender(req *http.Request) (*http.Response, error) { 287 return autorest.SendWithSender(client, req, 288 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 = "2018-06-01" 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 = autorest.SendWithSender(client, req, 371 azure.DoRetryWithRegistration(client.Client)) 372 if err != nil { 373 return 374 } 375 future.Future, err = azure.NewFutureFromResponse(resp) 376 return 377} 378 379// GrantAccessResponder handles the response to the GrantAccess request. The method always 380// closes the http.Response Body. 381func (client DisksClient) GrantAccessResponder(resp *http.Response) (result AccessURI, err error) { 382 err = autorest.Respond( 383 resp, 384 client.ByInspecting(), 385 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 386 autorest.ByUnmarshallingJSON(&result), 387 autorest.ByClosing()) 388 result.Response = autorest.Response{Response: resp} 389 return 390} 391 392// List lists all the disks under a subscription. 393func (client DisksClient) List(ctx context.Context) (result DiskListPage, err error) { 394 if tracing.IsEnabled() { 395 ctx = tracing.StartSpan(ctx, fqdn+"/DisksClient.List") 396 defer func() { 397 sc := -1 398 if result.dl.Response.Response != nil { 399 sc = result.dl.Response.Response.StatusCode 400 } 401 tracing.EndSpan(ctx, sc, err) 402 }() 403 } 404 result.fn = client.listNextResults 405 req, err := client.ListPreparer(ctx) 406 if err != nil { 407 err = autorest.NewErrorWithError(err, "compute.DisksClient", "List", nil, "Failure preparing request") 408 return 409 } 410 411 resp, err := client.ListSender(req) 412 if err != nil { 413 result.dl.Response = autorest.Response{Response: resp} 414 err = autorest.NewErrorWithError(err, "compute.DisksClient", "List", resp, "Failure sending request") 415 return 416 } 417 418 result.dl, err = client.ListResponder(resp) 419 if err != nil { 420 err = autorest.NewErrorWithError(err, "compute.DisksClient", "List", resp, "Failure responding to request") 421 } 422 423 return 424} 425 426// ListPreparer prepares the List request. 427func (client DisksClient) ListPreparer(ctx context.Context) (*http.Request, error) { 428 pathParameters := map[string]interface{}{ 429 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 430 } 431 432 const APIVersion = "2018-06-01" 433 queryParameters := map[string]interface{}{ 434 "api-version": APIVersion, 435 } 436 437 preparer := autorest.CreatePreparer( 438 autorest.AsGet(), 439 autorest.WithBaseURL(client.BaseURI), 440 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/disks", pathParameters), 441 autorest.WithQueryParameters(queryParameters)) 442 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 443} 444 445// ListSender sends the List request. The method will close the 446// http.Response Body if it receives an error. 447func (client DisksClient) ListSender(req *http.Request) (*http.Response, error) { 448 return autorest.SendWithSender(client, req, 449 azure.DoRetryWithRegistration(client.Client)) 450} 451 452// ListResponder handles the response to the List request. The method always 453// closes the http.Response Body. 454func (client DisksClient) ListResponder(resp *http.Response) (result DiskList, err error) { 455 err = autorest.Respond( 456 resp, 457 client.ByInspecting(), 458 azure.WithErrorUnlessStatusCode(http.StatusOK), 459 autorest.ByUnmarshallingJSON(&result), 460 autorest.ByClosing()) 461 result.Response = autorest.Response{Response: resp} 462 return 463} 464 465// listNextResults retrieves the next set of results, if any. 466func (client DisksClient) listNextResults(ctx context.Context, lastResults DiskList) (result DiskList, err error) { 467 req, err := lastResults.diskListPreparer(ctx) 468 if err != nil { 469 return result, autorest.NewErrorWithError(err, "compute.DisksClient", "listNextResults", nil, "Failure preparing next results request") 470 } 471 if req == nil { 472 return 473 } 474 resp, err := client.ListSender(req) 475 if err != nil { 476 result.Response = autorest.Response{Response: resp} 477 return result, autorest.NewErrorWithError(err, "compute.DisksClient", "listNextResults", resp, "Failure sending next results request") 478 } 479 result, err = client.ListResponder(resp) 480 if err != nil { 481 err = autorest.NewErrorWithError(err, "compute.DisksClient", "listNextResults", resp, "Failure responding to next results request") 482 } 483 return 484} 485 486// ListComplete enumerates all values, automatically crossing page boundaries as required. 487func (client DisksClient) ListComplete(ctx context.Context) (result DiskListIterator, err error) { 488 if tracing.IsEnabled() { 489 ctx = tracing.StartSpan(ctx, fqdn+"/DisksClient.List") 490 defer func() { 491 sc := -1 492 if result.Response().Response.Response != nil { 493 sc = result.page.Response().Response.Response.StatusCode 494 } 495 tracing.EndSpan(ctx, sc, err) 496 }() 497 } 498 result.page, err = client.List(ctx) 499 return 500} 501 502// ListByResourceGroup lists all the disks under a resource group. 503// Parameters: 504// resourceGroupName - the name of the resource group. 505func (client DisksClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result DiskListPage, err error) { 506 if tracing.IsEnabled() { 507 ctx = tracing.StartSpan(ctx, fqdn+"/DisksClient.ListByResourceGroup") 508 defer func() { 509 sc := -1 510 if result.dl.Response.Response != nil { 511 sc = result.dl.Response.Response.StatusCode 512 } 513 tracing.EndSpan(ctx, sc, err) 514 }() 515 } 516 result.fn = client.listByResourceGroupNextResults 517 req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName) 518 if err != nil { 519 err = autorest.NewErrorWithError(err, "compute.DisksClient", "ListByResourceGroup", nil, "Failure preparing request") 520 return 521 } 522 523 resp, err := client.ListByResourceGroupSender(req) 524 if err != nil { 525 result.dl.Response = autorest.Response{Response: resp} 526 err = autorest.NewErrorWithError(err, "compute.DisksClient", "ListByResourceGroup", resp, "Failure sending request") 527 return 528 } 529 530 result.dl, err = client.ListByResourceGroupResponder(resp) 531 if err != nil { 532 err = autorest.NewErrorWithError(err, "compute.DisksClient", "ListByResourceGroup", resp, "Failure responding to request") 533 } 534 535 return 536} 537 538// ListByResourceGroupPreparer prepares the ListByResourceGroup request. 539func (client DisksClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) { 540 pathParameters := map[string]interface{}{ 541 "resourceGroupName": autorest.Encode("path", resourceGroupName), 542 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 543 } 544 545 const APIVersion = "2018-06-01" 546 queryParameters := map[string]interface{}{ 547 "api-version": APIVersion, 548 } 549 550 preparer := autorest.CreatePreparer( 551 autorest.AsGet(), 552 autorest.WithBaseURL(client.BaseURI), 553 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks", pathParameters), 554 autorest.WithQueryParameters(queryParameters)) 555 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 556} 557 558// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the 559// http.Response Body if it receives an error. 560func (client DisksClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { 561 return autorest.SendWithSender(client, req, 562 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 client.ByInspecting(), 571 azure.WithErrorUnlessStatusCode(http.StatusOK), 572 autorest.ByUnmarshallingJSON(&result), 573 autorest.ByClosing()) 574 result.Response = autorest.Response{Response: resp} 575 return 576} 577 578// listByResourceGroupNextResults retrieves the next set of results, if any. 579func (client DisksClient) listByResourceGroupNextResults(ctx context.Context, lastResults DiskList) (result DiskList, err error) { 580 req, err := lastResults.diskListPreparer(ctx) 581 if err != nil { 582 return result, autorest.NewErrorWithError(err, "compute.DisksClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request") 583 } 584 if req == nil { 585 return 586 } 587 resp, err := client.ListByResourceGroupSender(req) 588 if err != nil { 589 result.Response = autorest.Response{Response: resp} 590 return result, autorest.NewErrorWithError(err, "compute.DisksClient", "listByResourceGroupNextResults", resp, "Failure sending next results request") 591 } 592 result, err = client.ListByResourceGroupResponder(resp) 593 if err != nil { 594 err = autorest.NewErrorWithError(err, "compute.DisksClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request") 595 } 596 return 597} 598 599// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required. 600func (client DisksClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result DiskListIterator, err error) { 601 if tracing.IsEnabled() { 602 ctx = tracing.StartSpan(ctx, fqdn+"/DisksClient.ListByResourceGroup") 603 defer func() { 604 sc := -1 605 if result.Response().Response.Response != nil { 606 sc = result.page.Response().Response.Response.StatusCode 607 } 608 tracing.EndSpan(ctx, sc, err) 609 }() 610 } 611 result.page, err = client.ListByResourceGroup(ctx, resourceGroupName) 612 return 613} 614 615// RevokeAccess revokes access to a disk. 616// Parameters: 617// resourceGroupName - the name of the resource group. 618// diskName - the name of the managed disk that is being created. The name can't be changed after the disk is 619// created. Supported characters for the name are a-z, A-Z, 0-9 and _. The maximum name length is 80 620// characters. 621func (client DisksClient) RevokeAccess(ctx context.Context, resourceGroupName string, diskName string) (result DisksRevokeAccessFuture, err error) { 622 if tracing.IsEnabled() { 623 ctx = tracing.StartSpan(ctx, fqdn+"/DisksClient.RevokeAccess") 624 defer func() { 625 sc := -1 626 if result.Response() != nil { 627 sc = result.Response().StatusCode 628 } 629 tracing.EndSpan(ctx, sc, err) 630 }() 631 } 632 req, err := client.RevokeAccessPreparer(ctx, resourceGroupName, diskName) 633 if err != nil { 634 err = autorest.NewErrorWithError(err, "compute.DisksClient", "RevokeAccess", nil, "Failure preparing request") 635 return 636 } 637 638 result, err = client.RevokeAccessSender(req) 639 if err != nil { 640 err = autorest.NewErrorWithError(err, "compute.DisksClient", "RevokeAccess", result.Response(), "Failure sending request") 641 return 642 } 643 644 return 645} 646 647// RevokeAccessPreparer prepares the RevokeAccess request. 648func (client DisksClient) RevokeAccessPreparer(ctx context.Context, resourceGroupName string, diskName string) (*http.Request, error) { 649 pathParameters := map[string]interface{}{ 650 "diskName": autorest.Encode("path", diskName), 651 "resourceGroupName": autorest.Encode("path", resourceGroupName), 652 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 653 } 654 655 const APIVersion = "2018-06-01" 656 queryParameters := map[string]interface{}{ 657 "api-version": APIVersion, 658 } 659 660 preparer := autorest.CreatePreparer( 661 autorest.AsPost(), 662 autorest.WithBaseURL(client.BaseURI), 663 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disks/{diskName}/endGetAccess", pathParameters), 664 autorest.WithQueryParameters(queryParameters)) 665 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 666} 667 668// RevokeAccessSender sends the RevokeAccess request. The method will close the 669// http.Response Body if it receives an error. 670func (client DisksClient) RevokeAccessSender(req *http.Request) (future DisksRevokeAccessFuture, err error) { 671 var resp *http.Response 672 resp, err = autorest.SendWithSender(client, req, 673 azure.DoRetryWithRegistration(client.Client)) 674 if err != nil { 675 return 676 } 677 future.Future, err = azure.NewFutureFromResponse(resp) 678 return 679} 680 681// RevokeAccessResponder handles the response to the RevokeAccess request. The method always 682// closes the http.Response Body. 683func (client DisksClient) RevokeAccessResponder(resp *http.Response) (result autorest.Response, err error) { 684 err = autorest.Respond( 685 resp, 686 client.ByInspecting(), 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.Response() != nil { 706 sc = result.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", result.Response(), "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 = autorest.SendWithSender(client, req, 754 azure.DoRetryWithRegistration(client.Client)) 755 if err != nil { 756 return 757 } 758 future.Future, err = azure.NewFutureFromResponse(resp) 759 return 760} 761 762// UpdateResponder handles the response to the Update request. The method always 763// closes the http.Response Body. 764func (client DisksClient) UpdateResponder(resp *http.Response) (result Disk, err error) { 765 err = autorest.Respond( 766 resp, 767 client.ByInspecting(), 768 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 769 autorest.ByUnmarshallingJSON(&result), 770 autorest.ByClosing()) 771 result.Response = autorest.Response{Response: resp} 772 return 773} 774