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