1package dtl
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/autorest/validation"
25	"github.com/Azure/go-autorest/tracing"
26	"net/http"
27)
28
29// VirtualMachinesClient is the the DevTest Labs Client.
30type VirtualMachinesClient struct {
31	BaseClient
32}
33
34// NewVirtualMachinesClient creates an instance of the VirtualMachinesClient client.
35func NewVirtualMachinesClient(subscriptionID string) VirtualMachinesClient {
36	return NewVirtualMachinesClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewVirtualMachinesClientWithBaseURI creates an instance of the VirtualMachinesClient client using a custom endpoint.
40// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
41func NewVirtualMachinesClientWithBaseURI(baseURI string, subscriptionID string) VirtualMachinesClient {
42	return VirtualMachinesClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// AddDataDisk attach a new or existing data disk to virtual machine. This operation can take a while to complete.
46// Parameters:
47// resourceGroupName - the name of the resource group.
48// labName - the name of the lab.
49// name - the name of the virtual machine.
50// dataDiskProperties - request body for adding a new or existing data disk to a virtual machine.
51func (client VirtualMachinesClient) AddDataDisk(ctx context.Context, resourceGroupName string, labName string, name string, dataDiskProperties DataDiskProperties) (result VirtualMachinesAddDataDiskFuture, err error) {
52	if tracing.IsEnabled() {
53		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachinesClient.AddDataDisk")
54		defer func() {
55			sc := -1
56			if result.Response() != nil {
57				sc = result.Response().StatusCode
58			}
59			tracing.EndSpan(ctx, sc, err)
60		}()
61	}
62	req, err := client.AddDataDiskPreparer(ctx, resourceGroupName, labName, name, dataDiskProperties)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "AddDataDisk", nil, "Failure preparing request")
65		return
66	}
67
68	result, err = client.AddDataDiskSender(req)
69	if err != nil {
70		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "AddDataDisk", nil, "Failure sending request")
71		return
72	}
73
74	return
75}
76
77// AddDataDiskPreparer prepares the AddDataDisk request.
78func (client VirtualMachinesClient) AddDataDiskPreparer(ctx context.Context, resourceGroupName string, labName string, name string, dataDiskProperties DataDiskProperties) (*http.Request, error) {
79	pathParameters := map[string]interface{}{
80		"labName":           autorest.Encode("path", labName),
81		"name":              autorest.Encode("path", name),
82		"resourceGroupName": autorest.Encode("path", resourceGroupName),
83		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
84	}
85
86	const APIVersion = "2016-05-15"
87	queryParameters := map[string]interface{}{
88		"api-version": APIVersion,
89	}
90
91	preparer := autorest.CreatePreparer(
92		autorest.AsContentType("application/json; charset=utf-8"),
93		autorest.AsPost(),
94		autorest.WithBaseURL(client.BaseURI),
95		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/addDataDisk", pathParameters),
96		autorest.WithJSON(dataDiskProperties),
97		autorest.WithQueryParameters(queryParameters))
98	return preparer.Prepare((&http.Request{}).WithContext(ctx))
99}
100
101// AddDataDiskSender sends the AddDataDisk request. The method will close the
102// http.Response Body if it receives an error.
103func (client VirtualMachinesClient) AddDataDiskSender(req *http.Request) (future VirtualMachinesAddDataDiskFuture, err error) {
104	var resp *http.Response
105	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
106	if err != nil {
107		return
108	}
109	var azf azure.Future
110	azf, err = azure.NewFutureFromResponse(resp)
111	future.FutureAPI = &azf
112	future.Result = func(client VirtualMachinesClient) (ar autorest.Response, err error) {
113		var done bool
114		done, err = future.DoneWithContext(context.Background(), client)
115		if err != nil {
116			err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesAddDataDiskFuture", "Result", future.Response(), "Polling failure")
117			return
118		}
119		if !done {
120			err = azure.NewAsyncOpIncompleteError("dtl.VirtualMachinesAddDataDiskFuture")
121			return
122		}
123		ar.Response = future.Response()
124		return
125	}
126	return
127}
128
129// AddDataDiskResponder handles the response to the AddDataDisk request. The method always
130// closes the http.Response Body.
131func (client VirtualMachinesClient) AddDataDiskResponder(resp *http.Response) (result autorest.Response, err error) {
132	err = autorest.Respond(
133		resp,
134		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
135		autorest.ByClosing())
136	result.Response = resp
137	return
138}
139
140// ApplyArtifacts apply artifacts to virtual machine. This operation can take a while to complete.
141// Parameters:
142// resourceGroupName - the name of the resource group.
143// labName - the name of the lab.
144// name - the name of the virtual machine.
145// applyArtifactsRequest - request body for applying artifacts to a virtual machine.
146func (client VirtualMachinesClient) ApplyArtifacts(ctx context.Context, resourceGroupName string, labName string, name string, applyArtifactsRequest ApplyArtifactsRequest) (result VirtualMachinesApplyArtifactsFuture, err error) {
147	if tracing.IsEnabled() {
148		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachinesClient.ApplyArtifacts")
149		defer func() {
150			sc := -1
151			if result.Response() != nil {
152				sc = result.Response().StatusCode
153			}
154			tracing.EndSpan(ctx, sc, err)
155		}()
156	}
157	req, err := client.ApplyArtifactsPreparer(ctx, resourceGroupName, labName, name, applyArtifactsRequest)
158	if err != nil {
159		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "ApplyArtifacts", nil, "Failure preparing request")
160		return
161	}
162
163	result, err = client.ApplyArtifactsSender(req)
164	if err != nil {
165		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "ApplyArtifacts", nil, "Failure sending request")
166		return
167	}
168
169	return
170}
171
172// ApplyArtifactsPreparer prepares the ApplyArtifacts request.
173func (client VirtualMachinesClient) ApplyArtifactsPreparer(ctx context.Context, resourceGroupName string, labName string, name string, applyArtifactsRequest ApplyArtifactsRequest) (*http.Request, error) {
174	pathParameters := map[string]interface{}{
175		"labName":           autorest.Encode("path", labName),
176		"name":              autorest.Encode("path", name),
177		"resourceGroupName": autorest.Encode("path", resourceGroupName),
178		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
179	}
180
181	const APIVersion = "2016-05-15"
182	queryParameters := map[string]interface{}{
183		"api-version": APIVersion,
184	}
185
186	preparer := autorest.CreatePreparer(
187		autorest.AsContentType("application/json; charset=utf-8"),
188		autorest.AsPost(),
189		autorest.WithBaseURL(client.BaseURI),
190		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/applyArtifacts", pathParameters),
191		autorest.WithJSON(applyArtifactsRequest),
192		autorest.WithQueryParameters(queryParameters))
193	return preparer.Prepare((&http.Request{}).WithContext(ctx))
194}
195
196// ApplyArtifactsSender sends the ApplyArtifacts request. The method will close the
197// http.Response Body if it receives an error.
198func (client VirtualMachinesClient) ApplyArtifactsSender(req *http.Request) (future VirtualMachinesApplyArtifactsFuture, err error) {
199	var resp *http.Response
200	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
201	if err != nil {
202		return
203	}
204	var azf azure.Future
205	azf, err = azure.NewFutureFromResponse(resp)
206	future.FutureAPI = &azf
207	future.Result = func(client VirtualMachinesClient) (ar autorest.Response, err error) {
208		var done bool
209		done, err = future.DoneWithContext(context.Background(), client)
210		if err != nil {
211			err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesApplyArtifactsFuture", "Result", future.Response(), "Polling failure")
212			return
213		}
214		if !done {
215			err = azure.NewAsyncOpIncompleteError("dtl.VirtualMachinesApplyArtifactsFuture")
216			return
217		}
218		ar.Response = future.Response()
219		return
220	}
221	return
222}
223
224// ApplyArtifactsResponder handles the response to the ApplyArtifacts request. The method always
225// closes the http.Response Body.
226func (client VirtualMachinesClient) ApplyArtifactsResponder(resp *http.Response) (result autorest.Response, err error) {
227	err = autorest.Respond(
228		resp,
229		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
230		autorest.ByClosing())
231	result.Response = resp
232	return
233}
234
235// Claim take ownership of an existing virtual machine This operation can take a while to complete.
236// Parameters:
237// resourceGroupName - the name of the resource group.
238// labName - the name of the lab.
239// name - the name of the virtual machine.
240func (client VirtualMachinesClient) Claim(ctx context.Context, resourceGroupName string, labName string, name string) (result VirtualMachinesClaimFuture, err error) {
241	if tracing.IsEnabled() {
242		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachinesClient.Claim")
243		defer func() {
244			sc := -1
245			if result.Response() != nil {
246				sc = result.Response().StatusCode
247			}
248			tracing.EndSpan(ctx, sc, err)
249		}()
250	}
251	req, err := client.ClaimPreparer(ctx, resourceGroupName, labName, name)
252	if err != nil {
253		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "Claim", nil, "Failure preparing request")
254		return
255	}
256
257	result, err = client.ClaimSender(req)
258	if err != nil {
259		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "Claim", nil, "Failure sending request")
260		return
261	}
262
263	return
264}
265
266// ClaimPreparer prepares the Claim request.
267func (client VirtualMachinesClient) ClaimPreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
268	pathParameters := map[string]interface{}{
269		"labName":           autorest.Encode("path", labName),
270		"name":              autorest.Encode("path", name),
271		"resourceGroupName": autorest.Encode("path", resourceGroupName),
272		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
273	}
274
275	const APIVersion = "2016-05-15"
276	queryParameters := map[string]interface{}{
277		"api-version": APIVersion,
278	}
279
280	preparer := autorest.CreatePreparer(
281		autorest.AsPost(),
282		autorest.WithBaseURL(client.BaseURI),
283		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/claim", pathParameters),
284		autorest.WithQueryParameters(queryParameters))
285	return preparer.Prepare((&http.Request{}).WithContext(ctx))
286}
287
288// ClaimSender sends the Claim request. The method will close the
289// http.Response Body if it receives an error.
290func (client VirtualMachinesClient) ClaimSender(req *http.Request) (future VirtualMachinesClaimFuture, err error) {
291	var resp *http.Response
292	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
293	if err != nil {
294		return
295	}
296	var azf azure.Future
297	azf, err = azure.NewFutureFromResponse(resp)
298	future.FutureAPI = &azf
299	future.Result = func(client VirtualMachinesClient) (ar autorest.Response, err error) {
300		var done bool
301		done, err = future.DoneWithContext(context.Background(), client)
302		if err != nil {
303			err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClaimFuture", "Result", future.Response(), "Polling failure")
304			return
305		}
306		if !done {
307			err = azure.NewAsyncOpIncompleteError("dtl.VirtualMachinesClaimFuture")
308			return
309		}
310		ar.Response = future.Response()
311		return
312	}
313	return
314}
315
316// ClaimResponder handles the response to the Claim request. The method always
317// closes the http.Response Body.
318func (client VirtualMachinesClient) ClaimResponder(resp *http.Response) (result autorest.Response, err error) {
319	err = autorest.Respond(
320		resp,
321		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
322		autorest.ByClosing())
323	result.Response = resp
324	return
325}
326
327// CreateOrUpdate create or replace an existing Virtual machine. This operation can take a while to complete.
328// Parameters:
329// resourceGroupName - the name of the resource group.
330// labName - the name of the lab.
331// name - the name of the virtual machine.
332// labVirtualMachine - a virtual machine.
333func (client VirtualMachinesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, labName string, name string, labVirtualMachine LabVirtualMachine) (result VirtualMachinesCreateOrUpdateFuture, err error) {
334	if tracing.IsEnabled() {
335		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachinesClient.CreateOrUpdate")
336		defer func() {
337			sc := -1
338			if result.Response() != nil {
339				sc = result.Response().StatusCode
340			}
341			tracing.EndSpan(ctx, sc, err)
342		}()
343	}
344	if err := validation.Validate([]validation.Validation{
345		{TargetValue: labVirtualMachine,
346			Constraints: []validation.Constraint{{Target: "labVirtualMachine.LabVirtualMachineProperties", Name: validation.Null, Rule: true,
347				Chain: []validation.Constraint{{Target: "labVirtualMachine.LabVirtualMachineProperties.ApplicableSchedule", Name: validation.Null, Rule: false,
348					Chain: []validation.Constraint{{Target: "labVirtualMachine.LabVirtualMachineProperties.ApplicableSchedule.ApplicableScheduleProperties", Name: validation.Null, Rule: true,
349						Chain: []validation.Constraint{{Target: "labVirtualMachine.LabVirtualMachineProperties.ApplicableSchedule.ApplicableScheduleProperties.LabVmsShutdown", Name: validation.Null, Rule: false,
350							Chain: []validation.Constraint{{Target: "labVirtualMachine.LabVirtualMachineProperties.ApplicableSchedule.ApplicableScheduleProperties.LabVmsShutdown.ScheduleProperties", Name: validation.Null, Rule: true, Chain: nil}}},
351							{Target: "labVirtualMachine.LabVirtualMachineProperties.ApplicableSchedule.ApplicableScheduleProperties.LabVmsStartup", Name: validation.Null, Rule: false,
352								Chain: []validation.Constraint{{Target: "labVirtualMachine.LabVirtualMachineProperties.ApplicableSchedule.ApplicableScheduleProperties.LabVmsStartup.ScheduleProperties", Name: validation.Null, Rule: true, Chain: nil}}},
353						}},
354					}},
355				}}}}}); err != nil {
356		return result, validation.NewError("dtl.VirtualMachinesClient", "CreateOrUpdate", err.Error())
357	}
358
359	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, labName, name, labVirtualMachine)
360	if err != nil {
361		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "CreateOrUpdate", nil, "Failure preparing request")
362		return
363	}
364
365	result, err = client.CreateOrUpdateSender(req)
366	if err != nil {
367		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "CreateOrUpdate", nil, "Failure sending request")
368		return
369	}
370
371	return
372}
373
374// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
375func (client VirtualMachinesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, labName string, name string, labVirtualMachine LabVirtualMachine) (*http.Request, error) {
376	pathParameters := map[string]interface{}{
377		"labName":           autorest.Encode("path", labName),
378		"name":              autorest.Encode("path", name),
379		"resourceGroupName": autorest.Encode("path", resourceGroupName),
380		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
381	}
382
383	const APIVersion = "2016-05-15"
384	queryParameters := map[string]interface{}{
385		"api-version": APIVersion,
386	}
387
388	preparer := autorest.CreatePreparer(
389		autorest.AsContentType("application/json; charset=utf-8"),
390		autorest.AsPut(),
391		autorest.WithBaseURL(client.BaseURI),
392		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}", pathParameters),
393		autorest.WithJSON(labVirtualMachine),
394		autorest.WithQueryParameters(queryParameters))
395	return preparer.Prepare((&http.Request{}).WithContext(ctx))
396}
397
398// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
399// http.Response Body if it receives an error.
400func (client VirtualMachinesClient) CreateOrUpdateSender(req *http.Request) (future VirtualMachinesCreateOrUpdateFuture, err error) {
401	var resp *http.Response
402	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
403	if err != nil {
404		return
405	}
406	var azf azure.Future
407	azf, err = azure.NewFutureFromResponse(resp)
408	future.FutureAPI = &azf
409	future.Result = func(client VirtualMachinesClient) (lvm LabVirtualMachine, err error) {
410		var done bool
411		done, err = future.DoneWithContext(context.Background(), client)
412		if err != nil {
413			err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesCreateOrUpdateFuture", "Result", future.Response(), "Polling failure")
414			return
415		}
416		if !done {
417			err = azure.NewAsyncOpIncompleteError("dtl.VirtualMachinesCreateOrUpdateFuture")
418			return
419		}
420		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
421		if lvm.Response.Response, err = future.GetResult(sender); err == nil && lvm.Response.Response.StatusCode != http.StatusNoContent {
422			lvm, err = client.CreateOrUpdateResponder(lvm.Response.Response)
423			if err != nil {
424				err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesCreateOrUpdateFuture", "Result", lvm.Response.Response, "Failure responding to request")
425			}
426		}
427		return
428	}
429	return
430}
431
432// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
433// closes the http.Response Body.
434func (client VirtualMachinesClient) CreateOrUpdateResponder(resp *http.Response) (result LabVirtualMachine, err error) {
435	err = autorest.Respond(
436		resp,
437		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
438		autorest.ByUnmarshallingJSON(&result),
439		autorest.ByClosing())
440	result.Response = autorest.Response{Response: resp}
441	return
442}
443
444// Delete delete virtual machine. This operation can take a while to complete.
445// Parameters:
446// resourceGroupName - the name of the resource group.
447// labName - the name of the lab.
448// name - the name of the virtual machine.
449func (client VirtualMachinesClient) Delete(ctx context.Context, resourceGroupName string, labName string, name string) (result VirtualMachinesDeleteFuture, err error) {
450	if tracing.IsEnabled() {
451		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachinesClient.Delete")
452		defer func() {
453			sc := -1
454			if result.Response() != nil {
455				sc = result.Response().StatusCode
456			}
457			tracing.EndSpan(ctx, sc, err)
458		}()
459	}
460	req, err := client.DeletePreparer(ctx, resourceGroupName, labName, name)
461	if err != nil {
462		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "Delete", nil, "Failure preparing request")
463		return
464	}
465
466	result, err = client.DeleteSender(req)
467	if err != nil {
468		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "Delete", nil, "Failure sending request")
469		return
470	}
471
472	return
473}
474
475// DeletePreparer prepares the Delete request.
476func (client VirtualMachinesClient) DeletePreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
477	pathParameters := map[string]interface{}{
478		"labName":           autorest.Encode("path", labName),
479		"name":              autorest.Encode("path", name),
480		"resourceGroupName": autorest.Encode("path", resourceGroupName),
481		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
482	}
483
484	const APIVersion = "2016-05-15"
485	queryParameters := map[string]interface{}{
486		"api-version": APIVersion,
487	}
488
489	preparer := autorest.CreatePreparer(
490		autorest.AsDelete(),
491		autorest.WithBaseURL(client.BaseURI),
492		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}", pathParameters),
493		autorest.WithQueryParameters(queryParameters))
494	return preparer.Prepare((&http.Request{}).WithContext(ctx))
495}
496
497// DeleteSender sends the Delete request. The method will close the
498// http.Response Body if it receives an error.
499func (client VirtualMachinesClient) DeleteSender(req *http.Request) (future VirtualMachinesDeleteFuture, err error) {
500	var resp *http.Response
501	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
502	if err != nil {
503		return
504	}
505	var azf azure.Future
506	azf, err = azure.NewFutureFromResponse(resp)
507	future.FutureAPI = &azf
508	future.Result = func(client VirtualMachinesClient) (ar autorest.Response, err error) {
509		var done bool
510		done, err = future.DoneWithContext(context.Background(), client)
511		if err != nil {
512			err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesDeleteFuture", "Result", future.Response(), "Polling failure")
513			return
514		}
515		if !done {
516			err = azure.NewAsyncOpIncompleteError("dtl.VirtualMachinesDeleteFuture")
517			return
518		}
519		ar.Response = future.Response()
520		return
521	}
522	return
523}
524
525// DeleteResponder handles the response to the Delete request. The method always
526// closes the http.Response Body.
527func (client VirtualMachinesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
528	err = autorest.Respond(
529		resp,
530		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
531		autorest.ByClosing())
532	result.Response = resp
533	return
534}
535
536// DetachDataDisk detach the specified disk from the virtual machine. This operation can take a while to complete.
537// Parameters:
538// resourceGroupName - the name of the resource group.
539// labName - the name of the lab.
540// name - the name of the virtual machine.
541// detachDataDiskProperties - request body for detaching data disk from a virtual machine.
542func (client VirtualMachinesClient) DetachDataDisk(ctx context.Context, resourceGroupName string, labName string, name string, detachDataDiskProperties DetachDataDiskProperties) (result VirtualMachinesDetachDataDiskFuture, err error) {
543	if tracing.IsEnabled() {
544		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachinesClient.DetachDataDisk")
545		defer func() {
546			sc := -1
547			if result.Response() != nil {
548				sc = result.Response().StatusCode
549			}
550			tracing.EndSpan(ctx, sc, err)
551		}()
552	}
553	req, err := client.DetachDataDiskPreparer(ctx, resourceGroupName, labName, name, detachDataDiskProperties)
554	if err != nil {
555		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "DetachDataDisk", nil, "Failure preparing request")
556		return
557	}
558
559	result, err = client.DetachDataDiskSender(req)
560	if err != nil {
561		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "DetachDataDisk", nil, "Failure sending request")
562		return
563	}
564
565	return
566}
567
568// DetachDataDiskPreparer prepares the DetachDataDisk request.
569func (client VirtualMachinesClient) DetachDataDiskPreparer(ctx context.Context, resourceGroupName string, labName string, name string, detachDataDiskProperties DetachDataDiskProperties) (*http.Request, error) {
570	pathParameters := map[string]interface{}{
571		"labName":           autorest.Encode("path", labName),
572		"name":              autorest.Encode("path", name),
573		"resourceGroupName": autorest.Encode("path", resourceGroupName),
574		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
575	}
576
577	const APIVersion = "2016-05-15"
578	queryParameters := map[string]interface{}{
579		"api-version": APIVersion,
580	}
581
582	preparer := autorest.CreatePreparer(
583		autorest.AsContentType("application/json; charset=utf-8"),
584		autorest.AsPost(),
585		autorest.WithBaseURL(client.BaseURI),
586		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/detachDataDisk", pathParameters),
587		autorest.WithJSON(detachDataDiskProperties),
588		autorest.WithQueryParameters(queryParameters))
589	return preparer.Prepare((&http.Request{}).WithContext(ctx))
590}
591
592// DetachDataDiskSender sends the DetachDataDisk request. The method will close the
593// http.Response Body if it receives an error.
594func (client VirtualMachinesClient) DetachDataDiskSender(req *http.Request) (future VirtualMachinesDetachDataDiskFuture, err error) {
595	var resp *http.Response
596	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
597	if err != nil {
598		return
599	}
600	var azf azure.Future
601	azf, err = azure.NewFutureFromResponse(resp)
602	future.FutureAPI = &azf
603	future.Result = func(client VirtualMachinesClient) (ar autorest.Response, err error) {
604		var done bool
605		done, err = future.DoneWithContext(context.Background(), client)
606		if err != nil {
607			err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesDetachDataDiskFuture", "Result", future.Response(), "Polling failure")
608			return
609		}
610		if !done {
611			err = azure.NewAsyncOpIncompleteError("dtl.VirtualMachinesDetachDataDiskFuture")
612			return
613		}
614		ar.Response = future.Response()
615		return
616	}
617	return
618}
619
620// DetachDataDiskResponder handles the response to the DetachDataDisk request. The method always
621// closes the http.Response Body.
622func (client VirtualMachinesClient) DetachDataDiskResponder(resp *http.Response) (result autorest.Response, err error) {
623	err = autorest.Respond(
624		resp,
625		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
626		autorest.ByClosing())
627	result.Response = resp
628	return
629}
630
631// Get get virtual machine.
632// Parameters:
633// resourceGroupName - the name of the resource group.
634// labName - the name of the lab.
635// name - the name of the virtual machine.
636// expand - specify the $expand query. Example:
637// 'properties($expand=artifacts,computeVm,networkInterface,applicableSchedule)'
638func (client VirtualMachinesClient) Get(ctx context.Context, resourceGroupName string, labName string, name string, expand string) (result LabVirtualMachine, err error) {
639	if tracing.IsEnabled() {
640		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachinesClient.Get")
641		defer func() {
642			sc := -1
643			if result.Response.Response != nil {
644				sc = result.Response.Response.StatusCode
645			}
646			tracing.EndSpan(ctx, sc, err)
647		}()
648	}
649	req, err := client.GetPreparer(ctx, resourceGroupName, labName, name, expand)
650	if err != nil {
651		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "Get", nil, "Failure preparing request")
652		return
653	}
654
655	resp, err := client.GetSender(req)
656	if err != nil {
657		result.Response = autorest.Response{Response: resp}
658		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "Get", resp, "Failure sending request")
659		return
660	}
661
662	result, err = client.GetResponder(resp)
663	if err != nil {
664		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "Get", resp, "Failure responding to request")
665		return
666	}
667
668	return
669}
670
671// GetPreparer prepares the Get request.
672func (client VirtualMachinesClient) GetPreparer(ctx context.Context, resourceGroupName string, labName string, name string, expand string) (*http.Request, error) {
673	pathParameters := map[string]interface{}{
674		"labName":           autorest.Encode("path", labName),
675		"name":              autorest.Encode("path", name),
676		"resourceGroupName": autorest.Encode("path", resourceGroupName),
677		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
678	}
679
680	const APIVersion = "2016-05-15"
681	queryParameters := map[string]interface{}{
682		"api-version": APIVersion,
683	}
684	if len(expand) > 0 {
685		queryParameters["$expand"] = autorest.Encode("query", expand)
686	}
687
688	preparer := autorest.CreatePreparer(
689		autorest.AsGet(),
690		autorest.WithBaseURL(client.BaseURI),
691		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}", pathParameters),
692		autorest.WithQueryParameters(queryParameters))
693	return preparer.Prepare((&http.Request{}).WithContext(ctx))
694}
695
696// GetSender sends the Get request. The method will close the
697// http.Response Body if it receives an error.
698func (client VirtualMachinesClient) GetSender(req *http.Request) (*http.Response, error) {
699	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
700}
701
702// GetResponder handles the response to the Get request. The method always
703// closes the http.Response Body.
704func (client VirtualMachinesClient) GetResponder(resp *http.Response) (result LabVirtualMachine, err error) {
705	err = autorest.Respond(
706		resp,
707		azure.WithErrorUnlessStatusCode(http.StatusOK),
708		autorest.ByUnmarshallingJSON(&result),
709		autorest.ByClosing())
710	result.Response = autorest.Response{Response: resp}
711	return
712}
713
714// List list virtual machines in a given lab.
715// Parameters:
716// resourceGroupName - the name of the resource group.
717// labName - the name of the lab.
718// expand - specify the $expand query. Example:
719// 'properties($expand=artifacts,computeVm,networkInterface,applicableSchedule)'
720// filter - the filter to apply to the operation.
721// top - the maximum number of resources to return from the operation.
722// orderby - the ordering expression for the results, using OData notation.
723func (client VirtualMachinesClient) List(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationLabVirtualMachinePage, err error) {
724	if tracing.IsEnabled() {
725		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachinesClient.List")
726		defer func() {
727			sc := -1
728			if result.rwclvm.Response.Response != nil {
729				sc = result.rwclvm.Response.Response.StatusCode
730			}
731			tracing.EndSpan(ctx, sc, err)
732		}()
733	}
734	result.fn = client.listNextResults
735	req, err := client.ListPreparer(ctx, resourceGroupName, labName, expand, filter, top, orderby)
736	if err != nil {
737		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "List", nil, "Failure preparing request")
738		return
739	}
740
741	resp, err := client.ListSender(req)
742	if err != nil {
743		result.rwclvm.Response = autorest.Response{Response: resp}
744		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "List", resp, "Failure sending request")
745		return
746	}
747
748	result.rwclvm, err = client.ListResponder(resp)
749	if err != nil {
750		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "List", resp, "Failure responding to request")
751		return
752	}
753	if result.rwclvm.hasNextLink() && result.rwclvm.IsEmpty() {
754		err = result.NextWithContext(ctx)
755		return
756	}
757
758	return
759}
760
761// ListPreparer prepares the List request.
762func (client VirtualMachinesClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (*http.Request, error) {
763	pathParameters := map[string]interface{}{
764		"labName":           autorest.Encode("path", labName),
765		"resourceGroupName": autorest.Encode("path", resourceGroupName),
766		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
767	}
768
769	const APIVersion = "2016-05-15"
770	queryParameters := map[string]interface{}{
771		"api-version": APIVersion,
772	}
773	if len(expand) > 0 {
774		queryParameters["$expand"] = autorest.Encode("query", expand)
775	}
776	if len(filter) > 0 {
777		queryParameters["$filter"] = autorest.Encode("query", filter)
778	}
779	if top != nil {
780		queryParameters["$top"] = autorest.Encode("query", *top)
781	}
782	if len(orderby) > 0 {
783		queryParameters["$orderby"] = autorest.Encode("query", orderby)
784	}
785
786	preparer := autorest.CreatePreparer(
787		autorest.AsGet(),
788		autorest.WithBaseURL(client.BaseURI),
789		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines", pathParameters),
790		autorest.WithQueryParameters(queryParameters))
791	return preparer.Prepare((&http.Request{}).WithContext(ctx))
792}
793
794// ListSender sends the List request. The method will close the
795// http.Response Body if it receives an error.
796func (client VirtualMachinesClient) ListSender(req *http.Request) (*http.Response, error) {
797	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
798}
799
800// ListResponder handles the response to the List request. The method always
801// closes the http.Response Body.
802func (client VirtualMachinesClient) ListResponder(resp *http.Response) (result ResponseWithContinuationLabVirtualMachine, err error) {
803	err = autorest.Respond(
804		resp,
805		azure.WithErrorUnlessStatusCode(http.StatusOK),
806		autorest.ByUnmarshallingJSON(&result),
807		autorest.ByClosing())
808	result.Response = autorest.Response{Response: resp}
809	return
810}
811
812// listNextResults retrieves the next set of results, if any.
813func (client VirtualMachinesClient) listNextResults(ctx context.Context, lastResults ResponseWithContinuationLabVirtualMachine) (result ResponseWithContinuationLabVirtualMachine, err error) {
814	req, err := lastResults.responseWithContinuationLabVirtualMachinePreparer(ctx)
815	if err != nil {
816		return result, autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "listNextResults", nil, "Failure preparing next results request")
817	}
818	if req == nil {
819		return
820	}
821	resp, err := client.ListSender(req)
822	if err != nil {
823		result.Response = autorest.Response{Response: resp}
824		return result, autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "listNextResults", resp, "Failure sending next results request")
825	}
826	result, err = client.ListResponder(resp)
827	if err != nil {
828		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "listNextResults", resp, "Failure responding to next results request")
829	}
830	return
831}
832
833// ListComplete enumerates all values, automatically crossing page boundaries as required.
834func (client VirtualMachinesClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationLabVirtualMachineIterator, err error) {
835	if tracing.IsEnabled() {
836		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachinesClient.List")
837		defer func() {
838			sc := -1
839			if result.Response().Response.Response != nil {
840				sc = result.page.Response().Response.Response.StatusCode
841			}
842			tracing.EndSpan(ctx, sc, err)
843		}()
844	}
845	result.page, err = client.List(ctx, resourceGroupName, labName, expand, filter, top, orderby)
846	return
847}
848
849// ListApplicableSchedules lists all applicable schedules
850// Parameters:
851// resourceGroupName - the name of the resource group.
852// labName - the name of the lab.
853// name - the name of the virtual machine.
854func (client VirtualMachinesClient) ListApplicableSchedules(ctx context.Context, resourceGroupName string, labName string, name string) (result ApplicableSchedule, err error) {
855	if tracing.IsEnabled() {
856		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachinesClient.ListApplicableSchedules")
857		defer func() {
858			sc := -1
859			if result.Response.Response != nil {
860				sc = result.Response.Response.StatusCode
861			}
862			tracing.EndSpan(ctx, sc, err)
863		}()
864	}
865	req, err := client.ListApplicableSchedulesPreparer(ctx, resourceGroupName, labName, name)
866	if err != nil {
867		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "ListApplicableSchedules", nil, "Failure preparing request")
868		return
869	}
870
871	resp, err := client.ListApplicableSchedulesSender(req)
872	if err != nil {
873		result.Response = autorest.Response{Response: resp}
874		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "ListApplicableSchedules", resp, "Failure sending request")
875		return
876	}
877
878	result, err = client.ListApplicableSchedulesResponder(resp)
879	if err != nil {
880		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "ListApplicableSchedules", resp, "Failure responding to request")
881		return
882	}
883
884	return
885}
886
887// ListApplicableSchedulesPreparer prepares the ListApplicableSchedules request.
888func (client VirtualMachinesClient) ListApplicableSchedulesPreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
889	pathParameters := map[string]interface{}{
890		"labName":           autorest.Encode("path", labName),
891		"name":              autorest.Encode("path", name),
892		"resourceGroupName": autorest.Encode("path", resourceGroupName),
893		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
894	}
895
896	const APIVersion = "2016-05-15"
897	queryParameters := map[string]interface{}{
898		"api-version": APIVersion,
899	}
900
901	preparer := autorest.CreatePreparer(
902		autorest.AsPost(),
903		autorest.WithBaseURL(client.BaseURI),
904		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/listApplicableSchedules", pathParameters),
905		autorest.WithQueryParameters(queryParameters))
906	return preparer.Prepare((&http.Request{}).WithContext(ctx))
907}
908
909// ListApplicableSchedulesSender sends the ListApplicableSchedules request. The method will close the
910// http.Response Body if it receives an error.
911func (client VirtualMachinesClient) ListApplicableSchedulesSender(req *http.Request) (*http.Response, error) {
912	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
913}
914
915// ListApplicableSchedulesResponder handles the response to the ListApplicableSchedules request. The method always
916// closes the http.Response Body.
917func (client VirtualMachinesClient) ListApplicableSchedulesResponder(resp *http.Response) (result ApplicableSchedule, err error) {
918	err = autorest.Respond(
919		resp,
920		azure.WithErrorUnlessStatusCode(http.StatusOK),
921		autorest.ByUnmarshallingJSON(&result),
922		autorest.ByClosing())
923	result.Response = autorest.Response{Response: resp}
924	return
925}
926
927// Start start a virtual machine. This operation can take a while to complete.
928// Parameters:
929// resourceGroupName - the name of the resource group.
930// labName - the name of the lab.
931// name - the name of the virtual machine.
932func (client VirtualMachinesClient) Start(ctx context.Context, resourceGroupName string, labName string, name string) (result VirtualMachinesStartFuture, err error) {
933	if tracing.IsEnabled() {
934		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachinesClient.Start")
935		defer func() {
936			sc := -1
937			if result.Response() != nil {
938				sc = result.Response().StatusCode
939			}
940			tracing.EndSpan(ctx, sc, err)
941		}()
942	}
943	req, err := client.StartPreparer(ctx, resourceGroupName, labName, name)
944	if err != nil {
945		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "Start", nil, "Failure preparing request")
946		return
947	}
948
949	result, err = client.StartSender(req)
950	if err != nil {
951		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "Start", nil, "Failure sending request")
952		return
953	}
954
955	return
956}
957
958// StartPreparer prepares the Start request.
959func (client VirtualMachinesClient) StartPreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
960	pathParameters := map[string]interface{}{
961		"labName":           autorest.Encode("path", labName),
962		"name":              autorest.Encode("path", name),
963		"resourceGroupName": autorest.Encode("path", resourceGroupName),
964		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
965	}
966
967	const APIVersion = "2016-05-15"
968	queryParameters := map[string]interface{}{
969		"api-version": APIVersion,
970	}
971
972	preparer := autorest.CreatePreparer(
973		autorest.AsPost(),
974		autorest.WithBaseURL(client.BaseURI),
975		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/start", pathParameters),
976		autorest.WithQueryParameters(queryParameters))
977	return preparer.Prepare((&http.Request{}).WithContext(ctx))
978}
979
980// StartSender sends the Start request. The method will close the
981// http.Response Body if it receives an error.
982func (client VirtualMachinesClient) StartSender(req *http.Request) (future VirtualMachinesStartFuture, err error) {
983	var resp *http.Response
984	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
985	if err != nil {
986		return
987	}
988	var azf azure.Future
989	azf, err = azure.NewFutureFromResponse(resp)
990	future.FutureAPI = &azf
991	future.Result = func(client VirtualMachinesClient) (ar autorest.Response, err error) {
992		var done bool
993		done, err = future.DoneWithContext(context.Background(), client)
994		if err != nil {
995			err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesStartFuture", "Result", future.Response(), "Polling failure")
996			return
997		}
998		if !done {
999			err = azure.NewAsyncOpIncompleteError("dtl.VirtualMachinesStartFuture")
1000			return
1001		}
1002		ar.Response = future.Response()
1003		return
1004	}
1005	return
1006}
1007
1008// StartResponder handles the response to the Start request. The method always
1009// closes the http.Response Body.
1010func (client VirtualMachinesClient) StartResponder(resp *http.Response) (result autorest.Response, err error) {
1011	err = autorest.Respond(
1012		resp,
1013		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
1014		autorest.ByClosing())
1015	result.Response = resp
1016	return
1017}
1018
1019// Stop stop a virtual machine This operation can take a while to complete.
1020// Parameters:
1021// resourceGroupName - the name of the resource group.
1022// labName - the name of the lab.
1023// name - the name of the virtual machine.
1024func (client VirtualMachinesClient) Stop(ctx context.Context, resourceGroupName string, labName string, name string) (result VirtualMachinesStopFuture, err error) {
1025	if tracing.IsEnabled() {
1026		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachinesClient.Stop")
1027		defer func() {
1028			sc := -1
1029			if result.Response() != nil {
1030				sc = result.Response().StatusCode
1031			}
1032			tracing.EndSpan(ctx, sc, err)
1033		}()
1034	}
1035	req, err := client.StopPreparer(ctx, resourceGroupName, labName, name)
1036	if err != nil {
1037		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "Stop", nil, "Failure preparing request")
1038		return
1039	}
1040
1041	result, err = client.StopSender(req)
1042	if err != nil {
1043		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "Stop", nil, "Failure sending request")
1044		return
1045	}
1046
1047	return
1048}
1049
1050// StopPreparer prepares the Stop request.
1051func (client VirtualMachinesClient) StopPreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
1052	pathParameters := map[string]interface{}{
1053		"labName":           autorest.Encode("path", labName),
1054		"name":              autorest.Encode("path", name),
1055		"resourceGroupName": autorest.Encode("path", resourceGroupName),
1056		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
1057	}
1058
1059	const APIVersion = "2016-05-15"
1060	queryParameters := map[string]interface{}{
1061		"api-version": APIVersion,
1062	}
1063
1064	preparer := autorest.CreatePreparer(
1065		autorest.AsPost(),
1066		autorest.WithBaseURL(client.BaseURI),
1067		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/stop", pathParameters),
1068		autorest.WithQueryParameters(queryParameters))
1069	return preparer.Prepare((&http.Request{}).WithContext(ctx))
1070}
1071
1072// StopSender sends the Stop request. The method will close the
1073// http.Response Body if it receives an error.
1074func (client VirtualMachinesClient) StopSender(req *http.Request) (future VirtualMachinesStopFuture, err error) {
1075	var resp *http.Response
1076	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
1077	if err != nil {
1078		return
1079	}
1080	var azf azure.Future
1081	azf, err = azure.NewFutureFromResponse(resp)
1082	future.FutureAPI = &azf
1083	future.Result = func(client VirtualMachinesClient) (ar autorest.Response, err error) {
1084		var done bool
1085		done, err = future.DoneWithContext(context.Background(), client)
1086		if err != nil {
1087			err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesStopFuture", "Result", future.Response(), "Polling failure")
1088			return
1089		}
1090		if !done {
1091			err = azure.NewAsyncOpIncompleteError("dtl.VirtualMachinesStopFuture")
1092			return
1093		}
1094		ar.Response = future.Response()
1095		return
1096	}
1097	return
1098}
1099
1100// StopResponder handles the response to the Stop request. The method always
1101// closes the http.Response Body.
1102func (client VirtualMachinesClient) StopResponder(resp *http.Response) (result autorest.Response, err error) {
1103	err = autorest.Respond(
1104		resp,
1105		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
1106		autorest.ByClosing())
1107	result.Response = resp
1108	return
1109}
1110
1111// Update modify properties of virtual machines.
1112// Parameters:
1113// resourceGroupName - the name of the resource group.
1114// labName - the name of the lab.
1115// name - the name of the virtual machine.
1116// labVirtualMachine - a virtual machine.
1117func (client VirtualMachinesClient) Update(ctx context.Context, resourceGroupName string, labName string, name string, labVirtualMachine LabVirtualMachineFragment) (result LabVirtualMachine, err error) {
1118	if tracing.IsEnabled() {
1119		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachinesClient.Update")
1120		defer func() {
1121			sc := -1
1122			if result.Response.Response != nil {
1123				sc = result.Response.Response.StatusCode
1124			}
1125			tracing.EndSpan(ctx, sc, err)
1126		}()
1127	}
1128	req, err := client.UpdatePreparer(ctx, resourceGroupName, labName, name, labVirtualMachine)
1129	if err != nil {
1130		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "Update", nil, "Failure preparing request")
1131		return
1132	}
1133
1134	resp, err := client.UpdateSender(req)
1135	if err != nil {
1136		result.Response = autorest.Response{Response: resp}
1137		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "Update", resp, "Failure sending request")
1138		return
1139	}
1140
1141	result, err = client.UpdateResponder(resp)
1142	if err != nil {
1143		err = autorest.NewErrorWithError(err, "dtl.VirtualMachinesClient", "Update", resp, "Failure responding to request")
1144		return
1145	}
1146
1147	return
1148}
1149
1150// UpdatePreparer prepares the Update request.
1151func (client VirtualMachinesClient) UpdatePreparer(ctx context.Context, resourceGroupName string, labName string, name string, labVirtualMachine LabVirtualMachineFragment) (*http.Request, error) {
1152	pathParameters := map[string]interface{}{
1153		"labName":           autorest.Encode("path", labName),
1154		"name":              autorest.Encode("path", name),
1155		"resourceGroupName": autorest.Encode("path", resourceGroupName),
1156		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
1157	}
1158
1159	const APIVersion = "2016-05-15"
1160	queryParameters := map[string]interface{}{
1161		"api-version": APIVersion,
1162	}
1163
1164	preparer := autorest.CreatePreparer(
1165		autorest.AsContentType("application/json; charset=utf-8"),
1166		autorest.AsPatch(),
1167		autorest.WithBaseURL(client.BaseURI),
1168		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}", pathParameters),
1169		autorest.WithJSON(labVirtualMachine),
1170		autorest.WithQueryParameters(queryParameters))
1171	return preparer.Prepare((&http.Request{}).WithContext(ctx))
1172}
1173
1174// UpdateSender sends the Update request. The method will close the
1175// http.Response Body if it receives an error.
1176func (client VirtualMachinesClient) UpdateSender(req *http.Request) (*http.Response, error) {
1177	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
1178}
1179
1180// UpdateResponder handles the response to the Update request. The method always
1181// closes the http.Response Body.
1182func (client VirtualMachinesClient) UpdateResponder(resp *http.Response) (result LabVirtualMachine, err error) {
1183	err = autorest.Respond(
1184		resp,
1185		azure.WithErrorUnlessStatusCode(http.StatusOK),
1186		autorest.ByUnmarshallingJSON(&result),
1187		autorest.ByClosing())
1188	result.Response = autorest.Response{Response: resp}
1189	return
1190}
1191