1package compute
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/tracing"
14	"net/http"
15)
16
17// AvailabilitySetsClient is the compute Client
18type AvailabilitySetsClient struct {
19	BaseClient
20}
21
22// NewAvailabilitySetsClient creates an instance of the AvailabilitySetsClient client.
23func NewAvailabilitySetsClient(subscriptionID string) AvailabilitySetsClient {
24	return NewAvailabilitySetsClientWithBaseURI(DefaultBaseURI, subscriptionID)
25}
26
27// NewAvailabilitySetsClientWithBaseURI creates an instance of the AvailabilitySetsClient client using a custom
28// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
29// stack).
30func NewAvailabilitySetsClientWithBaseURI(baseURI string, subscriptionID string) AvailabilitySetsClient {
31	return AvailabilitySetsClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// CreateOrUpdate create or update an availability set.
35// Parameters:
36// resourceGroupName - the name of the resource group.
37// name - the name of the availability set.
38// parameters - parameters supplied to the Create Availability Set operation.
39func (client AvailabilitySetsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, name string, parameters AvailabilitySet) (result AvailabilitySet, err error) {
40	if tracing.IsEnabled() {
41		ctx = tracing.StartSpan(ctx, fqdn+"/AvailabilitySetsClient.CreateOrUpdate")
42		defer func() {
43			sc := -1
44			if result.Response.Response != nil {
45				sc = result.Response.Response.StatusCode
46			}
47			tracing.EndSpan(ctx, sc, err)
48		}()
49	}
50	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, name, parameters)
51	if err != nil {
52		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "CreateOrUpdate", nil, "Failure preparing request")
53		return
54	}
55
56	resp, err := client.CreateOrUpdateSender(req)
57	if err != nil {
58		result.Response = autorest.Response{Response: resp}
59		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "CreateOrUpdate", resp, "Failure sending request")
60		return
61	}
62
63	result, err = client.CreateOrUpdateResponder(resp)
64	if err != nil {
65		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "CreateOrUpdate", resp, "Failure responding to request")
66		return
67	}
68
69	return
70}
71
72// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
73func (client AvailabilitySetsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, name string, parameters AvailabilitySet) (*http.Request, error) {
74	pathParameters := map[string]interface{}{
75		"availabilitySetName": autorest.Encode("path", name),
76		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
77		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
78	}
79
80	const APIVersion = "2015-06-15"
81	queryParameters := map[string]interface{}{
82		"api-version": APIVersion,
83	}
84
85	preparer := autorest.CreatePreparer(
86		autorest.AsContentType("application/json; charset=utf-8"),
87		autorest.AsPut(),
88		autorest.WithBaseURL(client.BaseURI),
89		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/availabilitySets/{availabilitySetName}", pathParameters),
90		autorest.WithJSON(parameters),
91		autorest.WithQueryParameters(queryParameters))
92	return preparer.Prepare((&http.Request{}).WithContext(ctx))
93}
94
95// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
96// http.Response Body if it receives an error.
97func (client AvailabilitySetsClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
98	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
99}
100
101// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
102// closes the http.Response Body.
103func (client AvailabilitySetsClient) CreateOrUpdateResponder(resp *http.Response) (result AvailabilitySet, err error) {
104	err = autorest.Respond(
105		resp,
106		azure.WithErrorUnlessStatusCode(http.StatusOK),
107		autorest.ByUnmarshallingJSON(&result),
108		autorest.ByClosing())
109	result.Response = autorest.Response{Response: resp}
110	return
111}
112
113// Delete delete an availability set.
114// Parameters:
115// resourceGroupName - the name of the resource group.
116// availabilitySetName - the name of the availability set.
117func (client AvailabilitySetsClient) Delete(ctx context.Context, resourceGroupName string, availabilitySetName string) (result OperationStatusResponse, err error) {
118	if tracing.IsEnabled() {
119		ctx = tracing.StartSpan(ctx, fqdn+"/AvailabilitySetsClient.Delete")
120		defer func() {
121			sc := -1
122			if result.Response.Response != nil {
123				sc = result.Response.Response.StatusCode
124			}
125			tracing.EndSpan(ctx, sc, err)
126		}()
127	}
128	req, err := client.DeletePreparer(ctx, resourceGroupName, availabilitySetName)
129	if err != nil {
130		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "Delete", nil, "Failure preparing request")
131		return
132	}
133
134	resp, err := client.DeleteSender(req)
135	if err != nil {
136		result.Response = autorest.Response{Response: resp}
137		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "Delete", resp, "Failure sending request")
138		return
139	}
140
141	result, err = client.DeleteResponder(resp)
142	if err != nil {
143		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "Delete", resp, "Failure responding to request")
144		return
145	}
146
147	return
148}
149
150// DeletePreparer prepares the Delete request.
151func (client AvailabilitySetsClient) DeletePreparer(ctx context.Context, resourceGroupName string, availabilitySetName string) (*http.Request, error) {
152	pathParameters := map[string]interface{}{
153		"availabilitySetName": autorest.Encode("path", availabilitySetName),
154		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
155		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
156	}
157
158	const APIVersion = "2015-06-15"
159	queryParameters := map[string]interface{}{
160		"api-version": APIVersion,
161	}
162
163	preparer := autorest.CreatePreparer(
164		autorest.AsDelete(),
165		autorest.WithBaseURL(client.BaseURI),
166		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/availabilitySets/{availabilitySetName}", pathParameters),
167		autorest.WithQueryParameters(queryParameters))
168	return preparer.Prepare((&http.Request{}).WithContext(ctx))
169}
170
171// DeleteSender sends the Delete request. The method will close the
172// http.Response Body if it receives an error.
173func (client AvailabilitySetsClient) DeleteSender(req *http.Request) (*http.Response, error) {
174	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
175}
176
177// DeleteResponder handles the response to the Delete request. The method always
178// closes the http.Response Body.
179func (client AvailabilitySetsClient) DeleteResponder(resp *http.Response) (result OperationStatusResponse, err error) {
180	err = autorest.Respond(
181		resp,
182		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
183		autorest.ByUnmarshallingJSON(&result),
184		autorest.ByClosing())
185	result.Response = autorest.Response{Response: resp}
186	return
187}
188
189// Get retrieves information about an availability set.
190// Parameters:
191// resourceGroupName - the name of the resource group.
192// availabilitySetName - the name of the availability set.
193func (client AvailabilitySetsClient) Get(ctx context.Context, resourceGroupName string, availabilitySetName string) (result AvailabilitySet, err error) {
194	if tracing.IsEnabled() {
195		ctx = tracing.StartSpan(ctx, fqdn+"/AvailabilitySetsClient.Get")
196		defer func() {
197			sc := -1
198			if result.Response.Response != nil {
199				sc = result.Response.Response.StatusCode
200			}
201			tracing.EndSpan(ctx, sc, err)
202		}()
203	}
204	req, err := client.GetPreparer(ctx, resourceGroupName, availabilitySetName)
205	if err != nil {
206		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "Get", nil, "Failure preparing request")
207		return
208	}
209
210	resp, err := client.GetSender(req)
211	if err != nil {
212		result.Response = autorest.Response{Response: resp}
213		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "Get", resp, "Failure sending request")
214		return
215	}
216
217	result, err = client.GetResponder(resp)
218	if err != nil {
219		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "Get", resp, "Failure responding to request")
220		return
221	}
222
223	return
224}
225
226// GetPreparer prepares the Get request.
227func (client AvailabilitySetsClient) GetPreparer(ctx context.Context, resourceGroupName string, availabilitySetName string) (*http.Request, error) {
228	pathParameters := map[string]interface{}{
229		"availabilitySetName": autorest.Encode("path", availabilitySetName),
230		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
231		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
232	}
233
234	const APIVersion = "2015-06-15"
235	queryParameters := map[string]interface{}{
236		"api-version": APIVersion,
237	}
238
239	preparer := autorest.CreatePreparer(
240		autorest.AsGet(),
241		autorest.WithBaseURL(client.BaseURI),
242		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/availabilitySets/{availabilitySetName}", pathParameters),
243		autorest.WithQueryParameters(queryParameters))
244	return preparer.Prepare((&http.Request{}).WithContext(ctx))
245}
246
247// GetSender sends the Get request. The method will close the
248// http.Response Body if it receives an error.
249func (client AvailabilitySetsClient) GetSender(req *http.Request) (*http.Response, error) {
250	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
251}
252
253// GetResponder handles the response to the Get request. The method always
254// closes the http.Response Body.
255func (client AvailabilitySetsClient) GetResponder(resp *http.Response) (result AvailabilitySet, err error) {
256	err = autorest.Respond(
257		resp,
258		azure.WithErrorUnlessStatusCode(http.StatusOK),
259		autorest.ByUnmarshallingJSON(&result),
260		autorest.ByClosing())
261	result.Response = autorest.Response{Response: resp}
262	return
263}
264
265// List lists all availability sets in a resource group.
266// Parameters:
267// resourceGroupName - the name of the resource group.
268func (client AvailabilitySetsClient) List(ctx context.Context, resourceGroupName string) (result AvailabilitySetListResultPage, err error) {
269	if tracing.IsEnabled() {
270		ctx = tracing.StartSpan(ctx, fqdn+"/AvailabilitySetsClient.List")
271		defer func() {
272			sc := -1
273			if result.aslr.Response.Response != nil {
274				sc = result.aslr.Response.Response.StatusCode
275			}
276			tracing.EndSpan(ctx, sc, err)
277		}()
278	}
279	result.fn = client.listNextResults
280	req, err := client.ListPreparer(ctx, resourceGroupName)
281	if err != nil {
282		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "List", nil, "Failure preparing request")
283		return
284	}
285
286	resp, err := client.ListSender(req)
287	if err != nil {
288		result.aslr.Response = autorest.Response{Response: resp}
289		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "List", resp, "Failure sending request")
290		return
291	}
292
293	result.aslr, err = client.ListResponder(resp)
294	if err != nil {
295		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "List", resp, "Failure responding to request")
296		return
297	}
298	if result.aslr.hasNextLink() && result.aslr.IsEmpty() {
299		err = result.NextWithContext(ctx)
300		return
301	}
302
303	return
304}
305
306// ListPreparer prepares the List request.
307func (client AvailabilitySetsClient) ListPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
308	pathParameters := map[string]interface{}{
309		"resourceGroupName": autorest.Encode("path", resourceGroupName),
310		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
311	}
312
313	const APIVersion = "2015-06-15"
314	queryParameters := map[string]interface{}{
315		"api-version": APIVersion,
316	}
317
318	preparer := autorest.CreatePreparer(
319		autorest.AsGet(),
320		autorest.WithBaseURL(client.BaseURI),
321		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/availabilitySets", pathParameters),
322		autorest.WithQueryParameters(queryParameters))
323	return preparer.Prepare((&http.Request{}).WithContext(ctx))
324}
325
326// ListSender sends the List request. The method will close the
327// http.Response Body if it receives an error.
328func (client AvailabilitySetsClient) ListSender(req *http.Request) (*http.Response, error) {
329	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
330}
331
332// ListResponder handles the response to the List request. The method always
333// closes the http.Response Body.
334func (client AvailabilitySetsClient) ListResponder(resp *http.Response) (result AvailabilitySetListResult, err error) {
335	err = autorest.Respond(
336		resp,
337		azure.WithErrorUnlessStatusCode(http.StatusOK),
338		autorest.ByUnmarshallingJSON(&result),
339		autorest.ByClosing())
340	result.Response = autorest.Response{Response: resp}
341	return
342}
343
344// listNextResults retrieves the next set of results, if any.
345func (client AvailabilitySetsClient) listNextResults(ctx context.Context, lastResults AvailabilitySetListResult) (result AvailabilitySetListResult, err error) {
346	req, err := lastResults.availabilitySetListResultPreparer(ctx)
347	if err != nil {
348		return result, autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "listNextResults", nil, "Failure preparing next results request")
349	}
350	if req == nil {
351		return
352	}
353	resp, err := client.ListSender(req)
354	if err != nil {
355		result.Response = autorest.Response{Response: resp}
356		return result, autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "listNextResults", resp, "Failure sending next results request")
357	}
358	result, err = client.ListResponder(resp)
359	if err != nil {
360		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "listNextResults", resp, "Failure responding to next results request")
361	}
362	return
363}
364
365// ListComplete enumerates all values, automatically crossing page boundaries as required.
366func (client AvailabilitySetsClient) ListComplete(ctx context.Context, resourceGroupName string) (result AvailabilitySetListResultIterator, err error) {
367	if tracing.IsEnabled() {
368		ctx = tracing.StartSpan(ctx, fqdn+"/AvailabilitySetsClient.List")
369		defer func() {
370			sc := -1
371			if result.Response().Response.Response != nil {
372				sc = result.page.Response().Response.Response.StatusCode
373			}
374			tracing.EndSpan(ctx, sc, err)
375		}()
376	}
377	result.page, err = client.List(ctx, resourceGroupName)
378	return
379}
380
381// ListAvailableSizes lists all available virtual machine sizes that can be used to create a new virtual machine in an
382// existing availability set.
383// Parameters:
384// resourceGroupName - the name of the resource group.
385// availabilitySetName - the name of the availability set.
386func (client AvailabilitySetsClient) ListAvailableSizes(ctx context.Context, resourceGroupName string, availabilitySetName string) (result VirtualMachineSizeListResult, err error) {
387	if tracing.IsEnabled() {
388		ctx = tracing.StartSpan(ctx, fqdn+"/AvailabilitySetsClient.ListAvailableSizes")
389		defer func() {
390			sc := -1
391			if result.Response.Response != nil {
392				sc = result.Response.Response.StatusCode
393			}
394			tracing.EndSpan(ctx, sc, err)
395		}()
396	}
397	req, err := client.ListAvailableSizesPreparer(ctx, resourceGroupName, availabilitySetName)
398	if err != nil {
399		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "ListAvailableSizes", nil, "Failure preparing request")
400		return
401	}
402
403	resp, err := client.ListAvailableSizesSender(req)
404	if err != nil {
405		result.Response = autorest.Response{Response: resp}
406		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "ListAvailableSizes", resp, "Failure sending request")
407		return
408	}
409
410	result, err = client.ListAvailableSizesResponder(resp)
411	if err != nil {
412		err = autorest.NewErrorWithError(err, "compute.AvailabilitySetsClient", "ListAvailableSizes", resp, "Failure responding to request")
413		return
414	}
415
416	return
417}
418
419// ListAvailableSizesPreparer prepares the ListAvailableSizes request.
420func (client AvailabilitySetsClient) ListAvailableSizesPreparer(ctx context.Context, resourceGroupName string, availabilitySetName string) (*http.Request, error) {
421	pathParameters := map[string]interface{}{
422		"availabilitySetName": autorest.Encode("path", availabilitySetName),
423		"resourceGroupName":   autorest.Encode("path", resourceGroupName),
424		"subscriptionId":      autorest.Encode("path", client.SubscriptionID),
425	}
426
427	const APIVersion = "2015-06-15"
428	queryParameters := map[string]interface{}{
429		"api-version": APIVersion,
430	}
431
432	preparer := autorest.CreatePreparer(
433		autorest.AsGet(),
434		autorest.WithBaseURL(client.BaseURI),
435		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/availabilitySets/{availabilitySetName}/vmSizes", pathParameters),
436		autorest.WithQueryParameters(queryParameters))
437	return preparer.Prepare((&http.Request{}).WithContext(ctx))
438}
439
440// ListAvailableSizesSender sends the ListAvailableSizes request. The method will close the
441// http.Response Body if it receives an error.
442func (client AvailabilitySetsClient) ListAvailableSizesSender(req *http.Request) (*http.Response, error) {
443	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
444}
445
446// ListAvailableSizesResponder handles the response to the ListAvailableSizes request. The method always
447// closes the http.Response Body.
448func (client AvailabilitySetsClient) ListAvailableSizesResponder(resp *http.Response) (result VirtualMachineSizeListResult, err error) {
449	err = autorest.Respond(
450		resp,
451		azure.WithErrorUnlessStatusCode(http.StatusOK),
452		autorest.ByUnmarshallingJSON(&result),
453		autorest.ByClosing())
454	result.Response = autorest.Response{Response: resp}
455	return
456}
457