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