1package compute 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "github.com/Azure/go-autorest/autorest/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// GalleryImageVersionsClient is the compute Client 30type GalleryImageVersionsClient struct { 31 BaseClient 32} 33 34// NewGalleryImageVersionsClient creates an instance of the GalleryImageVersionsClient client. 35func NewGalleryImageVersionsClient(subscriptionID string) GalleryImageVersionsClient { 36 return NewGalleryImageVersionsClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewGalleryImageVersionsClientWithBaseURI creates an instance of the GalleryImageVersionsClient client. 40func NewGalleryImageVersionsClientWithBaseURI(baseURI string, subscriptionID string) GalleryImageVersionsClient { 41 return GalleryImageVersionsClient{NewWithBaseURI(baseURI, subscriptionID)} 42} 43 44// CreateOrUpdate create or update a gallery Image Version. 45// Parameters: 46// resourceGroupName - the name of the resource group. 47// galleryName - the name of the Shared Image Gallery in which the Image Definition resides. 48// galleryImageName - the name of the gallery Image Definition in which the Image Version is to be created. 49// galleryImageVersionName - the name of the gallery Image Version to be created. Needs to follow semantic 50// version name pattern: The allowed characters are digit and period. Digits must be within the range of a 51// 32-bit integer. Format: <MajorVersion>.<MinorVersion>.<Patch> 52// galleryImageVersion - parameters supplied to the create or update gallery Image Version operation. 53func (client GalleryImageVersionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, galleryImageVersionName string, galleryImageVersion GalleryImageVersion) (result GalleryImageVersionsCreateOrUpdateFuture, err error) { 54 if tracing.IsEnabled() { 55 ctx = tracing.StartSpan(ctx, fqdn+"/GalleryImageVersionsClient.CreateOrUpdate") 56 defer func() { 57 sc := -1 58 if result.Response() != nil { 59 sc = result.Response().StatusCode 60 } 61 tracing.EndSpan(ctx, sc, err) 62 }() 63 } 64 if err := validation.Validate([]validation.Validation{ 65 {TargetValue: galleryImageVersion, 66 Constraints: []validation.Constraint{{Target: "galleryImageVersion.GalleryImageVersionProperties", Name: validation.Null, Rule: false, 67 Chain: []validation.Constraint{{Target: "galleryImageVersion.GalleryImageVersionProperties.PublishingProfile", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { 68 return result, validation.NewError("compute.GalleryImageVersionsClient", "CreateOrUpdate", err.Error()) 69 } 70 71 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, galleryName, galleryImageName, galleryImageVersionName, galleryImageVersion) 72 if err != nil { 73 err = autorest.NewErrorWithError(err, "compute.GalleryImageVersionsClient", "CreateOrUpdate", nil, "Failure preparing request") 74 return 75 } 76 77 result, err = client.CreateOrUpdateSender(req) 78 if err != nil { 79 err = autorest.NewErrorWithError(err, "compute.GalleryImageVersionsClient", "CreateOrUpdate", result.Response(), "Failure sending request") 80 return 81 } 82 83 return 84} 85 86// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 87func (client GalleryImageVersionsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, galleryImageVersionName string, galleryImageVersion GalleryImageVersion) (*http.Request, error) { 88 pathParameters := map[string]interface{}{ 89 "galleryImageName": autorest.Encode("path", galleryImageName), 90 "galleryImageVersionName": autorest.Encode("path", galleryImageVersionName), 91 "galleryName": autorest.Encode("path", galleryName), 92 "resourceGroupName": autorest.Encode("path", resourceGroupName), 93 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 94 } 95 96 const APIVersion = "2018-06-01" 97 queryParameters := map[string]interface{}{ 98 "api-version": APIVersion, 99 } 100 101 preparer := autorest.CreatePreparer( 102 autorest.AsContentType("application/json; charset=utf-8"), 103 autorest.AsPut(), 104 autorest.WithBaseURL(client.BaseURI), 105 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/images/{galleryImageName}/versions/{galleryImageVersionName}", pathParameters), 106 autorest.WithJSON(galleryImageVersion), 107 autorest.WithQueryParameters(queryParameters)) 108 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 109} 110 111// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 112// http.Response Body if it receives an error. 113func (client GalleryImageVersionsClient) CreateOrUpdateSender(req *http.Request) (future GalleryImageVersionsCreateOrUpdateFuture, err error) { 114 var resp *http.Response 115 resp, err = autorest.SendWithSender(client, req, 116 azure.DoRetryWithRegistration(client.Client)) 117 if err != nil { 118 return 119 } 120 future.Future, err = azure.NewFutureFromResponse(resp) 121 return 122} 123 124// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 125// closes the http.Response Body. 126func (client GalleryImageVersionsClient) CreateOrUpdateResponder(resp *http.Response) (result GalleryImageVersion, err error) { 127 err = autorest.Respond( 128 resp, 129 client.ByInspecting(), 130 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted), 131 autorest.ByUnmarshallingJSON(&result), 132 autorest.ByClosing()) 133 result.Response = autorest.Response{Response: resp} 134 return 135} 136 137// Delete delete a gallery Image Version. 138// Parameters: 139// resourceGroupName - the name of the resource group. 140// galleryName - the name of the Shared Image Gallery in which the Image Definition resides. 141// galleryImageName - the name of the gallery Image Definition in which the Image Version resides. 142// galleryImageVersionName - the name of the gallery Image Version to be deleted. 143func (client GalleryImageVersionsClient) Delete(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, galleryImageVersionName string) (result GalleryImageVersionsDeleteFuture, err error) { 144 if tracing.IsEnabled() { 145 ctx = tracing.StartSpan(ctx, fqdn+"/GalleryImageVersionsClient.Delete") 146 defer func() { 147 sc := -1 148 if result.Response() != nil { 149 sc = result.Response().StatusCode 150 } 151 tracing.EndSpan(ctx, sc, err) 152 }() 153 } 154 req, err := client.DeletePreparer(ctx, resourceGroupName, galleryName, galleryImageName, galleryImageVersionName) 155 if err != nil { 156 err = autorest.NewErrorWithError(err, "compute.GalleryImageVersionsClient", "Delete", nil, "Failure preparing request") 157 return 158 } 159 160 result, err = client.DeleteSender(req) 161 if err != nil { 162 err = autorest.NewErrorWithError(err, "compute.GalleryImageVersionsClient", "Delete", result.Response(), "Failure sending request") 163 return 164 } 165 166 return 167} 168 169// DeletePreparer prepares the Delete request. 170func (client GalleryImageVersionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, galleryImageVersionName string) (*http.Request, error) { 171 pathParameters := map[string]interface{}{ 172 "galleryImageName": autorest.Encode("path", galleryImageName), 173 "galleryImageVersionName": autorest.Encode("path", galleryImageVersionName), 174 "galleryName": autorest.Encode("path", galleryName), 175 "resourceGroupName": autorest.Encode("path", resourceGroupName), 176 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 177 } 178 179 const APIVersion = "2018-06-01" 180 queryParameters := map[string]interface{}{ 181 "api-version": APIVersion, 182 } 183 184 preparer := autorest.CreatePreparer( 185 autorest.AsDelete(), 186 autorest.WithBaseURL(client.BaseURI), 187 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/images/{galleryImageName}/versions/{galleryImageVersionName}", pathParameters), 188 autorest.WithQueryParameters(queryParameters)) 189 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 190} 191 192// DeleteSender sends the Delete request. The method will close the 193// http.Response Body if it receives an error. 194func (client GalleryImageVersionsClient) DeleteSender(req *http.Request) (future GalleryImageVersionsDeleteFuture, err error) { 195 var resp *http.Response 196 resp, err = autorest.SendWithSender(client, req, 197 azure.DoRetryWithRegistration(client.Client)) 198 if err != nil { 199 return 200 } 201 future.Future, err = azure.NewFutureFromResponse(resp) 202 return 203} 204 205// DeleteResponder handles the response to the Delete request. The method always 206// closes the http.Response Body. 207func (client GalleryImageVersionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 208 err = autorest.Respond( 209 resp, 210 client.ByInspecting(), 211 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 212 autorest.ByClosing()) 213 result.Response = resp 214 return 215} 216 217// Get retrieves information about a gallery Image Version. 218// Parameters: 219// resourceGroupName - the name of the resource group. 220// galleryName - the name of the Shared Image Gallery in which the Image Definition resides. 221// galleryImageName - the name of the gallery Image Definition in which the Image Version resides. 222// galleryImageVersionName - the name of the gallery Image Version to be retrieved. 223// expand - the expand expression to apply on the operation. 224func (client GalleryImageVersionsClient) Get(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, galleryImageVersionName string, expand ReplicationStatusTypes) (result GalleryImageVersion, err error) { 225 if tracing.IsEnabled() { 226 ctx = tracing.StartSpan(ctx, fqdn+"/GalleryImageVersionsClient.Get") 227 defer func() { 228 sc := -1 229 if result.Response.Response != nil { 230 sc = result.Response.Response.StatusCode 231 } 232 tracing.EndSpan(ctx, sc, err) 233 }() 234 } 235 req, err := client.GetPreparer(ctx, resourceGroupName, galleryName, galleryImageName, galleryImageVersionName, expand) 236 if err != nil { 237 err = autorest.NewErrorWithError(err, "compute.GalleryImageVersionsClient", "Get", nil, "Failure preparing request") 238 return 239 } 240 241 resp, err := client.GetSender(req) 242 if err != nil { 243 result.Response = autorest.Response{Response: resp} 244 err = autorest.NewErrorWithError(err, "compute.GalleryImageVersionsClient", "Get", resp, "Failure sending request") 245 return 246 } 247 248 result, err = client.GetResponder(resp) 249 if err != nil { 250 err = autorest.NewErrorWithError(err, "compute.GalleryImageVersionsClient", "Get", resp, "Failure responding to request") 251 } 252 253 return 254} 255 256// GetPreparer prepares the Get request. 257func (client GalleryImageVersionsClient) GetPreparer(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string, galleryImageVersionName string, expand ReplicationStatusTypes) (*http.Request, error) { 258 pathParameters := map[string]interface{}{ 259 "galleryImageName": autorest.Encode("path", galleryImageName), 260 "galleryImageVersionName": autorest.Encode("path", galleryImageVersionName), 261 "galleryName": autorest.Encode("path", galleryName), 262 "resourceGroupName": autorest.Encode("path", resourceGroupName), 263 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 264 } 265 266 const APIVersion = "2018-06-01" 267 queryParameters := map[string]interface{}{ 268 "api-version": APIVersion, 269 } 270 if len(string(expand)) > 0 { 271 queryParameters["$expand"] = autorest.Encode("query", expand) 272 } 273 274 preparer := autorest.CreatePreparer( 275 autorest.AsGet(), 276 autorest.WithBaseURL(client.BaseURI), 277 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/images/{galleryImageName}/versions/{galleryImageVersionName}", pathParameters), 278 autorest.WithQueryParameters(queryParameters)) 279 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 280} 281 282// GetSender sends the Get request. The method will close the 283// http.Response Body if it receives an error. 284func (client GalleryImageVersionsClient) GetSender(req *http.Request) (*http.Response, error) { 285 return autorest.SendWithSender(client, req, 286 azure.DoRetryWithRegistration(client.Client)) 287} 288 289// GetResponder handles the response to the Get request. The method always 290// closes the http.Response Body. 291func (client GalleryImageVersionsClient) GetResponder(resp *http.Response) (result GalleryImageVersion, err error) { 292 err = autorest.Respond( 293 resp, 294 client.ByInspecting(), 295 azure.WithErrorUnlessStatusCode(http.StatusOK), 296 autorest.ByUnmarshallingJSON(&result), 297 autorest.ByClosing()) 298 result.Response = autorest.Response{Response: resp} 299 return 300} 301 302// ListByGalleryImage list gallery Image Versions in a gallery Image Definition. 303// Parameters: 304// resourceGroupName - the name of the resource group. 305// galleryName - the name of the Shared Image Gallery in which the Image Definition resides. 306// galleryImageName - the name of the Shared Image Gallery Image Definition from which the Image Versions are 307// to be listed. 308func (client GalleryImageVersionsClient) ListByGalleryImage(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string) (result GalleryImageVersionListPage, err error) { 309 if tracing.IsEnabled() { 310 ctx = tracing.StartSpan(ctx, fqdn+"/GalleryImageVersionsClient.ListByGalleryImage") 311 defer func() { 312 sc := -1 313 if result.givl.Response.Response != nil { 314 sc = result.givl.Response.Response.StatusCode 315 } 316 tracing.EndSpan(ctx, sc, err) 317 }() 318 } 319 result.fn = client.listByGalleryImageNextResults 320 req, err := client.ListByGalleryImagePreparer(ctx, resourceGroupName, galleryName, galleryImageName) 321 if err != nil { 322 err = autorest.NewErrorWithError(err, "compute.GalleryImageVersionsClient", "ListByGalleryImage", nil, "Failure preparing request") 323 return 324 } 325 326 resp, err := client.ListByGalleryImageSender(req) 327 if err != nil { 328 result.givl.Response = autorest.Response{Response: resp} 329 err = autorest.NewErrorWithError(err, "compute.GalleryImageVersionsClient", "ListByGalleryImage", resp, "Failure sending request") 330 return 331 } 332 333 result.givl, err = client.ListByGalleryImageResponder(resp) 334 if err != nil { 335 err = autorest.NewErrorWithError(err, "compute.GalleryImageVersionsClient", "ListByGalleryImage", resp, "Failure responding to request") 336 } 337 338 return 339} 340 341// ListByGalleryImagePreparer prepares the ListByGalleryImage request. 342func (client GalleryImageVersionsClient) ListByGalleryImagePreparer(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string) (*http.Request, error) { 343 pathParameters := map[string]interface{}{ 344 "galleryImageName": autorest.Encode("path", galleryImageName), 345 "galleryName": autorest.Encode("path", galleryName), 346 "resourceGroupName": autorest.Encode("path", resourceGroupName), 347 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 348 } 349 350 const APIVersion = "2018-06-01" 351 queryParameters := map[string]interface{}{ 352 "api-version": APIVersion, 353 } 354 355 preparer := autorest.CreatePreparer( 356 autorest.AsGet(), 357 autorest.WithBaseURL(client.BaseURI), 358 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/images/{galleryImageName}/versions", pathParameters), 359 autorest.WithQueryParameters(queryParameters)) 360 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 361} 362 363// ListByGalleryImageSender sends the ListByGalleryImage request. The method will close the 364// http.Response Body if it receives an error. 365func (client GalleryImageVersionsClient) ListByGalleryImageSender(req *http.Request) (*http.Response, error) { 366 return autorest.SendWithSender(client, req, 367 azure.DoRetryWithRegistration(client.Client)) 368} 369 370// ListByGalleryImageResponder handles the response to the ListByGalleryImage request. The method always 371// closes the http.Response Body. 372func (client GalleryImageVersionsClient) ListByGalleryImageResponder(resp *http.Response) (result GalleryImageVersionList, err error) { 373 err = autorest.Respond( 374 resp, 375 client.ByInspecting(), 376 azure.WithErrorUnlessStatusCode(http.StatusOK), 377 autorest.ByUnmarshallingJSON(&result), 378 autorest.ByClosing()) 379 result.Response = autorest.Response{Response: resp} 380 return 381} 382 383// listByGalleryImageNextResults retrieves the next set of results, if any. 384func (client GalleryImageVersionsClient) listByGalleryImageNextResults(ctx context.Context, lastResults GalleryImageVersionList) (result GalleryImageVersionList, err error) { 385 req, err := lastResults.galleryImageVersionListPreparer(ctx) 386 if err != nil { 387 return result, autorest.NewErrorWithError(err, "compute.GalleryImageVersionsClient", "listByGalleryImageNextResults", nil, "Failure preparing next results request") 388 } 389 if req == nil { 390 return 391 } 392 resp, err := client.ListByGalleryImageSender(req) 393 if err != nil { 394 result.Response = autorest.Response{Response: resp} 395 return result, autorest.NewErrorWithError(err, "compute.GalleryImageVersionsClient", "listByGalleryImageNextResults", resp, "Failure sending next results request") 396 } 397 result, err = client.ListByGalleryImageResponder(resp) 398 if err != nil { 399 err = autorest.NewErrorWithError(err, "compute.GalleryImageVersionsClient", "listByGalleryImageNextResults", resp, "Failure responding to next results request") 400 } 401 return 402} 403 404// ListByGalleryImageComplete enumerates all values, automatically crossing page boundaries as required. 405func (client GalleryImageVersionsClient) ListByGalleryImageComplete(ctx context.Context, resourceGroupName string, galleryName string, galleryImageName string) (result GalleryImageVersionListIterator, err error) { 406 if tracing.IsEnabled() { 407 ctx = tracing.StartSpan(ctx, fqdn+"/GalleryImageVersionsClient.ListByGalleryImage") 408 defer func() { 409 sc := -1 410 if result.Response().Response.Response != nil { 411 sc = result.page.Response().Response.Response.StatusCode 412 } 413 tracing.EndSpan(ctx, sc, err) 414 }() 415 } 416 result.page, err = client.ListByGalleryImage(ctx, resourceGroupName, galleryName, galleryImageName) 417 return 418} 419