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// VirtualMachineScaleSetExtensionsClient is the compute Client
29type VirtualMachineScaleSetExtensionsClient struct {
30	BaseClient
31}
32
33// NewVirtualMachineScaleSetExtensionsClient creates an instance of the VirtualMachineScaleSetExtensionsClient client.
34func NewVirtualMachineScaleSetExtensionsClient(subscriptionID string) VirtualMachineScaleSetExtensionsClient {
35	return NewVirtualMachineScaleSetExtensionsClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewVirtualMachineScaleSetExtensionsClientWithBaseURI creates an instance of the
39// VirtualMachineScaleSetExtensionsClient client.
40func NewVirtualMachineScaleSetExtensionsClientWithBaseURI(baseURI string, subscriptionID string) VirtualMachineScaleSetExtensionsClient {
41	return VirtualMachineScaleSetExtensionsClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// CreateOrUpdate the operation to create or update an extension.
45// Parameters:
46// resourceGroupName - the name of the resource group.
47// VMScaleSetName - the name of the VM scale set where the extension should be create or updated.
48// vmssExtensionName - the name of the VM scale set extension.
49// extensionParameters - parameters supplied to the Create VM scale set Extension operation.
50func (client VirtualMachineScaleSetExtensionsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, VMScaleSetName string, vmssExtensionName string, extensionParameters VirtualMachineScaleSetExtension) (result VirtualMachineScaleSetExtensionsCreateOrUpdateFuture, err error) {
51	if tracing.IsEnabled() {
52		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineScaleSetExtensionsClient.CreateOrUpdate")
53		defer func() {
54			sc := -1
55			if result.Response() != nil {
56				sc = result.Response().StatusCode
57			}
58			tracing.EndSpan(ctx, sc, err)
59		}()
60	}
61	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, VMScaleSetName, vmssExtensionName, extensionParameters)
62	if err != nil {
63		err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetExtensionsClient", "CreateOrUpdate", nil, "Failure preparing request")
64		return
65	}
66
67	result, err = client.CreateOrUpdateSender(req)
68	if err != nil {
69		err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetExtensionsClient", "CreateOrUpdate", result.Response(), "Failure sending request")
70		return
71	}
72
73	return
74}
75
76// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
77func (client VirtualMachineScaleSetExtensionsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, VMScaleSetName string, vmssExtensionName string, extensionParameters VirtualMachineScaleSetExtension) (*http.Request, error) {
78	pathParameters := map[string]interface{}{
79		"resourceGroupName": autorest.Encode("path", resourceGroupName),
80		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
81		"vmScaleSetName":    autorest.Encode("path", VMScaleSetName),
82		"vmssExtensionName": autorest.Encode("path", vmssExtensionName),
83	}
84
85	const APIVersion = "2018-10-01"
86	queryParameters := map[string]interface{}{
87		"api-version": APIVersion,
88	}
89
90	preparer := autorest.CreatePreparer(
91		autorest.AsContentType("application/json; charset=utf-8"),
92		autorest.AsPut(),
93		autorest.WithBaseURL(client.BaseURI),
94		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/extensions/{vmssExtensionName}", pathParameters),
95		autorest.WithJSON(extensionParameters),
96		autorest.WithQueryParameters(queryParameters))
97	return preparer.Prepare((&http.Request{}).WithContext(ctx))
98}
99
100// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
101// http.Response Body if it receives an error.
102func (client VirtualMachineScaleSetExtensionsClient) CreateOrUpdateSender(req *http.Request) (future VirtualMachineScaleSetExtensionsCreateOrUpdateFuture, err error) {
103	var resp *http.Response
104	resp, err = autorest.SendWithSender(client, req,
105		azure.DoRetryWithRegistration(client.Client))
106	if err != nil {
107		return
108	}
109	future.Future, err = azure.NewFutureFromResponse(resp)
110	return
111}
112
113// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
114// closes the http.Response Body.
115func (client VirtualMachineScaleSetExtensionsClient) CreateOrUpdateResponder(resp *http.Response) (result VirtualMachineScaleSetExtension, err error) {
116	err = autorest.Respond(
117		resp,
118		client.ByInspecting(),
119		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
120		autorest.ByUnmarshallingJSON(&result),
121		autorest.ByClosing())
122	result.Response = autorest.Response{Response: resp}
123	return
124}
125
126// Delete the operation to delete the extension.
127// Parameters:
128// resourceGroupName - the name of the resource group.
129// VMScaleSetName - the name of the VM scale set where the extension should be deleted.
130// vmssExtensionName - the name of the VM scale set extension.
131func (client VirtualMachineScaleSetExtensionsClient) Delete(ctx context.Context, resourceGroupName string, VMScaleSetName string, vmssExtensionName string) (result VirtualMachineScaleSetExtensionsDeleteFuture, err error) {
132	if tracing.IsEnabled() {
133		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineScaleSetExtensionsClient.Delete")
134		defer func() {
135			sc := -1
136			if result.Response() != nil {
137				sc = result.Response().StatusCode
138			}
139			tracing.EndSpan(ctx, sc, err)
140		}()
141	}
142	req, err := client.DeletePreparer(ctx, resourceGroupName, VMScaleSetName, vmssExtensionName)
143	if err != nil {
144		err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetExtensionsClient", "Delete", nil, "Failure preparing request")
145		return
146	}
147
148	result, err = client.DeleteSender(req)
149	if err != nil {
150		err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetExtensionsClient", "Delete", result.Response(), "Failure sending request")
151		return
152	}
153
154	return
155}
156
157// DeletePreparer prepares the Delete request.
158func (client VirtualMachineScaleSetExtensionsClient) DeletePreparer(ctx context.Context, resourceGroupName string, VMScaleSetName string, vmssExtensionName string) (*http.Request, error) {
159	pathParameters := map[string]interface{}{
160		"resourceGroupName": autorest.Encode("path", resourceGroupName),
161		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
162		"vmScaleSetName":    autorest.Encode("path", VMScaleSetName),
163		"vmssExtensionName": autorest.Encode("path", vmssExtensionName),
164	}
165
166	const APIVersion = "2018-10-01"
167	queryParameters := map[string]interface{}{
168		"api-version": APIVersion,
169	}
170
171	preparer := autorest.CreatePreparer(
172		autorest.AsDelete(),
173		autorest.WithBaseURL(client.BaseURI),
174		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/extensions/{vmssExtensionName}", pathParameters),
175		autorest.WithQueryParameters(queryParameters))
176	return preparer.Prepare((&http.Request{}).WithContext(ctx))
177}
178
179// DeleteSender sends the Delete request. The method will close the
180// http.Response Body if it receives an error.
181func (client VirtualMachineScaleSetExtensionsClient) DeleteSender(req *http.Request) (future VirtualMachineScaleSetExtensionsDeleteFuture, err error) {
182	var resp *http.Response
183	resp, err = autorest.SendWithSender(client, req,
184		azure.DoRetryWithRegistration(client.Client))
185	if err != nil {
186		return
187	}
188	future.Future, err = azure.NewFutureFromResponse(resp)
189	return
190}
191
192// DeleteResponder handles the response to the Delete request. The method always
193// closes the http.Response Body.
194func (client VirtualMachineScaleSetExtensionsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
195	err = autorest.Respond(
196		resp,
197		client.ByInspecting(),
198		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
199		autorest.ByClosing())
200	result.Response = resp
201	return
202}
203
204// Get the operation to get the extension.
205// Parameters:
206// resourceGroupName - the name of the resource group.
207// VMScaleSetName - the name of the VM scale set containing the extension.
208// vmssExtensionName - the name of the VM scale set extension.
209// expand - the expand expression to apply on the operation.
210func (client VirtualMachineScaleSetExtensionsClient) Get(ctx context.Context, resourceGroupName string, VMScaleSetName string, vmssExtensionName string, expand string) (result VirtualMachineScaleSetExtension, err error) {
211	if tracing.IsEnabled() {
212		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineScaleSetExtensionsClient.Get")
213		defer func() {
214			sc := -1
215			if result.Response.Response != nil {
216				sc = result.Response.Response.StatusCode
217			}
218			tracing.EndSpan(ctx, sc, err)
219		}()
220	}
221	req, err := client.GetPreparer(ctx, resourceGroupName, VMScaleSetName, vmssExtensionName, expand)
222	if err != nil {
223		err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetExtensionsClient", "Get", nil, "Failure preparing request")
224		return
225	}
226
227	resp, err := client.GetSender(req)
228	if err != nil {
229		result.Response = autorest.Response{Response: resp}
230		err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetExtensionsClient", "Get", resp, "Failure sending request")
231		return
232	}
233
234	result, err = client.GetResponder(resp)
235	if err != nil {
236		err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetExtensionsClient", "Get", resp, "Failure responding to request")
237	}
238
239	return
240}
241
242// GetPreparer prepares the Get request.
243func (client VirtualMachineScaleSetExtensionsClient) GetPreparer(ctx context.Context, resourceGroupName string, VMScaleSetName string, vmssExtensionName string, expand string) (*http.Request, error) {
244	pathParameters := map[string]interface{}{
245		"resourceGroupName": autorest.Encode("path", resourceGroupName),
246		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
247		"vmScaleSetName":    autorest.Encode("path", VMScaleSetName),
248		"vmssExtensionName": autorest.Encode("path", vmssExtensionName),
249	}
250
251	const APIVersion = "2018-10-01"
252	queryParameters := map[string]interface{}{
253		"api-version": APIVersion,
254	}
255	if len(expand) > 0 {
256		queryParameters["$expand"] = autorest.Encode("query", expand)
257	}
258
259	preparer := autorest.CreatePreparer(
260		autorest.AsGet(),
261		autorest.WithBaseURL(client.BaseURI),
262		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/extensions/{vmssExtensionName}", pathParameters),
263		autorest.WithQueryParameters(queryParameters))
264	return preparer.Prepare((&http.Request{}).WithContext(ctx))
265}
266
267// GetSender sends the Get request. The method will close the
268// http.Response Body if it receives an error.
269func (client VirtualMachineScaleSetExtensionsClient) GetSender(req *http.Request) (*http.Response, error) {
270	return autorest.SendWithSender(client, req,
271		azure.DoRetryWithRegistration(client.Client))
272}
273
274// GetResponder handles the response to the Get request. The method always
275// closes the http.Response Body.
276func (client VirtualMachineScaleSetExtensionsClient) GetResponder(resp *http.Response) (result VirtualMachineScaleSetExtension, err error) {
277	err = autorest.Respond(
278		resp,
279		client.ByInspecting(),
280		azure.WithErrorUnlessStatusCode(http.StatusOK),
281		autorest.ByUnmarshallingJSON(&result),
282		autorest.ByClosing())
283	result.Response = autorest.Response{Response: resp}
284	return
285}
286
287// List gets a list of all extensions in a VM scale set.
288// Parameters:
289// resourceGroupName - the name of the resource group.
290// VMScaleSetName - the name of the VM scale set containing the extension.
291func (client VirtualMachineScaleSetExtensionsClient) List(ctx context.Context, resourceGroupName string, VMScaleSetName string) (result VirtualMachineScaleSetExtensionListResultPage, err error) {
292	if tracing.IsEnabled() {
293		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineScaleSetExtensionsClient.List")
294		defer func() {
295			sc := -1
296			if result.vmsselr.Response.Response != nil {
297				sc = result.vmsselr.Response.Response.StatusCode
298			}
299			tracing.EndSpan(ctx, sc, err)
300		}()
301	}
302	result.fn = client.listNextResults
303	req, err := client.ListPreparer(ctx, resourceGroupName, VMScaleSetName)
304	if err != nil {
305		err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetExtensionsClient", "List", nil, "Failure preparing request")
306		return
307	}
308
309	resp, err := client.ListSender(req)
310	if err != nil {
311		result.vmsselr.Response = autorest.Response{Response: resp}
312		err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetExtensionsClient", "List", resp, "Failure sending request")
313		return
314	}
315
316	result.vmsselr, err = client.ListResponder(resp)
317	if err != nil {
318		err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetExtensionsClient", "List", resp, "Failure responding to request")
319	}
320
321	return
322}
323
324// ListPreparer prepares the List request.
325func (client VirtualMachineScaleSetExtensionsClient) ListPreparer(ctx context.Context, resourceGroupName string, VMScaleSetName string) (*http.Request, error) {
326	pathParameters := map[string]interface{}{
327		"resourceGroupName": autorest.Encode("path", resourceGroupName),
328		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
329		"vmScaleSetName":    autorest.Encode("path", VMScaleSetName),
330	}
331
332	const APIVersion = "2018-10-01"
333	queryParameters := map[string]interface{}{
334		"api-version": APIVersion,
335	}
336
337	preparer := autorest.CreatePreparer(
338		autorest.AsGet(),
339		autorest.WithBaseURL(client.BaseURI),
340		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/extensions", pathParameters),
341		autorest.WithQueryParameters(queryParameters))
342	return preparer.Prepare((&http.Request{}).WithContext(ctx))
343}
344
345// ListSender sends the List request. The method will close the
346// http.Response Body if it receives an error.
347func (client VirtualMachineScaleSetExtensionsClient) ListSender(req *http.Request) (*http.Response, error) {
348	return autorest.SendWithSender(client, req,
349		azure.DoRetryWithRegistration(client.Client))
350}
351
352// ListResponder handles the response to the List request. The method always
353// closes the http.Response Body.
354func (client VirtualMachineScaleSetExtensionsClient) ListResponder(resp *http.Response) (result VirtualMachineScaleSetExtensionListResult, err error) {
355	err = autorest.Respond(
356		resp,
357		client.ByInspecting(),
358		azure.WithErrorUnlessStatusCode(http.StatusOK),
359		autorest.ByUnmarshallingJSON(&result),
360		autorest.ByClosing())
361	result.Response = autorest.Response{Response: resp}
362	return
363}
364
365// listNextResults retrieves the next set of results, if any.
366func (client VirtualMachineScaleSetExtensionsClient) listNextResults(ctx context.Context, lastResults VirtualMachineScaleSetExtensionListResult) (result VirtualMachineScaleSetExtensionListResult, err error) {
367	req, err := lastResults.virtualMachineScaleSetExtensionListResultPreparer(ctx)
368	if err != nil {
369		return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetExtensionsClient", "listNextResults", nil, "Failure preparing next results request")
370	}
371	if req == nil {
372		return
373	}
374	resp, err := client.ListSender(req)
375	if err != nil {
376		result.Response = autorest.Response{Response: resp}
377		return result, autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetExtensionsClient", "listNextResults", resp, "Failure sending next results request")
378	}
379	result, err = client.ListResponder(resp)
380	if err != nil {
381		err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetExtensionsClient", "listNextResults", resp, "Failure responding to next results request")
382	}
383	return
384}
385
386// ListComplete enumerates all values, automatically crossing page boundaries as required.
387func (client VirtualMachineScaleSetExtensionsClient) ListComplete(ctx context.Context, resourceGroupName string, VMScaleSetName string) (result VirtualMachineScaleSetExtensionListResultIterator, err error) {
388	if tracing.IsEnabled() {
389		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineScaleSetExtensionsClient.List")
390		defer func() {
391			sc := -1
392			if result.Response().Response.Response != nil {
393				sc = result.page.Response().Response.Response.StatusCode
394			}
395			tracing.EndSpan(ctx, sc, err)
396		}()
397	}
398	result.page, err = client.List(ctx, resourceGroupName, VMScaleSetName)
399	return
400}
401