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