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/tracing" 25 "net/http" 26) 27 28// ImagesClient is the compute Client 29type ImagesClient struct { 30 BaseClient 31} 32 33// NewImagesClient creates an instance of the ImagesClient client. 34func NewImagesClient(subscriptionID string) ImagesClient { 35 return NewImagesClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewImagesClientWithBaseURI creates an instance of the ImagesClient client using a custom endpoint. Use this when 39// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 40func NewImagesClientWithBaseURI(baseURI string, subscriptionID string) ImagesClient { 41 return ImagesClient{NewWithBaseURI(baseURI, subscriptionID)} 42} 43 44// CreateOrUpdate create or update an image. 45// Parameters: 46// resourceGroupName - the name of the resource group. 47// imageName - the name of the image. 48// parameters - parameters supplied to the Create Image operation. 49func (client ImagesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, imageName string, parameters Image) (result ImagesCreateOrUpdateFuture, err error) { 50 if tracing.IsEnabled() { 51 ctx = tracing.StartSpan(ctx, fqdn+"/ImagesClient.CreateOrUpdate") 52 defer func() { 53 sc := -1 54 if result.Response() != nil { 55 sc = result.Response().StatusCode 56 } 57 tracing.EndSpan(ctx, sc, err) 58 }() 59 } 60 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, imageName, parameters) 61 if err != nil { 62 err = autorest.NewErrorWithError(err, "compute.ImagesClient", "CreateOrUpdate", nil, "Failure preparing request") 63 return 64 } 65 66 result, err = client.CreateOrUpdateSender(req) 67 if err != nil { 68 err = autorest.NewErrorWithError(err, "compute.ImagesClient", "CreateOrUpdate", nil, "Failure sending request") 69 return 70 } 71 72 return 73} 74 75// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 76func (client ImagesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, imageName string, parameters Image) (*http.Request, error) { 77 pathParameters := map[string]interface{}{ 78 "imageName": autorest.Encode("path", imageName), 79 "resourceGroupName": autorest.Encode("path", resourceGroupName), 80 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 81 } 82 83 const APIVersion = "2017-12-01" 84 queryParameters := map[string]interface{}{ 85 "api-version": APIVersion, 86 } 87 88 preparer := autorest.CreatePreparer( 89 autorest.AsContentType("application/json; charset=utf-8"), 90 autorest.AsPut(), 91 autorest.WithBaseURL(client.BaseURI), 92 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/images/{imageName}", pathParameters), 93 autorest.WithJSON(parameters), 94 autorest.WithQueryParameters(queryParameters)) 95 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 96} 97 98// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 99// http.Response Body if it receives an error. 100func (client ImagesClient) CreateOrUpdateSender(req *http.Request) (future ImagesCreateOrUpdateFuture, err error) { 101 var resp *http.Response 102 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 103 if err != nil { 104 return 105 } 106 var azf azure.Future 107 azf, err = azure.NewFutureFromResponse(resp) 108 future.FutureAPI = &azf 109 future.Result = func(client ImagesClient) (i Image, err error) { 110 var done bool 111 done, err = future.DoneWithContext(context.Background(), client) 112 if err != nil { 113 err = autorest.NewErrorWithError(err, "compute.ImagesCreateOrUpdateFuture", "Result", future.Response(), "Polling failure") 114 return 115 } 116 if !done { 117 err = azure.NewAsyncOpIncompleteError("compute.ImagesCreateOrUpdateFuture") 118 return 119 } 120 sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 121 if i.Response.Response, err = future.GetResult(sender); err == nil && i.Response.Response.StatusCode != http.StatusNoContent { 122 i, err = client.CreateOrUpdateResponder(i.Response.Response) 123 if err != nil { 124 err = autorest.NewErrorWithError(err, "compute.ImagesCreateOrUpdateFuture", "Result", i.Response.Response, "Failure responding to request") 125 } 126 } 127 return 128 } 129 return 130} 131 132// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 133// closes the http.Response Body. 134func (client ImagesClient) CreateOrUpdateResponder(resp *http.Response) (result Image, err error) { 135 err = autorest.Respond( 136 resp, 137 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 138 autorest.ByUnmarshallingJSON(&result), 139 autorest.ByClosing()) 140 result.Response = autorest.Response{Response: resp} 141 return 142} 143 144// Delete deletes an Image. 145// Parameters: 146// resourceGroupName - the name of the resource group. 147// imageName - the name of the image. 148func (client ImagesClient) Delete(ctx context.Context, resourceGroupName string, imageName string) (result ImagesDeleteFuture, err error) { 149 if tracing.IsEnabled() { 150 ctx = tracing.StartSpan(ctx, fqdn+"/ImagesClient.Delete") 151 defer func() { 152 sc := -1 153 if result.Response() != nil { 154 sc = result.Response().StatusCode 155 } 156 tracing.EndSpan(ctx, sc, err) 157 }() 158 } 159 req, err := client.DeletePreparer(ctx, resourceGroupName, imageName) 160 if err != nil { 161 err = autorest.NewErrorWithError(err, "compute.ImagesClient", "Delete", nil, "Failure preparing request") 162 return 163 } 164 165 result, err = client.DeleteSender(req) 166 if err != nil { 167 err = autorest.NewErrorWithError(err, "compute.ImagesClient", "Delete", nil, "Failure sending request") 168 return 169 } 170 171 return 172} 173 174// DeletePreparer prepares the Delete request. 175func (client ImagesClient) DeletePreparer(ctx context.Context, resourceGroupName string, imageName string) (*http.Request, error) { 176 pathParameters := map[string]interface{}{ 177 "imageName": autorest.Encode("path", imageName), 178 "resourceGroupName": autorest.Encode("path", resourceGroupName), 179 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 180 } 181 182 const APIVersion = "2017-12-01" 183 queryParameters := map[string]interface{}{ 184 "api-version": APIVersion, 185 } 186 187 preparer := autorest.CreatePreparer( 188 autorest.AsDelete(), 189 autorest.WithBaseURL(client.BaseURI), 190 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/images/{imageName}", pathParameters), 191 autorest.WithQueryParameters(queryParameters)) 192 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 193} 194 195// DeleteSender sends the Delete request. The method will close the 196// http.Response Body if it receives an error. 197func (client ImagesClient) DeleteSender(req *http.Request) (future ImagesDeleteFuture, err error) { 198 var resp *http.Response 199 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 200 if err != nil { 201 return 202 } 203 var azf azure.Future 204 azf, err = azure.NewFutureFromResponse(resp) 205 future.FutureAPI = &azf 206 future.Result = func(client ImagesClient) (osr OperationStatusResponse, err error) { 207 var done bool 208 done, err = future.DoneWithContext(context.Background(), client) 209 if err != nil { 210 err = autorest.NewErrorWithError(err, "compute.ImagesDeleteFuture", "Result", future.Response(), "Polling failure") 211 return 212 } 213 if !done { 214 err = azure.NewAsyncOpIncompleteError("compute.ImagesDeleteFuture") 215 return 216 } 217 sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 218 if osr.Response.Response, err = future.GetResult(sender); err == nil && osr.Response.Response.StatusCode != http.StatusNoContent { 219 osr, err = client.DeleteResponder(osr.Response.Response) 220 if err != nil { 221 err = autorest.NewErrorWithError(err, "compute.ImagesDeleteFuture", "Result", osr.Response.Response, "Failure responding to request") 222 } 223 } 224 return 225 } 226 return 227} 228 229// DeleteResponder handles the response to the Delete request. The method always 230// closes the http.Response Body. 231func (client ImagesClient) DeleteResponder(resp *http.Response) (result OperationStatusResponse, err error) { 232 err = autorest.Respond( 233 resp, 234 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 235 autorest.ByUnmarshallingJSON(&result), 236 autorest.ByClosing()) 237 result.Response = autorest.Response{Response: resp} 238 return 239} 240 241// Get gets an image. 242// Parameters: 243// resourceGroupName - the name of the resource group. 244// imageName - the name of the image. 245// expand - the expand expression to apply on the operation. 246func (client ImagesClient) Get(ctx context.Context, resourceGroupName string, imageName string, expand string) (result Image, err error) { 247 if tracing.IsEnabled() { 248 ctx = tracing.StartSpan(ctx, fqdn+"/ImagesClient.Get") 249 defer func() { 250 sc := -1 251 if result.Response.Response != nil { 252 sc = result.Response.Response.StatusCode 253 } 254 tracing.EndSpan(ctx, sc, err) 255 }() 256 } 257 req, err := client.GetPreparer(ctx, resourceGroupName, imageName, expand) 258 if err != nil { 259 err = autorest.NewErrorWithError(err, "compute.ImagesClient", "Get", nil, "Failure preparing request") 260 return 261 } 262 263 resp, err := client.GetSender(req) 264 if err != nil { 265 result.Response = autorest.Response{Response: resp} 266 err = autorest.NewErrorWithError(err, "compute.ImagesClient", "Get", resp, "Failure sending request") 267 return 268 } 269 270 result, err = client.GetResponder(resp) 271 if err != nil { 272 err = autorest.NewErrorWithError(err, "compute.ImagesClient", "Get", resp, "Failure responding to request") 273 return 274 } 275 276 return 277} 278 279// GetPreparer prepares the Get request. 280func (client ImagesClient) GetPreparer(ctx context.Context, resourceGroupName string, imageName string, expand string) (*http.Request, error) { 281 pathParameters := map[string]interface{}{ 282 "imageName": autorest.Encode("path", imageName), 283 "resourceGroupName": autorest.Encode("path", resourceGroupName), 284 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 285 } 286 287 const APIVersion = "2017-12-01" 288 queryParameters := map[string]interface{}{ 289 "api-version": APIVersion, 290 } 291 if len(expand) > 0 { 292 queryParameters["$expand"] = autorest.Encode("query", expand) 293 } 294 295 preparer := autorest.CreatePreparer( 296 autorest.AsGet(), 297 autorest.WithBaseURL(client.BaseURI), 298 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/images/{imageName}", pathParameters), 299 autorest.WithQueryParameters(queryParameters)) 300 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 301} 302 303// GetSender sends the Get request. The method will close the 304// http.Response Body if it receives an error. 305func (client ImagesClient) GetSender(req *http.Request) (*http.Response, error) { 306 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 307} 308 309// GetResponder handles the response to the Get request. The method always 310// closes the http.Response Body. 311func (client ImagesClient) GetResponder(resp *http.Response) (result Image, err error) { 312 err = autorest.Respond( 313 resp, 314 azure.WithErrorUnlessStatusCode(http.StatusOK), 315 autorest.ByUnmarshallingJSON(&result), 316 autorest.ByClosing()) 317 result.Response = autorest.Response{Response: resp} 318 return 319} 320 321// List gets the list of Images in the subscription. Use nextLink property in the response to get the next page of 322// Images. Do this till nextLink is null to fetch all the Images. 323func (client ImagesClient) List(ctx context.Context) (result ImageListResultPage, err error) { 324 if tracing.IsEnabled() { 325 ctx = tracing.StartSpan(ctx, fqdn+"/ImagesClient.List") 326 defer func() { 327 sc := -1 328 if result.ilr.Response.Response != nil { 329 sc = result.ilr.Response.Response.StatusCode 330 } 331 tracing.EndSpan(ctx, sc, err) 332 }() 333 } 334 result.fn = client.listNextResults 335 req, err := client.ListPreparer(ctx) 336 if err != nil { 337 err = autorest.NewErrorWithError(err, "compute.ImagesClient", "List", nil, "Failure preparing request") 338 return 339 } 340 341 resp, err := client.ListSender(req) 342 if err != nil { 343 result.ilr.Response = autorest.Response{Response: resp} 344 err = autorest.NewErrorWithError(err, "compute.ImagesClient", "List", resp, "Failure sending request") 345 return 346 } 347 348 result.ilr, err = client.ListResponder(resp) 349 if err != nil { 350 err = autorest.NewErrorWithError(err, "compute.ImagesClient", "List", resp, "Failure responding to request") 351 return 352 } 353 if result.ilr.hasNextLink() && result.ilr.IsEmpty() { 354 err = result.NextWithContext(ctx) 355 return 356 } 357 358 return 359} 360 361// ListPreparer prepares the List request. 362func (client ImagesClient) ListPreparer(ctx context.Context) (*http.Request, error) { 363 pathParameters := map[string]interface{}{ 364 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 365 } 366 367 const APIVersion = "2017-12-01" 368 queryParameters := map[string]interface{}{ 369 "api-version": APIVersion, 370 } 371 372 preparer := autorest.CreatePreparer( 373 autorest.AsGet(), 374 autorest.WithBaseURL(client.BaseURI), 375 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/images", pathParameters), 376 autorest.WithQueryParameters(queryParameters)) 377 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 378} 379 380// ListSender sends the List request. The method will close the 381// http.Response Body if it receives an error. 382func (client ImagesClient) ListSender(req *http.Request) (*http.Response, error) { 383 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 384} 385 386// ListResponder handles the response to the List request. The method always 387// closes the http.Response Body. 388func (client ImagesClient) ListResponder(resp *http.Response) (result ImageListResult, err error) { 389 err = autorest.Respond( 390 resp, 391 azure.WithErrorUnlessStatusCode(http.StatusOK), 392 autorest.ByUnmarshallingJSON(&result), 393 autorest.ByClosing()) 394 result.Response = autorest.Response{Response: resp} 395 return 396} 397 398// listNextResults retrieves the next set of results, if any. 399func (client ImagesClient) listNextResults(ctx context.Context, lastResults ImageListResult) (result ImageListResult, err error) { 400 req, err := lastResults.imageListResultPreparer(ctx) 401 if err != nil { 402 return result, autorest.NewErrorWithError(err, "compute.ImagesClient", "listNextResults", nil, "Failure preparing next results request") 403 } 404 if req == nil { 405 return 406 } 407 resp, err := client.ListSender(req) 408 if err != nil { 409 result.Response = autorest.Response{Response: resp} 410 return result, autorest.NewErrorWithError(err, "compute.ImagesClient", "listNextResults", resp, "Failure sending next results request") 411 } 412 result, err = client.ListResponder(resp) 413 if err != nil { 414 err = autorest.NewErrorWithError(err, "compute.ImagesClient", "listNextResults", resp, "Failure responding to next results request") 415 } 416 return 417} 418 419// ListComplete enumerates all values, automatically crossing page boundaries as required. 420func (client ImagesClient) ListComplete(ctx context.Context) (result ImageListResultIterator, err error) { 421 if tracing.IsEnabled() { 422 ctx = tracing.StartSpan(ctx, fqdn+"/ImagesClient.List") 423 defer func() { 424 sc := -1 425 if result.Response().Response.Response != nil { 426 sc = result.page.Response().Response.Response.StatusCode 427 } 428 tracing.EndSpan(ctx, sc, err) 429 }() 430 } 431 result.page, err = client.List(ctx) 432 return 433} 434 435// ListByResourceGroup gets the list of images under a resource group. 436// Parameters: 437// resourceGroupName - the name of the resource group. 438func (client ImagesClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result ImageListResultPage, err error) { 439 if tracing.IsEnabled() { 440 ctx = tracing.StartSpan(ctx, fqdn+"/ImagesClient.ListByResourceGroup") 441 defer func() { 442 sc := -1 443 if result.ilr.Response.Response != nil { 444 sc = result.ilr.Response.Response.StatusCode 445 } 446 tracing.EndSpan(ctx, sc, err) 447 }() 448 } 449 result.fn = client.listByResourceGroupNextResults 450 req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName) 451 if err != nil { 452 err = autorest.NewErrorWithError(err, "compute.ImagesClient", "ListByResourceGroup", nil, "Failure preparing request") 453 return 454 } 455 456 resp, err := client.ListByResourceGroupSender(req) 457 if err != nil { 458 result.ilr.Response = autorest.Response{Response: resp} 459 err = autorest.NewErrorWithError(err, "compute.ImagesClient", "ListByResourceGroup", resp, "Failure sending request") 460 return 461 } 462 463 result.ilr, err = client.ListByResourceGroupResponder(resp) 464 if err != nil { 465 err = autorest.NewErrorWithError(err, "compute.ImagesClient", "ListByResourceGroup", resp, "Failure responding to request") 466 return 467 } 468 if result.ilr.hasNextLink() && result.ilr.IsEmpty() { 469 err = result.NextWithContext(ctx) 470 return 471 } 472 473 return 474} 475 476// ListByResourceGroupPreparer prepares the ListByResourceGroup request. 477func (client ImagesClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) { 478 pathParameters := map[string]interface{}{ 479 "resourceGroupName": autorest.Encode("path", resourceGroupName), 480 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 481 } 482 483 const APIVersion = "2017-12-01" 484 queryParameters := map[string]interface{}{ 485 "api-version": APIVersion, 486 } 487 488 preparer := autorest.CreatePreparer( 489 autorest.AsGet(), 490 autorest.WithBaseURL(client.BaseURI), 491 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/images", pathParameters), 492 autorest.WithQueryParameters(queryParameters)) 493 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 494} 495 496// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the 497// http.Response Body if it receives an error. 498func (client ImagesClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { 499 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 500} 501 502// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always 503// closes the http.Response Body. 504func (client ImagesClient) ListByResourceGroupResponder(resp *http.Response) (result ImageListResult, err error) { 505 err = autorest.Respond( 506 resp, 507 azure.WithErrorUnlessStatusCode(http.StatusOK), 508 autorest.ByUnmarshallingJSON(&result), 509 autorest.ByClosing()) 510 result.Response = autorest.Response{Response: resp} 511 return 512} 513 514// listByResourceGroupNextResults retrieves the next set of results, if any. 515func (client ImagesClient) listByResourceGroupNextResults(ctx context.Context, lastResults ImageListResult) (result ImageListResult, err error) { 516 req, err := lastResults.imageListResultPreparer(ctx) 517 if err != nil { 518 return result, autorest.NewErrorWithError(err, "compute.ImagesClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request") 519 } 520 if req == nil { 521 return 522 } 523 resp, err := client.ListByResourceGroupSender(req) 524 if err != nil { 525 result.Response = autorest.Response{Response: resp} 526 return result, autorest.NewErrorWithError(err, "compute.ImagesClient", "listByResourceGroupNextResults", resp, "Failure sending next results request") 527 } 528 result, err = client.ListByResourceGroupResponder(resp) 529 if err != nil { 530 err = autorest.NewErrorWithError(err, "compute.ImagesClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request") 531 } 532 return 533} 534 535// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required. 536func (client ImagesClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result ImageListResultIterator, err error) { 537 if tracing.IsEnabled() { 538 ctx = tracing.StartSpan(ctx, fqdn+"/ImagesClient.ListByResourceGroup") 539 defer func() { 540 sc := -1 541 if result.Response().Response.Response != nil { 542 sc = result.page.Response().Response.Response.StatusCode 543 } 544 tracing.EndSpan(ctx, sc, err) 545 }() 546 } 547 result.page, err = client.ListByResourceGroup(ctx, resourceGroupName) 548 return 549} 550 551// Update update an image. 552// Parameters: 553// resourceGroupName - the name of the resource group. 554// imageName - the name of the image. 555// parameters - parameters supplied to the Update Image operation. 556func (client ImagesClient) Update(ctx context.Context, resourceGroupName string, imageName string, parameters ImageUpdate) (result ImagesUpdateFuture, err error) { 557 if tracing.IsEnabled() { 558 ctx = tracing.StartSpan(ctx, fqdn+"/ImagesClient.Update") 559 defer func() { 560 sc := -1 561 if result.Response() != nil { 562 sc = result.Response().StatusCode 563 } 564 tracing.EndSpan(ctx, sc, err) 565 }() 566 } 567 req, err := client.UpdatePreparer(ctx, resourceGroupName, imageName, parameters) 568 if err != nil { 569 err = autorest.NewErrorWithError(err, "compute.ImagesClient", "Update", nil, "Failure preparing request") 570 return 571 } 572 573 result, err = client.UpdateSender(req) 574 if err != nil { 575 err = autorest.NewErrorWithError(err, "compute.ImagesClient", "Update", nil, "Failure sending request") 576 return 577 } 578 579 return 580} 581 582// UpdatePreparer prepares the Update request. 583func (client ImagesClient) UpdatePreparer(ctx context.Context, resourceGroupName string, imageName string, parameters ImageUpdate) (*http.Request, error) { 584 pathParameters := map[string]interface{}{ 585 "imageName": autorest.Encode("path", imageName), 586 "resourceGroupName": autorest.Encode("path", resourceGroupName), 587 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 588 } 589 590 const APIVersion = "2017-12-01" 591 queryParameters := map[string]interface{}{ 592 "api-version": APIVersion, 593 } 594 595 preparer := autorest.CreatePreparer( 596 autorest.AsContentType("application/json; charset=utf-8"), 597 autorest.AsPatch(), 598 autorest.WithBaseURL(client.BaseURI), 599 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/images/{imageName}", pathParameters), 600 autorest.WithJSON(parameters), 601 autorest.WithQueryParameters(queryParameters)) 602 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 603} 604 605// UpdateSender sends the Update request. The method will close the 606// http.Response Body if it receives an error. 607func (client ImagesClient) UpdateSender(req *http.Request) (future ImagesUpdateFuture, err error) { 608 var resp *http.Response 609 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 610 if err != nil { 611 return 612 } 613 var azf azure.Future 614 azf, err = azure.NewFutureFromResponse(resp) 615 future.FutureAPI = &azf 616 future.Result = func(client ImagesClient) (i Image, err error) { 617 var done bool 618 done, err = future.DoneWithContext(context.Background(), client) 619 if err != nil { 620 err = autorest.NewErrorWithError(err, "compute.ImagesUpdateFuture", "Result", future.Response(), "Polling failure") 621 return 622 } 623 if !done { 624 err = azure.NewAsyncOpIncompleteError("compute.ImagesUpdateFuture") 625 return 626 } 627 sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 628 if i.Response.Response, err = future.GetResult(sender); err == nil && i.Response.Response.StatusCode != http.StatusNoContent { 629 i, err = client.UpdateResponder(i.Response.Response) 630 if err != nil { 631 err = autorest.NewErrorWithError(err, "compute.ImagesUpdateFuture", "Result", i.Response.Response, "Failure responding to request") 632 } 633 } 634 return 635 } 636 return 637} 638 639// UpdateResponder handles the response to the Update request. The method always 640// closes the http.Response Body. 641func (client ImagesClient) UpdateResponder(resp *http.Response) (result Image, err error) { 642 err = autorest.Respond( 643 resp, 644 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 645 autorest.ByUnmarshallingJSON(&result), 646 autorest.ByClosing()) 647 result.Response = autorest.Response{Response: resp} 648 return 649} 650