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// VirtualMachineImagesClient is the compute Client 29type VirtualMachineImagesClient struct { 30 BaseClient 31} 32 33// NewVirtualMachineImagesClient creates an instance of the VirtualMachineImagesClient client. 34func NewVirtualMachineImagesClient(subscriptionID string) VirtualMachineImagesClient { 35 return NewVirtualMachineImagesClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewVirtualMachineImagesClientWithBaseURI creates an instance of the VirtualMachineImagesClient client. 39func NewVirtualMachineImagesClientWithBaseURI(baseURI string, subscriptionID string) VirtualMachineImagesClient { 40 return VirtualMachineImagesClient{NewWithBaseURI(baseURI, subscriptionID)} 41} 42 43// Get gets a virtual machine image. 44// Parameters: 45// location - the name of a supported Azure region. 46// publisherName - a valid image publisher. 47// offer - a valid image publisher offer. 48// skus - a valid image SKU. 49// version - a valid image SKU version. 50func (client VirtualMachineImagesClient) Get(ctx context.Context, location string, publisherName string, offer string, skus string, version string) (result VirtualMachineImage, err error) { 51 if tracing.IsEnabled() { 52 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineImagesClient.Get") 53 defer func() { 54 sc := -1 55 if result.Response.Response != nil { 56 sc = result.Response.Response.StatusCode 57 } 58 tracing.EndSpan(ctx, sc, err) 59 }() 60 } 61 req, err := client.GetPreparer(ctx, location, publisherName, offer, skus, version) 62 if err != nil { 63 err = autorest.NewErrorWithError(err, "compute.VirtualMachineImagesClient", "Get", nil, "Failure preparing request") 64 return 65 } 66 67 resp, err := client.GetSender(req) 68 if err != nil { 69 result.Response = autorest.Response{Response: resp} 70 err = autorest.NewErrorWithError(err, "compute.VirtualMachineImagesClient", "Get", resp, "Failure sending request") 71 return 72 } 73 74 result, err = client.GetResponder(resp) 75 if err != nil { 76 err = autorest.NewErrorWithError(err, "compute.VirtualMachineImagesClient", "Get", resp, "Failure responding to request") 77 } 78 79 return 80} 81 82// GetPreparer prepares the Get request. 83func (client VirtualMachineImagesClient) GetPreparer(ctx context.Context, location string, publisherName string, offer string, skus string, version string) (*http.Request, error) { 84 pathParameters := map[string]interface{}{ 85 "location": autorest.Encode("path", location), 86 "offer": autorest.Encode("path", offer), 87 "publisherName": autorest.Encode("path", publisherName), 88 "skus": autorest.Encode("path", skus), 89 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 90 "version": autorest.Encode("path", version), 91 } 92 93 const APIVersion = "2016-04-30-preview" 94 queryParameters := map[string]interface{}{ 95 "api-version": APIVersion, 96 } 97 98 preparer := autorest.CreatePreparer( 99 autorest.AsGet(), 100 autorest.WithBaseURL(client.BaseURI), 101 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmimage/offers/{offer}/skus/{skus}/versions/{version}", pathParameters), 102 autorest.WithQueryParameters(queryParameters)) 103 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 104} 105 106// GetSender sends the Get request. The method will close the 107// http.Response Body if it receives an error. 108func (client VirtualMachineImagesClient) GetSender(req *http.Request) (*http.Response, error) { 109 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 110 return autorest.SendWithSender(client, req, sd...) 111} 112 113// GetResponder handles the response to the Get request. The method always 114// closes the http.Response Body. 115func (client VirtualMachineImagesClient) GetResponder(resp *http.Response) (result VirtualMachineImage, err error) { 116 err = autorest.Respond( 117 resp, 118 client.ByInspecting(), 119 azure.WithErrorUnlessStatusCode(http.StatusOK), 120 autorest.ByUnmarshallingJSON(&result), 121 autorest.ByClosing()) 122 result.Response = autorest.Response{Response: resp} 123 return 124} 125 126// List gets a list of all virtual machine image versions for the specified location, publisher, offer, and SKU. 127// Parameters: 128// location - the name of a supported Azure region. 129// publisherName - a valid image publisher. 130// offer - a valid image publisher offer. 131// skus - a valid image SKU. 132// filter - the filter to apply on the operation. 133func (client VirtualMachineImagesClient) List(ctx context.Context, location string, publisherName string, offer string, skus string, filter string, top *int32, orderby string) (result ListVirtualMachineImageResource, err error) { 134 if tracing.IsEnabled() { 135 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineImagesClient.List") 136 defer func() { 137 sc := -1 138 if result.Response.Response != nil { 139 sc = result.Response.Response.StatusCode 140 } 141 tracing.EndSpan(ctx, sc, err) 142 }() 143 } 144 req, err := client.ListPreparer(ctx, location, publisherName, offer, skus, filter, top, orderby) 145 if err != nil { 146 err = autorest.NewErrorWithError(err, "compute.VirtualMachineImagesClient", "List", nil, "Failure preparing request") 147 return 148 } 149 150 resp, err := client.ListSender(req) 151 if err != nil { 152 result.Response = autorest.Response{Response: resp} 153 err = autorest.NewErrorWithError(err, "compute.VirtualMachineImagesClient", "List", resp, "Failure sending request") 154 return 155 } 156 157 result, err = client.ListResponder(resp) 158 if err != nil { 159 err = autorest.NewErrorWithError(err, "compute.VirtualMachineImagesClient", "List", resp, "Failure responding to request") 160 } 161 162 return 163} 164 165// ListPreparer prepares the List request. 166func (client VirtualMachineImagesClient) ListPreparer(ctx context.Context, location string, publisherName string, offer string, skus string, filter string, top *int32, orderby string) (*http.Request, error) { 167 pathParameters := map[string]interface{}{ 168 "location": autorest.Encode("path", location), 169 "offer": autorest.Encode("path", offer), 170 "publisherName": autorest.Encode("path", publisherName), 171 "skus": autorest.Encode("path", skus), 172 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 173 } 174 175 const APIVersion = "2016-04-30-preview" 176 queryParameters := map[string]interface{}{ 177 "api-version": APIVersion, 178 } 179 if len(filter) > 0 { 180 queryParameters["$filter"] = autorest.Encode("query", filter) 181 } 182 if top != nil { 183 queryParameters["$top"] = autorest.Encode("query", *top) 184 } 185 if len(orderby) > 0 { 186 queryParameters["$orderby"] = autorest.Encode("query", orderby) 187 } 188 189 preparer := autorest.CreatePreparer( 190 autorest.AsGet(), 191 autorest.WithBaseURL(client.BaseURI), 192 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmimage/offers/{offer}/skus/{skus}/versions", pathParameters), 193 autorest.WithQueryParameters(queryParameters)) 194 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 195} 196 197// ListSender sends the List request. The method will close the 198// http.Response Body if it receives an error. 199func (client VirtualMachineImagesClient) ListSender(req *http.Request) (*http.Response, error) { 200 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 201 return autorest.SendWithSender(client, req, sd...) 202} 203 204// ListResponder handles the response to the List request. The method always 205// closes the http.Response Body. 206func (client VirtualMachineImagesClient) ListResponder(resp *http.Response) (result ListVirtualMachineImageResource, err error) { 207 err = autorest.Respond( 208 resp, 209 client.ByInspecting(), 210 azure.WithErrorUnlessStatusCode(http.StatusOK), 211 autorest.ByUnmarshallingJSON(&result.Value), 212 autorest.ByClosing()) 213 result.Response = autorest.Response{Response: resp} 214 return 215} 216 217// ListOffers gets a list of virtual machine image offers for the specified location and publisher. 218// Parameters: 219// location - the name of a supported Azure region. 220// publisherName - a valid image publisher. 221func (client VirtualMachineImagesClient) ListOffers(ctx context.Context, location string, publisherName string) (result ListVirtualMachineImageResource, err error) { 222 if tracing.IsEnabled() { 223 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineImagesClient.ListOffers") 224 defer func() { 225 sc := -1 226 if result.Response.Response != nil { 227 sc = result.Response.Response.StatusCode 228 } 229 tracing.EndSpan(ctx, sc, err) 230 }() 231 } 232 req, err := client.ListOffersPreparer(ctx, location, publisherName) 233 if err != nil { 234 err = autorest.NewErrorWithError(err, "compute.VirtualMachineImagesClient", "ListOffers", nil, "Failure preparing request") 235 return 236 } 237 238 resp, err := client.ListOffersSender(req) 239 if err != nil { 240 result.Response = autorest.Response{Response: resp} 241 err = autorest.NewErrorWithError(err, "compute.VirtualMachineImagesClient", "ListOffers", resp, "Failure sending request") 242 return 243 } 244 245 result, err = client.ListOffersResponder(resp) 246 if err != nil { 247 err = autorest.NewErrorWithError(err, "compute.VirtualMachineImagesClient", "ListOffers", resp, "Failure responding to request") 248 } 249 250 return 251} 252 253// ListOffersPreparer prepares the ListOffers request. 254func (client VirtualMachineImagesClient) ListOffersPreparer(ctx context.Context, location string, publisherName string) (*http.Request, error) { 255 pathParameters := map[string]interface{}{ 256 "location": autorest.Encode("path", location), 257 "publisherName": autorest.Encode("path", publisherName), 258 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 259 } 260 261 const APIVersion = "2016-04-30-preview" 262 queryParameters := map[string]interface{}{ 263 "api-version": APIVersion, 264 } 265 266 preparer := autorest.CreatePreparer( 267 autorest.AsGet(), 268 autorest.WithBaseURL(client.BaseURI), 269 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmimage/offers", pathParameters), 270 autorest.WithQueryParameters(queryParameters)) 271 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 272} 273 274// ListOffersSender sends the ListOffers request. The method will close the 275// http.Response Body if it receives an error. 276func (client VirtualMachineImagesClient) ListOffersSender(req *http.Request) (*http.Response, error) { 277 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 278 return autorest.SendWithSender(client, req, sd...) 279} 280 281// ListOffersResponder handles the response to the ListOffers request. The method always 282// closes the http.Response Body. 283func (client VirtualMachineImagesClient) ListOffersResponder(resp *http.Response) (result ListVirtualMachineImageResource, err error) { 284 err = autorest.Respond( 285 resp, 286 client.ByInspecting(), 287 azure.WithErrorUnlessStatusCode(http.StatusOK), 288 autorest.ByUnmarshallingJSON(&result.Value), 289 autorest.ByClosing()) 290 result.Response = autorest.Response{Response: resp} 291 return 292} 293 294// ListPublishers gets a list of virtual machine image publishers for the specified Azure location. 295// Parameters: 296// location - the name of a supported Azure region. 297func (client VirtualMachineImagesClient) ListPublishers(ctx context.Context, location string) (result ListVirtualMachineImageResource, err error) { 298 if tracing.IsEnabled() { 299 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineImagesClient.ListPublishers") 300 defer func() { 301 sc := -1 302 if result.Response.Response != nil { 303 sc = result.Response.Response.StatusCode 304 } 305 tracing.EndSpan(ctx, sc, err) 306 }() 307 } 308 req, err := client.ListPublishersPreparer(ctx, location) 309 if err != nil { 310 err = autorest.NewErrorWithError(err, "compute.VirtualMachineImagesClient", "ListPublishers", nil, "Failure preparing request") 311 return 312 } 313 314 resp, err := client.ListPublishersSender(req) 315 if err != nil { 316 result.Response = autorest.Response{Response: resp} 317 err = autorest.NewErrorWithError(err, "compute.VirtualMachineImagesClient", "ListPublishers", resp, "Failure sending request") 318 return 319 } 320 321 result, err = client.ListPublishersResponder(resp) 322 if err != nil { 323 err = autorest.NewErrorWithError(err, "compute.VirtualMachineImagesClient", "ListPublishers", resp, "Failure responding to request") 324 } 325 326 return 327} 328 329// ListPublishersPreparer prepares the ListPublishers request. 330func (client VirtualMachineImagesClient) ListPublishersPreparer(ctx context.Context, location string) (*http.Request, error) { 331 pathParameters := map[string]interface{}{ 332 "location": autorest.Encode("path", location), 333 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 334 } 335 336 const APIVersion = "2016-04-30-preview" 337 queryParameters := map[string]interface{}{ 338 "api-version": APIVersion, 339 } 340 341 preparer := autorest.CreatePreparer( 342 autorest.AsGet(), 343 autorest.WithBaseURL(client.BaseURI), 344 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers", pathParameters), 345 autorest.WithQueryParameters(queryParameters)) 346 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 347} 348 349// ListPublishersSender sends the ListPublishers request. The method will close the 350// http.Response Body if it receives an error. 351func (client VirtualMachineImagesClient) ListPublishersSender(req *http.Request) (*http.Response, error) { 352 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 353 return autorest.SendWithSender(client, req, sd...) 354} 355 356// ListPublishersResponder handles the response to the ListPublishers request. The method always 357// closes the http.Response Body. 358func (client VirtualMachineImagesClient) ListPublishersResponder(resp *http.Response) (result ListVirtualMachineImageResource, err error) { 359 err = autorest.Respond( 360 resp, 361 client.ByInspecting(), 362 azure.WithErrorUnlessStatusCode(http.StatusOK), 363 autorest.ByUnmarshallingJSON(&result.Value), 364 autorest.ByClosing()) 365 result.Response = autorest.Response{Response: resp} 366 return 367} 368 369// ListSkus gets a list of virtual machine image SKUs for the specified location, publisher, and offer. 370// Parameters: 371// location - the name of a supported Azure region. 372// publisherName - a valid image publisher. 373// offer - a valid image publisher offer. 374func (client VirtualMachineImagesClient) ListSkus(ctx context.Context, location string, publisherName string, offer string) (result ListVirtualMachineImageResource, err error) { 375 if tracing.IsEnabled() { 376 ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineImagesClient.ListSkus") 377 defer func() { 378 sc := -1 379 if result.Response.Response != nil { 380 sc = result.Response.Response.StatusCode 381 } 382 tracing.EndSpan(ctx, sc, err) 383 }() 384 } 385 req, err := client.ListSkusPreparer(ctx, location, publisherName, offer) 386 if err != nil { 387 err = autorest.NewErrorWithError(err, "compute.VirtualMachineImagesClient", "ListSkus", nil, "Failure preparing request") 388 return 389 } 390 391 resp, err := client.ListSkusSender(req) 392 if err != nil { 393 result.Response = autorest.Response{Response: resp} 394 err = autorest.NewErrorWithError(err, "compute.VirtualMachineImagesClient", "ListSkus", resp, "Failure sending request") 395 return 396 } 397 398 result, err = client.ListSkusResponder(resp) 399 if err != nil { 400 err = autorest.NewErrorWithError(err, "compute.VirtualMachineImagesClient", "ListSkus", resp, "Failure responding to request") 401 } 402 403 return 404} 405 406// ListSkusPreparer prepares the ListSkus request. 407func (client VirtualMachineImagesClient) ListSkusPreparer(ctx context.Context, location string, publisherName string, offer string) (*http.Request, error) { 408 pathParameters := map[string]interface{}{ 409 "location": autorest.Encode("path", location), 410 "offer": autorest.Encode("path", offer), 411 "publisherName": autorest.Encode("path", publisherName), 412 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 413 } 414 415 const APIVersion = "2016-04-30-preview" 416 queryParameters := map[string]interface{}{ 417 "api-version": APIVersion, 418 } 419 420 preparer := autorest.CreatePreparer( 421 autorest.AsGet(), 422 autorest.WithBaseURL(client.BaseURI), 423 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmimage/offers/{offer}/skus", pathParameters), 424 autorest.WithQueryParameters(queryParameters)) 425 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 426} 427 428// ListSkusSender sends the ListSkus request. The method will close the 429// http.Response Body if it receives an error. 430func (client VirtualMachineImagesClient) ListSkusSender(req *http.Request) (*http.Response, error) { 431 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 432 return autorest.SendWithSender(client, req, sd...) 433} 434 435// ListSkusResponder handles the response to the ListSkus request. The method always 436// closes the http.Response Body. 437func (client VirtualMachineImagesClient) ListSkusResponder(resp *http.Response) (result ListVirtualMachineImageResource, err error) { 438 err = autorest.Respond( 439 resp, 440 client.ByInspecting(), 441 azure.WithErrorUnlessStatusCode(http.StatusOK), 442 autorest.ByUnmarshallingJSON(&result.Value), 443 autorest.ByClosing()) 444 result.Response = autorest.Response{Response: resp} 445 return 446} 447