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