1package dtl
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/tracing"
14	"net/http"
15)
16
17// VirtualMachineClient is the azure DevTest Labs REST API version 2015-05-21-preview.
18type VirtualMachineClient struct {
19	BaseClient
20}
21
22// NewVirtualMachineClient creates an instance of the VirtualMachineClient client.
23func NewVirtualMachineClient(subscriptionID string) VirtualMachineClient {
24	return NewVirtualMachineClientWithBaseURI(DefaultBaseURI, subscriptionID)
25}
26
27// NewVirtualMachineClientWithBaseURI creates an instance of the VirtualMachineClient client using a custom endpoint.
28// Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
29func NewVirtualMachineClientWithBaseURI(baseURI string, subscriptionID string) VirtualMachineClient {
30	return VirtualMachineClient{NewWithBaseURI(baseURI, subscriptionID)}
31}
32
33// ApplyArtifacts apply artifacts to Lab VM. This operation can take a while to complete.
34// Parameters:
35// resourceGroupName - the name of the resource group.
36// labName - the name of the lab.
37// name - the name of the virtual Machine.
38func (client VirtualMachineClient) ApplyArtifacts(ctx context.Context, resourceGroupName string, labName string, name string, applyArtifactsRequest ApplyArtifactsRequest) (result VirtualMachineApplyArtifactsFuture, err error) {
39	if tracing.IsEnabled() {
40		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineClient.ApplyArtifacts")
41		defer func() {
42			sc := -1
43			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
44				sc = result.FutureAPI.Response().StatusCode
45			}
46			tracing.EndSpan(ctx, sc, err)
47		}()
48	}
49	req, err := client.ApplyArtifactsPreparer(ctx, resourceGroupName, labName, name, applyArtifactsRequest)
50	if err != nil {
51		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "ApplyArtifacts", nil, "Failure preparing request")
52		return
53	}
54
55	result, err = client.ApplyArtifactsSender(req)
56	if err != nil {
57		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "ApplyArtifacts", nil, "Failure sending request")
58		return
59	}
60
61	return
62}
63
64// ApplyArtifactsPreparer prepares the ApplyArtifacts request.
65func (client VirtualMachineClient) ApplyArtifactsPreparer(ctx context.Context, resourceGroupName string, labName string, name string, applyArtifactsRequest ApplyArtifactsRequest) (*http.Request, error) {
66	pathParameters := map[string]interface{}{
67		"labName":           autorest.Encode("path", labName),
68		"name":              autorest.Encode("path", name),
69		"resourceGroupName": autorest.Encode("path", resourceGroupName),
70		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
71	}
72
73	const APIVersion = "2015-05-21-preview"
74	queryParameters := map[string]interface{}{
75		"api-version": APIVersion,
76	}
77
78	preparer := autorest.CreatePreparer(
79		autorest.AsContentType("application/json; charset=utf-8"),
80		autorest.AsPost(),
81		autorest.WithBaseURL(client.BaseURI),
82		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/applyArtifacts", pathParameters),
83		autorest.WithJSON(applyArtifactsRequest),
84		autorest.WithQueryParameters(queryParameters))
85	return preparer.Prepare((&http.Request{}).WithContext(ctx))
86}
87
88// ApplyArtifactsSender sends the ApplyArtifacts request. The method will close the
89// http.Response Body if it receives an error.
90func (client VirtualMachineClient) ApplyArtifactsSender(req *http.Request) (future VirtualMachineApplyArtifactsFuture, err error) {
91	var resp *http.Response
92	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
93	if err != nil {
94		return
95	}
96	var azf azure.Future
97	azf, err = azure.NewFutureFromResponse(resp)
98	future.FutureAPI = &azf
99	future.Result = future.result
100	return
101}
102
103// ApplyArtifactsResponder handles the response to the ApplyArtifacts request. The method always
104// closes the http.Response Body.
105func (client VirtualMachineClient) ApplyArtifactsResponder(resp *http.Response) (result autorest.Response, err error) {
106	err = autorest.Respond(
107		resp,
108		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
109		autorest.ByClosing())
110	result.Response = resp
111	return
112}
113
114// CreateOrUpdateResource create or replace an existing Virtual Machine. This operation can take a while to complete.
115// Parameters:
116// resourceGroupName - the name of the resource group.
117// labName - the name of the lab.
118// name - the name of the virtual Machine.
119func (client VirtualMachineClient) CreateOrUpdateResource(ctx context.Context, resourceGroupName string, labName string, name string, labVirtualMachine LabVirtualMachine) (result VirtualMachineCreateOrUpdateResourceFuture, err error) {
120	if tracing.IsEnabled() {
121		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineClient.CreateOrUpdateResource")
122		defer func() {
123			sc := -1
124			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
125				sc = result.FutureAPI.Response().StatusCode
126			}
127			tracing.EndSpan(ctx, sc, err)
128		}()
129	}
130	req, err := client.CreateOrUpdateResourcePreparer(ctx, resourceGroupName, labName, name, labVirtualMachine)
131	if err != nil {
132		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "CreateOrUpdateResource", nil, "Failure preparing request")
133		return
134	}
135
136	result, err = client.CreateOrUpdateResourceSender(req)
137	if err != nil {
138		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "CreateOrUpdateResource", nil, "Failure sending request")
139		return
140	}
141
142	return
143}
144
145// CreateOrUpdateResourcePreparer prepares the CreateOrUpdateResource request.
146func (client VirtualMachineClient) CreateOrUpdateResourcePreparer(ctx context.Context, resourceGroupName string, labName string, name string, labVirtualMachine LabVirtualMachine) (*http.Request, error) {
147	pathParameters := map[string]interface{}{
148		"labName":           autorest.Encode("path", labName),
149		"name":              autorest.Encode("path", name),
150		"resourceGroupName": autorest.Encode("path", resourceGroupName),
151		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
152	}
153
154	const APIVersion = "2015-05-21-preview"
155	queryParameters := map[string]interface{}{
156		"api-version": APIVersion,
157	}
158
159	preparer := autorest.CreatePreparer(
160		autorest.AsContentType("application/json; charset=utf-8"),
161		autorest.AsPut(),
162		autorest.WithBaseURL(client.BaseURI),
163		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}", pathParameters),
164		autorest.WithJSON(labVirtualMachine),
165		autorest.WithQueryParameters(queryParameters))
166	return preparer.Prepare((&http.Request{}).WithContext(ctx))
167}
168
169// CreateOrUpdateResourceSender sends the CreateOrUpdateResource request. The method will close the
170// http.Response Body if it receives an error.
171func (client VirtualMachineClient) CreateOrUpdateResourceSender(req *http.Request) (future VirtualMachineCreateOrUpdateResourceFuture, err error) {
172	var resp *http.Response
173	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
174	if err != nil {
175		return
176	}
177	var azf azure.Future
178	azf, err = azure.NewFutureFromResponse(resp)
179	future.FutureAPI = &azf
180	future.Result = future.result
181	return
182}
183
184// CreateOrUpdateResourceResponder handles the response to the CreateOrUpdateResource request. The method always
185// closes the http.Response Body.
186func (client VirtualMachineClient) CreateOrUpdateResourceResponder(resp *http.Response) (result LabVirtualMachine, err error) {
187	err = autorest.Respond(
188		resp,
189		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
190		autorest.ByUnmarshallingJSON(&result),
191		autorest.ByClosing())
192	result.Response = autorest.Response{Response: resp}
193	return
194}
195
196// DeleteResource delete virtual machine. This operation can take a while to complete.
197// Parameters:
198// resourceGroupName - the name of the resource group.
199// labName - the name of the lab.
200// name - the name of the virtual Machine.
201func (client VirtualMachineClient) DeleteResource(ctx context.Context, resourceGroupName string, labName string, name string) (result VirtualMachineDeleteResourceFuture, err error) {
202	if tracing.IsEnabled() {
203		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineClient.DeleteResource")
204		defer func() {
205			sc := -1
206			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
207				sc = result.FutureAPI.Response().StatusCode
208			}
209			tracing.EndSpan(ctx, sc, err)
210		}()
211	}
212	req, err := client.DeleteResourcePreparer(ctx, resourceGroupName, labName, name)
213	if err != nil {
214		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "DeleteResource", nil, "Failure preparing request")
215		return
216	}
217
218	result, err = client.DeleteResourceSender(req)
219	if err != nil {
220		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "DeleteResource", nil, "Failure sending request")
221		return
222	}
223
224	return
225}
226
227// DeleteResourcePreparer prepares the DeleteResource request.
228func (client VirtualMachineClient) DeleteResourcePreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
229	pathParameters := map[string]interface{}{
230		"labName":           autorest.Encode("path", labName),
231		"name":              autorest.Encode("path", name),
232		"resourceGroupName": autorest.Encode("path", resourceGroupName),
233		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
234	}
235
236	const APIVersion = "2015-05-21-preview"
237	queryParameters := map[string]interface{}{
238		"api-version": APIVersion,
239	}
240
241	preparer := autorest.CreatePreparer(
242		autorest.AsDelete(),
243		autorest.WithBaseURL(client.BaseURI),
244		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}", pathParameters),
245		autorest.WithQueryParameters(queryParameters))
246	return preparer.Prepare((&http.Request{}).WithContext(ctx))
247}
248
249// DeleteResourceSender sends the DeleteResource request. The method will close the
250// http.Response Body if it receives an error.
251func (client VirtualMachineClient) DeleteResourceSender(req *http.Request) (future VirtualMachineDeleteResourceFuture, err error) {
252	var resp *http.Response
253	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
254	if err != nil {
255		return
256	}
257	var azf azure.Future
258	azf, err = azure.NewFutureFromResponse(resp)
259	future.FutureAPI = &azf
260	future.Result = future.result
261	return
262}
263
264// DeleteResourceResponder handles the response to the DeleteResource request. The method always
265// closes the http.Response Body.
266func (client VirtualMachineClient) DeleteResourceResponder(resp *http.Response) (result autorest.Response, err error) {
267	err = autorest.Respond(
268		resp,
269		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
270		autorest.ByClosing())
271	result.Response = resp
272	return
273}
274
275// GetResource get virtual machine.
276// Parameters:
277// resourceGroupName - the name of the resource group.
278// labName - the name of the lab.
279// name - the name of the virtual Machine.
280func (client VirtualMachineClient) GetResource(ctx context.Context, resourceGroupName string, labName string, name string) (result LabVirtualMachine, err error) {
281	if tracing.IsEnabled() {
282		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineClient.GetResource")
283		defer func() {
284			sc := -1
285			if result.Response.Response != nil {
286				sc = result.Response.Response.StatusCode
287			}
288			tracing.EndSpan(ctx, sc, err)
289		}()
290	}
291	req, err := client.GetResourcePreparer(ctx, resourceGroupName, labName, name)
292	if err != nil {
293		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "GetResource", nil, "Failure preparing request")
294		return
295	}
296
297	resp, err := client.GetResourceSender(req)
298	if err != nil {
299		result.Response = autorest.Response{Response: resp}
300		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "GetResource", resp, "Failure sending request")
301		return
302	}
303
304	result, err = client.GetResourceResponder(resp)
305	if err != nil {
306		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "GetResource", resp, "Failure responding to request")
307		return
308	}
309
310	return
311}
312
313// GetResourcePreparer prepares the GetResource request.
314func (client VirtualMachineClient) GetResourcePreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
315	pathParameters := map[string]interface{}{
316		"labName":           autorest.Encode("path", labName),
317		"name":              autorest.Encode("path", name),
318		"resourceGroupName": autorest.Encode("path", resourceGroupName),
319		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
320	}
321
322	const APIVersion = "2015-05-21-preview"
323	queryParameters := map[string]interface{}{
324		"api-version": APIVersion,
325	}
326
327	preparer := autorest.CreatePreparer(
328		autorest.AsGet(),
329		autorest.WithBaseURL(client.BaseURI),
330		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}", pathParameters),
331		autorest.WithQueryParameters(queryParameters))
332	return preparer.Prepare((&http.Request{}).WithContext(ctx))
333}
334
335// GetResourceSender sends the GetResource request. The method will close the
336// http.Response Body if it receives an error.
337func (client VirtualMachineClient) GetResourceSender(req *http.Request) (*http.Response, error) {
338	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
339}
340
341// GetResourceResponder handles the response to the GetResource request. The method always
342// closes the http.Response Body.
343func (client VirtualMachineClient) GetResourceResponder(resp *http.Response) (result LabVirtualMachine, err error) {
344	err = autorest.Respond(
345		resp,
346		azure.WithErrorUnlessStatusCode(http.StatusOK),
347		autorest.ByUnmarshallingJSON(&result),
348		autorest.ByClosing())
349	result.Response = autorest.Response{Response: resp}
350	return
351}
352
353// List list virtual machines.
354// Parameters:
355// resourceGroupName - the name of the resource group.
356// labName - the name of the lab.
357// filter - the filter to apply on the operation.
358func (client VirtualMachineClient) List(ctx context.Context, resourceGroupName string, labName string, filter string, top *int32, orderBy string) (result ResponseWithContinuationLabVirtualMachinePage, err error) {
359	if tracing.IsEnabled() {
360		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineClient.List")
361		defer func() {
362			sc := -1
363			if result.rwclvm.Response.Response != nil {
364				sc = result.rwclvm.Response.Response.StatusCode
365			}
366			tracing.EndSpan(ctx, sc, err)
367		}()
368	}
369	result.fn = client.listNextResults
370	req, err := client.ListPreparer(ctx, resourceGroupName, labName, filter, top, orderBy)
371	if err != nil {
372		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "List", nil, "Failure preparing request")
373		return
374	}
375
376	resp, err := client.ListSender(req)
377	if err != nil {
378		result.rwclvm.Response = autorest.Response{Response: resp}
379		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "List", resp, "Failure sending request")
380		return
381	}
382
383	result.rwclvm, err = client.ListResponder(resp)
384	if err != nil {
385		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "List", resp, "Failure responding to request")
386		return
387	}
388	if result.rwclvm.hasNextLink() && result.rwclvm.IsEmpty() {
389		err = result.NextWithContext(ctx)
390		return
391	}
392
393	return
394}
395
396// ListPreparer prepares the List request.
397func (client VirtualMachineClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, filter string, top *int32, orderBy string) (*http.Request, error) {
398	pathParameters := map[string]interface{}{
399		"labName":           autorest.Encode("path", labName),
400		"resourceGroupName": autorest.Encode("path", resourceGroupName),
401		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
402	}
403
404	const APIVersion = "2015-05-21-preview"
405	queryParameters := map[string]interface{}{
406		"api-version": APIVersion,
407	}
408	if len(filter) > 0 {
409		queryParameters["$filter"] = autorest.Encode("query", filter)
410	}
411	if top != nil {
412		queryParameters["$top"] = autorest.Encode("query", *top)
413	}
414	if len(orderBy) > 0 {
415		queryParameters["$orderBy"] = autorest.Encode("query", orderBy)
416	}
417
418	preparer := autorest.CreatePreparer(
419		autorest.AsGet(),
420		autorest.WithBaseURL(client.BaseURI),
421		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines", pathParameters),
422		autorest.WithQueryParameters(queryParameters))
423	return preparer.Prepare((&http.Request{}).WithContext(ctx))
424}
425
426// ListSender sends the List request. The method will close the
427// http.Response Body if it receives an error.
428func (client VirtualMachineClient) ListSender(req *http.Request) (*http.Response, error) {
429	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
430}
431
432// ListResponder handles the response to the List request. The method always
433// closes the http.Response Body.
434func (client VirtualMachineClient) ListResponder(resp *http.Response) (result ResponseWithContinuationLabVirtualMachine, err error) {
435	err = autorest.Respond(
436		resp,
437		azure.WithErrorUnlessStatusCode(http.StatusOK),
438		autorest.ByUnmarshallingJSON(&result),
439		autorest.ByClosing())
440	result.Response = autorest.Response{Response: resp}
441	return
442}
443
444// listNextResults retrieves the next set of results, if any.
445func (client VirtualMachineClient) listNextResults(ctx context.Context, lastResults ResponseWithContinuationLabVirtualMachine) (result ResponseWithContinuationLabVirtualMachine, err error) {
446	req, err := lastResults.responseWithContinuationLabVirtualMachinePreparer(ctx)
447	if err != nil {
448		return result, autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "listNextResults", nil, "Failure preparing next results request")
449	}
450	if req == nil {
451		return
452	}
453	resp, err := client.ListSender(req)
454	if err != nil {
455		result.Response = autorest.Response{Response: resp}
456		return result, autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "listNextResults", resp, "Failure sending next results request")
457	}
458	result, err = client.ListResponder(resp)
459	if err != nil {
460		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "listNextResults", resp, "Failure responding to next results request")
461	}
462	return
463}
464
465// ListComplete enumerates all values, automatically crossing page boundaries as required.
466func (client VirtualMachineClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, filter string, top *int32, orderBy string) (result ResponseWithContinuationLabVirtualMachineIterator, err error) {
467	if tracing.IsEnabled() {
468		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineClient.List")
469		defer func() {
470			sc := -1
471			if result.Response().Response.Response != nil {
472				sc = result.page.Response().Response.Response.StatusCode
473			}
474			tracing.EndSpan(ctx, sc, err)
475		}()
476	}
477	result.page, err = client.List(ctx, resourceGroupName, labName, filter, top, orderBy)
478	return
479}
480
481// PatchResource modify properties of virtual machines.
482// Parameters:
483// resourceGroupName - the name of the resource group.
484// labName - the name of the lab.
485// name - the name of the virtual Machine.
486func (client VirtualMachineClient) PatchResource(ctx context.Context, resourceGroupName string, labName string, name string, labVirtualMachine LabVirtualMachine) (result LabVirtualMachine, err error) {
487	if tracing.IsEnabled() {
488		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineClient.PatchResource")
489		defer func() {
490			sc := -1
491			if result.Response.Response != nil {
492				sc = result.Response.Response.StatusCode
493			}
494			tracing.EndSpan(ctx, sc, err)
495		}()
496	}
497	req, err := client.PatchResourcePreparer(ctx, resourceGroupName, labName, name, labVirtualMachine)
498	if err != nil {
499		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "PatchResource", nil, "Failure preparing request")
500		return
501	}
502
503	resp, err := client.PatchResourceSender(req)
504	if err != nil {
505		result.Response = autorest.Response{Response: resp}
506		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "PatchResource", resp, "Failure sending request")
507		return
508	}
509
510	result, err = client.PatchResourceResponder(resp)
511	if err != nil {
512		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "PatchResource", resp, "Failure responding to request")
513		return
514	}
515
516	return
517}
518
519// PatchResourcePreparer prepares the PatchResource request.
520func (client VirtualMachineClient) PatchResourcePreparer(ctx context.Context, resourceGroupName string, labName string, name string, labVirtualMachine LabVirtualMachine) (*http.Request, error) {
521	pathParameters := map[string]interface{}{
522		"labName":           autorest.Encode("path", labName),
523		"name":              autorest.Encode("path", name),
524		"resourceGroupName": autorest.Encode("path", resourceGroupName),
525		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
526	}
527
528	const APIVersion = "2015-05-21-preview"
529	queryParameters := map[string]interface{}{
530		"api-version": APIVersion,
531	}
532
533	preparer := autorest.CreatePreparer(
534		autorest.AsContentType("application/json; charset=utf-8"),
535		autorest.AsPatch(),
536		autorest.WithBaseURL(client.BaseURI),
537		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}", pathParameters),
538		autorest.WithJSON(labVirtualMachine),
539		autorest.WithQueryParameters(queryParameters))
540	return preparer.Prepare((&http.Request{}).WithContext(ctx))
541}
542
543// PatchResourceSender sends the PatchResource request. The method will close the
544// http.Response Body if it receives an error.
545func (client VirtualMachineClient) PatchResourceSender(req *http.Request) (*http.Response, error) {
546	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
547}
548
549// PatchResourceResponder handles the response to the PatchResource request. The method always
550// closes the http.Response Body.
551func (client VirtualMachineClient) PatchResourceResponder(resp *http.Response) (result LabVirtualMachine, err error) {
552	err = autorest.Respond(
553		resp,
554		azure.WithErrorUnlessStatusCode(http.StatusOK),
555		autorest.ByUnmarshallingJSON(&result),
556		autorest.ByClosing())
557	result.Response = autorest.Response{Response: resp}
558	return
559}
560
561// Start start a Lab VM. This operation can take a while to complete.
562// Parameters:
563// resourceGroupName - the name of the resource group.
564// labName - the name of the lab.
565// name - the name of the virtual Machine.
566func (client VirtualMachineClient) Start(ctx context.Context, resourceGroupName string, labName string, name string) (result VirtualMachineStartFuture, err error) {
567	if tracing.IsEnabled() {
568		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineClient.Start")
569		defer func() {
570			sc := -1
571			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
572				sc = result.FutureAPI.Response().StatusCode
573			}
574			tracing.EndSpan(ctx, sc, err)
575		}()
576	}
577	req, err := client.StartPreparer(ctx, resourceGroupName, labName, name)
578	if err != nil {
579		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "Start", nil, "Failure preparing request")
580		return
581	}
582
583	result, err = client.StartSender(req)
584	if err != nil {
585		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "Start", nil, "Failure sending request")
586		return
587	}
588
589	return
590}
591
592// StartPreparer prepares the Start request.
593func (client VirtualMachineClient) StartPreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
594	pathParameters := map[string]interface{}{
595		"labName":           autorest.Encode("path", labName),
596		"name":              autorest.Encode("path", name),
597		"resourceGroupName": autorest.Encode("path", resourceGroupName),
598		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
599	}
600
601	const APIVersion = "2015-05-21-preview"
602	queryParameters := map[string]interface{}{
603		"api-version": APIVersion,
604	}
605
606	preparer := autorest.CreatePreparer(
607		autorest.AsPost(),
608		autorest.WithBaseURL(client.BaseURI),
609		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/start", pathParameters),
610		autorest.WithQueryParameters(queryParameters))
611	return preparer.Prepare((&http.Request{}).WithContext(ctx))
612}
613
614// StartSender sends the Start request. The method will close the
615// http.Response Body if it receives an error.
616func (client VirtualMachineClient) StartSender(req *http.Request) (future VirtualMachineStartFuture, err error) {
617	var resp *http.Response
618	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
619	if err != nil {
620		return
621	}
622	var azf azure.Future
623	azf, err = azure.NewFutureFromResponse(resp)
624	future.FutureAPI = &azf
625	future.Result = future.result
626	return
627}
628
629// StartResponder handles the response to the Start request. The method always
630// closes the http.Response Body.
631func (client VirtualMachineClient) StartResponder(resp *http.Response) (result autorest.Response, err error) {
632	err = autorest.Respond(
633		resp,
634		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
635		autorest.ByClosing())
636	result.Response = resp
637	return
638}
639
640// Stop stop a Lab VM. This operation can take a while to complete.
641// Parameters:
642// resourceGroupName - the name of the resource group.
643// labName - the name of the lab.
644// name - the name of the virtual Machine.
645func (client VirtualMachineClient) Stop(ctx context.Context, resourceGroupName string, labName string, name string) (result VirtualMachineStopFuture, err error) {
646	if tracing.IsEnabled() {
647		ctx = tracing.StartSpan(ctx, fqdn+"/VirtualMachineClient.Stop")
648		defer func() {
649			sc := -1
650			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
651				sc = result.FutureAPI.Response().StatusCode
652			}
653			tracing.EndSpan(ctx, sc, err)
654		}()
655	}
656	req, err := client.StopPreparer(ctx, resourceGroupName, labName, name)
657	if err != nil {
658		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "Stop", nil, "Failure preparing request")
659		return
660	}
661
662	result, err = client.StopSender(req)
663	if err != nil {
664		err = autorest.NewErrorWithError(err, "dtl.VirtualMachineClient", "Stop", nil, "Failure sending request")
665		return
666	}
667
668	return
669}
670
671// StopPreparer prepares the Stop request.
672func (client VirtualMachineClient) StopPreparer(ctx context.Context, resourceGroupName string, labName string, name 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 = "2015-05-21-preview"
681	queryParameters := map[string]interface{}{
682		"api-version": APIVersion,
683	}
684
685	preparer := autorest.CreatePreparer(
686		autorest.AsPost(),
687		autorest.WithBaseURL(client.BaseURI),
688		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/virtualmachines/{name}/stop", pathParameters),
689		autorest.WithQueryParameters(queryParameters))
690	return preparer.Prepare((&http.Request{}).WithContext(ctx))
691}
692
693// StopSender sends the Stop request. The method will close the
694// http.Response Body if it receives an error.
695func (client VirtualMachineClient) StopSender(req *http.Request) (future VirtualMachineStopFuture, err error) {
696	var resp *http.Response
697	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
698	if err != nil {
699		return
700	}
701	var azf azure.Future
702	azf, err = azure.NewFutureFromResponse(resp)
703	future.FutureAPI = &azf
704	future.Result = future.result
705	return
706}
707
708// StopResponder handles the response to the Stop request. The method always
709// closes the http.Response Body.
710func (client VirtualMachineClient) StopResponder(resp *http.Response) (result autorest.Response, err error) {
711	err = autorest.Respond(
712		resp,
713		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
714		autorest.ByClosing())
715	result.Response = resp
716	return
717}
718