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