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// VirtualMachineScaleSetRollingUpgradesClient is the compute Client
29type VirtualMachineScaleSetRollingUpgradesClient struct {
30	BaseClient
31}
32
33// NewVirtualMachineScaleSetRollingUpgradesClient creates an instance of the
34// VirtualMachineScaleSetRollingUpgradesClient client.
35func NewVirtualMachineScaleSetRollingUpgradesClient(subscriptionID string) VirtualMachineScaleSetRollingUpgradesClient {
36	return NewVirtualMachineScaleSetRollingUpgradesClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewVirtualMachineScaleSetRollingUpgradesClientWithBaseURI creates an instance of the
40// VirtualMachineScaleSetRollingUpgradesClient client.
41func NewVirtualMachineScaleSetRollingUpgradesClientWithBaseURI(baseURI string, subscriptionID string) VirtualMachineScaleSetRollingUpgradesClient {
42	return VirtualMachineScaleSetRollingUpgradesClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// Cancel cancels the current virtual machine scale set rolling upgrade.
46// Parameters:
47// resourceGroupName - the name of the resource group.
48// VMScaleSetName - the name of the VM scale set.
49func (client VirtualMachineScaleSetRollingUpgradesClient) Cancel(ctx context.Context, resourceGroupName string, VMScaleSetName string) (result VirtualMachineScaleSetRollingUpgradesCancelFuture, err error) {
50	if tracing.IsEnabled() {
51		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineScaleSetRollingUpgradesClient.Cancel")
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.CancelPreparer(ctx, resourceGroupName, VMScaleSetName)
61	if err != nil {
62		err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetRollingUpgradesClient", "Cancel", nil, "Failure preparing request")
63		return
64	}
65
66	result, err = client.CancelSender(req)
67	if err != nil {
68		err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetRollingUpgradesClient", "Cancel", result.Response(), "Failure sending request")
69		return
70	}
71
72	return
73}
74
75// CancelPreparer prepares the Cancel request.
76func (client VirtualMachineScaleSetRollingUpgradesClient) CancelPreparer(ctx context.Context, resourceGroupName string, VMScaleSetName string) (*http.Request, error) {
77	pathParameters := map[string]interface{}{
78		"resourceGroupName": autorest.Encode("path", resourceGroupName),
79		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
80		"vmScaleSetName":    autorest.Encode("path", VMScaleSetName),
81	}
82
83	const APIVersion = "2018-10-01"
84	queryParameters := map[string]interface{}{
85		"api-version": APIVersion,
86	}
87
88	preparer := autorest.CreatePreparer(
89		autorest.AsPost(),
90		autorest.WithBaseURL(client.BaseURI),
91		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/rollingUpgrades/cancel", pathParameters),
92		autorest.WithQueryParameters(queryParameters))
93	return preparer.Prepare((&http.Request{}).WithContext(ctx))
94}
95
96// CancelSender sends the Cancel request. The method will close the
97// http.Response Body if it receives an error.
98func (client VirtualMachineScaleSetRollingUpgradesClient) CancelSender(req *http.Request) (future VirtualMachineScaleSetRollingUpgradesCancelFuture, err error) {
99	var resp *http.Response
100	resp, err = autorest.SendWithSender(client, req,
101		azure.DoRetryWithRegistration(client.Client))
102	if err != nil {
103		return
104	}
105	future.Future, err = azure.NewFutureFromResponse(resp)
106	return
107}
108
109// CancelResponder handles the response to the Cancel request. The method always
110// closes the http.Response Body.
111func (client VirtualMachineScaleSetRollingUpgradesClient) CancelResponder(resp *http.Response) (result autorest.Response, err error) {
112	err = autorest.Respond(
113		resp,
114		client.ByInspecting(),
115		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
116		autorest.ByClosing())
117	result.Response = resp
118	return
119}
120
121// GetLatest gets the status of the latest virtual machine scale set rolling upgrade.
122// Parameters:
123// resourceGroupName - the name of the resource group.
124// VMScaleSetName - the name of the VM scale set.
125func (client VirtualMachineScaleSetRollingUpgradesClient) GetLatest(ctx context.Context, resourceGroupName string, VMScaleSetName string) (result RollingUpgradeStatusInfo, err error) {
126	if tracing.IsEnabled() {
127		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineScaleSetRollingUpgradesClient.GetLatest")
128		defer func() {
129			sc := -1
130			if result.Response.Response != nil {
131				sc = result.Response.Response.StatusCode
132			}
133			tracing.EndSpan(ctx, sc, err)
134		}()
135	}
136	req, err := client.GetLatestPreparer(ctx, resourceGroupName, VMScaleSetName)
137	if err != nil {
138		err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetRollingUpgradesClient", "GetLatest", nil, "Failure preparing request")
139		return
140	}
141
142	resp, err := client.GetLatestSender(req)
143	if err != nil {
144		result.Response = autorest.Response{Response: resp}
145		err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetRollingUpgradesClient", "GetLatest", resp, "Failure sending request")
146		return
147	}
148
149	result, err = client.GetLatestResponder(resp)
150	if err != nil {
151		err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetRollingUpgradesClient", "GetLatest", resp, "Failure responding to request")
152	}
153
154	return
155}
156
157// GetLatestPreparer prepares the GetLatest request.
158func (client VirtualMachineScaleSetRollingUpgradesClient) GetLatestPreparer(ctx context.Context, resourceGroupName string, VMScaleSetName 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	}
164
165	const APIVersion = "2018-10-01"
166	queryParameters := map[string]interface{}{
167		"api-version": APIVersion,
168	}
169
170	preparer := autorest.CreatePreparer(
171		autorest.AsGet(),
172		autorest.WithBaseURL(client.BaseURI),
173		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/rollingUpgrades/latest", pathParameters),
174		autorest.WithQueryParameters(queryParameters))
175	return preparer.Prepare((&http.Request{}).WithContext(ctx))
176}
177
178// GetLatestSender sends the GetLatest request. The method will close the
179// http.Response Body if it receives an error.
180func (client VirtualMachineScaleSetRollingUpgradesClient) GetLatestSender(req *http.Request) (*http.Response, error) {
181	return autorest.SendWithSender(client, req,
182		azure.DoRetryWithRegistration(client.Client))
183}
184
185// GetLatestResponder handles the response to the GetLatest request. The method always
186// closes the http.Response Body.
187func (client VirtualMachineScaleSetRollingUpgradesClient) GetLatestResponder(resp *http.Response) (result RollingUpgradeStatusInfo, err error) {
188	err = autorest.Respond(
189		resp,
190		client.ByInspecting(),
191		azure.WithErrorUnlessStatusCode(http.StatusOK),
192		autorest.ByUnmarshallingJSON(&result),
193		autorest.ByClosing())
194	result.Response = autorest.Response{Response: resp}
195	return
196}
197
198// StartExtensionUpgrade starts a rolling upgrade to move all extensions for all virtual machine scale set instances to
199// the latest available extension version. Instances which are already running the latest extension versions are not
200// affected.
201// Parameters:
202// resourceGroupName - the name of the resource group.
203// VMScaleSetName - the name of the VM scale set.
204func (client VirtualMachineScaleSetRollingUpgradesClient) StartExtensionUpgrade(ctx context.Context, resourceGroupName string, VMScaleSetName string) (result VirtualMachineScaleSetRollingUpgradesStartExtensionUpgradeFuture, err error) {
205	if tracing.IsEnabled() {
206		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineScaleSetRollingUpgradesClient.StartExtensionUpgrade")
207		defer func() {
208			sc := -1
209			if result.Response() != nil {
210				sc = result.Response().StatusCode
211			}
212			tracing.EndSpan(ctx, sc, err)
213		}()
214	}
215	req, err := client.StartExtensionUpgradePreparer(ctx, resourceGroupName, VMScaleSetName)
216	if err != nil {
217		err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetRollingUpgradesClient", "StartExtensionUpgrade", nil, "Failure preparing request")
218		return
219	}
220
221	result, err = client.StartExtensionUpgradeSender(req)
222	if err != nil {
223		err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetRollingUpgradesClient", "StartExtensionUpgrade", result.Response(), "Failure sending request")
224		return
225	}
226
227	return
228}
229
230// StartExtensionUpgradePreparer prepares the StartExtensionUpgrade request.
231func (client VirtualMachineScaleSetRollingUpgradesClient) StartExtensionUpgradePreparer(ctx context.Context, resourceGroupName string, VMScaleSetName string) (*http.Request, error) {
232	pathParameters := map[string]interface{}{
233		"resourceGroupName": autorest.Encode("path", resourceGroupName),
234		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
235		"vmScaleSetName":    autorest.Encode("path", VMScaleSetName),
236	}
237
238	const APIVersion = "2018-10-01"
239	queryParameters := map[string]interface{}{
240		"api-version": APIVersion,
241	}
242
243	preparer := autorest.CreatePreparer(
244		autorest.AsPost(),
245		autorest.WithBaseURL(client.BaseURI),
246		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/extensionRollingUpgrade", pathParameters),
247		autorest.WithQueryParameters(queryParameters))
248	return preparer.Prepare((&http.Request{}).WithContext(ctx))
249}
250
251// StartExtensionUpgradeSender sends the StartExtensionUpgrade request. The method will close the
252// http.Response Body if it receives an error.
253func (client VirtualMachineScaleSetRollingUpgradesClient) StartExtensionUpgradeSender(req *http.Request) (future VirtualMachineScaleSetRollingUpgradesStartExtensionUpgradeFuture, err error) {
254	var resp *http.Response
255	resp, err = autorest.SendWithSender(client, req,
256		azure.DoRetryWithRegistration(client.Client))
257	if err != nil {
258		return
259	}
260	future.Future, err = azure.NewFutureFromResponse(resp)
261	return
262}
263
264// StartExtensionUpgradeResponder handles the response to the StartExtensionUpgrade request. The method always
265// closes the http.Response Body.
266func (client VirtualMachineScaleSetRollingUpgradesClient) StartExtensionUpgradeResponder(resp *http.Response) (result autorest.Response, err error) {
267	err = autorest.Respond(
268		resp,
269		client.ByInspecting(),
270		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
271		autorest.ByClosing())
272	result.Response = resp
273	return
274}
275
276// StartOSUpgrade starts a rolling upgrade to move all virtual machine scale set instances to the latest available
277// Platform Image OS version. Instances which are already running the latest available OS version are not affected.
278// Parameters:
279// resourceGroupName - the name of the resource group.
280// VMScaleSetName - the name of the VM scale set.
281func (client VirtualMachineScaleSetRollingUpgradesClient) StartOSUpgrade(ctx context.Context, resourceGroupName string, VMScaleSetName string) (result VirtualMachineScaleSetRollingUpgradesStartOSUpgradeFuture, err error) {
282	if tracing.IsEnabled() {
283		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineScaleSetRollingUpgradesClient.StartOSUpgrade")
284		defer func() {
285			sc := -1
286			if result.Response() != nil {
287				sc = result.Response().StatusCode
288			}
289			tracing.EndSpan(ctx, sc, err)
290		}()
291	}
292	req, err := client.StartOSUpgradePreparer(ctx, resourceGroupName, VMScaleSetName)
293	if err != nil {
294		err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetRollingUpgradesClient", "StartOSUpgrade", nil, "Failure preparing request")
295		return
296	}
297
298	result, err = client.StartOSUpgradeSender(req)
299	if err != nil {
300		err = autorest.NewErrorWithError(err, "compute.VirtualMachineScaleSetRollingUpgradesClient", "StartOSUpgrade", result.Response(), "Failure sending request")
301		return
302	}
303
304	return
305}
306
307// StartOSUpgradePreparer prepares the StartOSUpgrade request.
308func (client VirtualMachineScaleSetRollingUpgradesClient) StartOSUpgradePreparer(ctx context.Context, resourceGroupName string, VMScaleSetName string) (*http.Request, error) {
309	pathParameters := map[string]interface{}{
310		"resourceGroupName": autorest.Encode("path", resourceGroupName),
311		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
312		"vmScaleSetName":    autorest.Encode("path", VMScaleSetName),
313	}
314
315	const APIVersion = "2018-10-01"
316	queryParameters := map[string]interface{}{
317		"api-version": APIVersion,
318	}
319
320	preparer := autorest.CreatePreparer(
321		autorest.AsPost(),
322		autorest.WithBaseURL(client.BaseURI),
323		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}/osRollingUpgrade", pathParameters),
324		autorest.WithQueryParameters(queryParameters))
325	return preparer.Prepare((&http.Request{}).WithContext(ctx))
326}
327
328// StartOSUpgradeSender sends the StartOSUpgrade request. The method will close the
329// http.Response Body if it receives an error.
330func (client VirtualMachineScaleSetRollingUpgradesClient) StartOSUpgradeSender(req *http.Request) (future VirtualMachineScaleSetRollingUpgradesStartOSUpgradeFuture, err error) {
331	var resp *http.Response
332	resp, err = autorest.SendWithSender(client, req,
333		azure.DoRetryWithRegistration(client.Client))
334	if err != nil {
335		return
336	}
337	future.Future, err = azure.NewFutureFromResponse(resp)
338	return
339}
340
341// StartOSUpgradeResponder handles the response to the StartOSUpgrade request. The method always
342// closes the http.Response Body.
343func (client VirtualMachineScaleSetRollingUpgradesClient) StartOSUpgradeResponder(resp *http.Response) (result autorest.Response, err error) {
344	err = autorest.Respond(
345		resp,
346		client.ByInspecting(),
347		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
348		autorest.ByClosing())
349	result.Response = resp
350	return
351}
352