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// GlobalSchedulesClient is the the DevTest Labs Client.
30type GlobalSchedulesClient struct {
31	BaseClient
32}
33
34// NewGlobalSchedulesClient creates an instance of the GlobalSchedulesClient client.
35func NewGlobalSchedulesClient(subscriptionID string) GlobalSchedulesClient {
36	return NewGlobalSchedulesClientWithBaseURI(DefaultBaseURI, subscriptionID)
37}
38
39// NewGlobalSchedulesClientWithBaseURI creates an instance of the GlobalSchedulesClient client.
40func NewGlobalSchedulesClientWithBaseURI(baseURI string, subscriptionID string) GlobalSchedulesClient {
41	return GlobalSchedulesClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// CreateOrUpdate create or replace an existing schedule.
45// Parameters:
46// resourceGroupName - the name of the resource group.
47// name - the name of the schedule.
48// schedule - a schedule.
49func (client GlobalSchedulesClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, name string, schedule Schedule) (result Schedule, err error) {
50	if tracing.IsEnabled() {
51		ctx = tracing.StartSpan(ctx, fqdn+"/GlobalSchedulesClient.CreateOrUpdate")
52		defer func() {
53			sc := -1
54			if result.Response.Response != nil {
55				sc = result.Response.Response.StatusCode
56			}
57			tracing.EndSpan(ctx, sc, err)
58		}()
59	}
60	if err := validation.Validate([]validation.Validation{
61		{TargetValue: schedule,
62			Constraints: []validation.Constraint{{Target: "schedule.ScheduleProperties", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
63		return result, validation.NewError("dtl.GlobalSchedulesClient", "CreateOrUpdate", err.Error())
64	}
65
66	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, name, schedule)
67	if err != nil {
68		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "CreateOrUpdate", nil, "Failure preparing request")
69		return
70	}
71
72	resp, err := client.CreateOrUpdateSender(req)
73	if err != nil {
74		result.Response = autorest.Response{Response: resp}
75		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "CreateOrUpdate", resp, "Failure sending request")
76		return
77	}
78
79	result, err = client.CreateOrUpdateResponder(resp)
80	if err != nil {
81		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "CreateOrUpdate", resp, "Failure responding to request")
82	}
83
84	return
85}
86
87// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
88func (client GlobalSchedulesClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, name string, schedule Schedule) (*http.Request, error) {
89	pathParameters := map[string]interface{}{
90		"name":              autorest.Encode("path", name),
91		"resourceGroupName": autorest.Encode("path", resourceGroupName),
92		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
93	}
94
95	const APIVersion = "2018-09-15"
96	queryParameters := map[string]interface{}{
97		"api-version": APIVersion,
98	}
99
100	preparer := autorest.CreatePreparer(
101		autorest.AsContentType("application/json; charset=utf-8"),
102		autorest.AsPut(),
103		autorest.WithBaseURL(client.BaseURI),
104		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}", pathParameters),
105		autorest.WithJSON(schedule),
106		autorest.WithQueryParameters(queryParameters))
107	return preparer.Prepare((&http.Request{}).WithContext(ctx))
108}
109
110// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
111// http.Response Body if it receives an error.
112func (client GlobalSchedulesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
113	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
114	return autorest.SendWithSender(client, req, sd...)
115}
116
117// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
118// closes the http.Response Body.
119func (client GlobalSchedulesClient) CreateOrUpdateResponder(resp *http.Response) (result Schedule, err error) {
120	err = autorest.Respond(
121		resp,
122		client.ByInspecting(),
123		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
124		autorest.ByUnmarshallingJSON(&result),
125		autorest.ByClosing())
126	result.Response = autorest.Response{Response: resp}
127	return
128}
129
130// Delete delete schedule.
131// Parameters:
132// resourceGroupName - the name of the resource group.
133// name - the name of the schedule.
134func (client GlobalSchedulesClient) Delete(ctx context.Context, resourceGroupName string, name string) (result autorest.Response, err error) {
135	if tracing.IsEnabled() {
136		ctx = tracing.StartSpan(ctx, fqdn+"/GlobalSchedulesClient.Delete")
137		defer func() {
138			sc := -1
139			if result.Response != nil {
140				sc = result.Response.StatusCode
141			}
142			tracing.EndSpan(ctx, sc, err)
143		}()
144	}
145	req, err := client.DeletePreparer(ctx, resourceGroupName, name)
146	if err != nil {
147		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Delete", nil, "Failure preparing request")
148		return
149	}
150
151	resp, err := client.DeleteSender(req)
152	if err != nil {
153		result.Response = resp
154		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Delete", resp, "Failure sending request")
155		return
156	}
157
158	result, err = client.DeleteResponder(resp)
159	if err != nil {
160		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Delete", resp, "Failure responding to request")
161	}
162
163	return
164}
165
166// DeletePreparer prepares the Delete request.
167func (client GlobalSchedulesClient) DeletePreparer(ctx context.Context, resourceGroupName string, name string) (*http.Request, error) {
168	pathParameters := map[string]interface{}{
169		"name":              autorest.Encode("path", name),
170		"resourceGroupName": autorest.Encode("path", resourceGroupName),
171		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
172	}
173
174	const APIVersion = "2018-09-15"
175	queryParameters := map[string]interface{}{
176		"api-version": APIVersion,
177	}
178
179	preparer := autorest.CreatePreparer(
180		autorest.AsDelete(),
181		autorest.WithBaseURL(client.BaseURI),
182		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}", pathParameters),
183		autorest.WithQueryParameters(queryParameters))
184	return preparer.Prepare((&http.Request{}).WithContext(ctx))
185}
186
187// DeleteSender sends the Delete request. The method will close the
188// http.Response Body if it receives an error.
189func (client GlobalSchedulesClient) DeleteSender(req *http.Request) (*http.Response, error) {
190	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
191	return autorest.SendWithSender(client, req, sd...)
192}
193
194// DeleteResponder handles the response to the Delete request. The method always
195// closes the http.Response Body.
196func (client GlobalSchedulesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
197	err = autorest.Respond(
198		resp,
199		client.ByInspecting(),
200		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
201		autorest.ByClosing())
202	result.Response = resp
203	return
204}
205
206// Execute execute a schedule. This operation can take a while to complete.
207// Parameters:
208// resourceGroupName - the name of the resource group.
209// name - the name of the schedule.
210func (client GlobalSchedulesClient) Execute(ctx context.Context, resourceGroupName string, name string) (result GlobalSchedulesExecuteFuture, err error) {
211	if tracing.IsEnabled() {
212		ctx = tracing.StartSpan(ctx, fqdn+"/GlobalSchedulesClient.Execute")
213		defer func() {
214			sc := -1
215			if result.Response() != nil {
216				sc = result.Response().StatusCode
217			}
218			tracing.EndSpan(ctx, sc, err)
219		}()
220	}
221	req, err := client.ExecutePreparer(ctx, resourceGroupName, name)
222	if err != nil {
223		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Execute", nil, "Failure preparing request")
224		return
225	}
226
227	result, err = client.ExecuteSender(req)
228	if err != nil {
229		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Execute", result.Response(), "Failure sending request")
230		return
231	}
232
233	return
234}
235
236// ExecutePreparer prepares the Execute request.
237func (client GlobalSchedulesClient) ExecutePreparer(ctx context.Context, resourceGroupName string, name string) (*http.Request, error) {
238	pathParameters := map[string]interface{}{
239		"name":              autorest.Encode("path", name),
240		"resourceGroupName": autorest.Encode("path", resourceGroupName),
241		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
242	}
243
244	const APIVersion = "2018-09-15"
245	queryParameters := map[string]interface{}{
246		"api-version": APIVersion,
247	}
248
249	preparer := autorest.CreatePreparer(
250		autorest.AsPost(),
251		autorest.WithBaseURL(client.BaseURI),
252		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}/execute", pathParameters),
253		autorest.WithQueryParameters(queryParameters))
254	return preparer.Prepare((&http.Request{}).WithContext(ctx))
255}
256
257// ExecuteSender sends the Execute request. The method will close the
258// http.Response Body if it receives an error.
259func (client GlobalSchedulesClient) ExecuteSender(req *http.Request) (future GlobalSchedulesExecuteFuture, err error) {
260	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
261	var resp *http.Response
262	resp, err = autorest.SendWithSender(client, req, sd...)
263	if err != nil {
264		return
265	}
266	future.Future, err = azure.NewFutureFromResponse(resp)
267	return
268}
269
270// ExecuteResponder handles the response to the Execute request. The method always
271// closes the http.Response Body.
272func (client GlobalSchedulesClient) ExecuteResponder(resp *http.Response) (result autorest.Response, err error) {
273	err = autorest.Respond(
274		resp,
275		client.ByInspecting(),
276		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
277		autorest.ByClosing())
278	result.Response = resp
279	return
280}
281
282// Get get schedule.
283// Parameters:
284// resourceGroupName - the name of the resource group.
285// name - the name of the schedule.
286// expand - specify the $expand query. Example: 'properties($select=status)'
287func (client GlobalSchedulesClient) Get(ctx context.Context, resourceGroupName string, name string, expand string) (result Schedule, err error) {
288	if tracing.IsEnabled() {
289		ctx = tracing.StartSpan(ctx, fqdn+"/GlobalSchedulesClient.Get")
290		defer func() {
291			sc := -1
292			if result.Response.Response != nil {
293				sc = result.Response.Response.StatusCode
294			}
295			tracing.EndSpan(ctx, sc, err)
296		}()
297	}
298	req, err := client.GetPreparer(ctx, resourceGroupName, name, expand)
299	if err != nil {
300		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Get", nil, "Failure preparing request")
301		return
302	}
303
304	resp, err := client.GetSender(req)
305	if err != nil {
306		result.Response = autorest.Response{Response: resp}
307		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Get", resp, "Failure sending request")
308		return
309	}
310
311	result, err = client.GetResponder(resp)
312	if err != nil {
313		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Get", resp, "Failure responding to request")
314	}
315
316	return
317}
318
319// GetPreparer prepares the Get request.
320func (client GlobalSchedulesClient) GetPreparer(ctx context.Context, resourceGroupName string, name string, expand string) (*http.Request, error) {
321	pathParameters := map[string]interface{}{
322		"name":              autorest.Encode("path", name),
323		"resourceGroupName": autorest.Encode("path", resourceGroupName),
324		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
325	}
326
327	const APIVersion = "2018-09-15"
328	queryParameters := map[string]interface{}{
329		"api-version": APIVersion,
330	}
331	if len(expand) > 0 {
332		queryParameters["$expand"] = autorest.Encode("query", expand)
333	}
334
335	preparer := autorest.CreatePreparer(
336		autorest.AsGet(),
337		autorest.WithBaseURL(client.BaseURI),
338		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}", pathParameters),
339		autorest.WithQueryParameters(queryParameters))
340	return preparer.Prepare((&http.Request{}).WithContext(ctx))
341}
342
343// GetSender sends the Get request. The method will close the
344// http.Response Body if it receives an error.
345func (client GlobalSchedulesClient) GetSender(req *http.Request) (*http.Response, error) {
346	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
347	return autorest.SendWithSender(client, req, sd...)
348}
349
350// GetResponder handles the response to the Get request. The method always
351// closes the http.Response Body.
352func (client GlobalSchedulesClient) GetResponder(resp *http.Response) (result Schedule, err error) {
353	err = autorest.Respond(
354		resp,
355		client.ByInspecting(),
356		azure.WithErrorUnlessStatusCode(http.StatusOK),
357		autorest.ByUnmarshallingJSON(&result),
358		autorest.ByClosing())
359	result.Response = autorest.Response{Response: resp}
360	return
361}
362
363// ListByResourceGroup list schedules in a resource group.
364// Parameters:
365// resourceGroupName - the name of the resource group.
366// expand - specify the $expand query. Example: 'properties($select=status)'
367// filter - the filter to apply to the operation. Example: '$filter=contains(name,'myName')
368// top - the maximum number of resources to return from the operation. Example: '$top=10'
369// orderby - the ordering expression for the results, using OData notation. Example: '$orderby=name desc'
370func (client GlobalSchedulesClient) ListByResourceGroup(ctx context.Context, resourceGroupName string, expand string, filter string, top *int32, orderby string) (result ScheduleListPage, err error) {
371	if tracing.IsEnabled() {
372		ctx = tracing.StartSpan(ctx, fqdn+"/GlobalSchedulesClient.ListByResourceGroup")
373		defer func() {
374			sc := -1
375			if result.sl.Response.Response != nil {
376				sc = result.sl.Response.Response.StatusCode
377			}
378			tracing.EndSpan(ctx, sc, err)
379		}()
380	}
381	result.fn = client.listByResourceGroupNextResults
382	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName, expand, filter, top, orderby)
383	if err != nil {
384		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "ListByResourceGroup", nil, "Failure preparing request")
385		return
386	}
387
388	resp, err := client.ListByResourceGroupSender(req)
389	if err != nil {
390		result.sl.Response = autorest.Response{Response: resp}
391		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "ListByResourceGroup", resp, "Failure sending request")
392		return
393	}
394
395	result.sl, err = client.ListByResourceGroupResponder(resp)
396	if err != nil {
397		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "ListByResourceGroup", resp, "Failure responding to request")
398	}
399
400	return
401}
402
403// ListByResourceGroupPreparer prepares the ListByResourceGroup request.
404func (client GlobalSchedulesClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string, expand string, filter string, top *int32, orderby string) (*http.Request, error) {
405	pathParameters := map[string]interface{}{
406		"resourceGroupName": autorest.Encode("path", resourceGroupName),
407		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
408	}
409
410	const APIVersion = "2018-09-15"
411	queryParameters := map[string]interface{}{
412		"api-version": APIVersion,
413	}
414	if len(expand) > 0 {
415		queryParameters["$expand"] = autorest.Encode("query", expand)
416	}
417	if len(filter) > 0 {
418		queryParameters["$filter"] = autorest.Encode("query", filter)
419	}
420	if top != nil {
421		queryParameters["$top"] = autorest.Encode("query", *top)
422	}
423	if len(orderby) > 0 {
424		queryParameters["$orderby"] = autorest.Encode("query", orderby)
425	}
426
427	preparer := autorest.CreatePreparer(
428		autorest.AsGet(),
429		autorest.WithBaseURL(client.BaseURI),
430		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules", pathParameters),
431		autorest.WithQueryParameters(queryParameters))
432	return preparer.Prepare((&http.Request{}).WithContext(ctx))
433}
434
435// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
436// http.Response Body if it receives an error.
437func (client GlobalSchedulesClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
438	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
439	return autorest.SendWithSender(client, req, sd...)
440}
441
442// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
443// closes the http.Response Body.
444func (client GlobalSchedulesClient) ListByResourceGroupResponder(resp *http.Response) (result ScheduleList, err error) {
445	err = autorest.Respond(
446		resp,
447		client.ByInspecting(),
448		azure.WithErrorUnlessStatusCode(http.StatusOK),
449		autorest.ByUnmarshallingJSON(&result),
450		autorest.ByClosing())
451	result.Response = autorest.Response{Response: resp}
452	return
453}
454
455// listByResourceGroupNextResults retrieves the next set of results, if any.
456func (client GlobalSchedulesClient) listByResourceGroupNextResults(ctx context.Context, lastResults ScheduleList) (result ScheduleList, err error) {
457	req, err := lastResults.scheduleListPreparer(ctx)
458	if err != nil {
459		return result, autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request")
460	}
461	if req == nil {
462		return
463	}
464	resp, err := client.ListByResourceGroupSender(req)
465	if err != nil {
466		result.Response = autorest.Response{Response: resp}
467		return result, autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "listByResourceGroupNextResults", resp, "Failure sending next results request")
468	}
469	result, err = client.ListByResourceGroupResponder(resp)
470	if err != nil {
471		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request")
472	}
473	return
474}
475
476// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required.
477func (client GlobalSchedulesClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string, expand string, filter string, top *int32, orderby string) (result ScheduleListIterator, err error) {
478	if tracing.IsEnabled() {
479		ctx = tracing.StartSpan(ctx, fqdn+"/GlobalSchedulesClient.ListByResourceGroup")
480		defer func() {
481			sc := -1
482			if result.Response().Response.Response != nil {
483				sc = result.page.Response().Response.Response.StatusCode
484			}
485			tracing.EndSpan(ctx, sc, err)
486		}()
487	}
488	result.page, err = client.ListByResourceGroup(ctx, resourceGroupName, expand, filter, top, orderby)
489	return
490}
491
492// ListBySubscription list schedules in a subscription.
493// Parameters:
494// expand - specify the $expand query. Example: 'properties($select=status)'
495// filter - the filter to apply to the operation. Example: '$filter=contains(name,'myName')
496// top - the maximum number of resources to return from the operation. Example: '$top=10'
497// orderby - the ordering expression for the results, using OData notation. Example: '$orderby=name desc'
498func (client GlobalSchedulesClient) ListBySubscription(ctx context.Context, expand string, filter string, top *int32, orderby string) (result ScheduleListPage, err error) {
499	if tracing.IsEnabled() {
500		ctx = tracing.StartSpan(ctx, fqdn+"/GlobalSchedulesClient.ListBySubscription")
501		defer func() {
502			sc := -1
503			if result.sl.Response.Response != nil {
504				sc = result.sl.Response.Response.StatusCode
505			}
506			tracing.EndSpan(ctx, sc, err)
507		}()
508	}
509	result.fn = client.listBySubscriptionNextResults
510	req, err := client.ListBySubscriptionPreparer(ctx, expand, filter, top, orderby)
511	if err != nil {
512		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "ListBySubscription", nil, "Failure preparing request")
513		return
514	}
515
516	resp, err := client.ListBySubscriptionSender(req)
517	if err != nil {
518		result.sl.Response = autorest.Response{Response: resp}
519		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "ListBySubscription", resp, "Failure sending request")
520		return
521	}
522
523	result.sl, err = client.ListBySubscriptionResponder(resp)
524	if err != nil {
525		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "ListBySubscription", resp, "Failure responding to request")
526	}
527
528	return
529}
530
531// ListBySubscriptionPreparer prepares the ListBySubscription request.
532func (client GlobalSchedulesClient) ListBySubscriptionPreparer(ctx context.Context, expand string, filter string, top *int32, orderby string) (*http.Request, error) {
533	pathParameters := map[string]interface{}{
534		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
535	}
536
537	const APIVersion = "2018-09-15"
538	queryParameters := map[string]interface{}{
539		"api-version": APIVersion,
540	}
541	if len(expand) > 0 {
542		queryParameters["$expand"] = autorest.Encode("query", expand)
543	}
544	if len(filter) > 0 {
545		queryParameters["$filter"] = autorest.Encode("query", filter)
546	}
547	if top != nil {
548		queryParameters["$top"] = autorest.Encode("query", *top)
549	}
550	if len(orderby) > 0 {
551		queryParameters["$orderby"] = autorest.Encode("query", orderby)
552	}
553
554	preparer := autorest.CreatePreparer(
555		autorest.AsGet(),
556		autorest.WithBaseURL(client.BaseURI),
557		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DevTestLab/schedules", pathParameters),
558		autorest.WithQueryParameters(queryParameters))
559	return preparer.Prepare((&http.Request{}).WithContext(ctx))
560}
561
562// ListBySubscriptionSender sends the ListBySubscription request. The method will close the
563// http.Response Body if it receives an error.
564func (client GlobalSchedulesClient) ListBySubscriptionSender(req *http.Request) (*http.Response, error) {
565	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
566	return autorest.SendWithSender(client, req, sd...)
567}
568
569// ListBySubscriptionResponder handles the response to the ListBySubscription request. The method always
570// closes the http.Response Body.
571func (client GlobalSchedulesClient) ListBySubscriptionResponder(resp *http.Response) (result ScheduleList, err error) {
572	err = autorest.Respond(
573		resp,
574		client.ByInspecting(),
575		azure.WithErrorUnlessStatusCode(http.StatusOK),
576		autorest.ByUnmarshallingJSON(&result),
577		autorest.ByClosing())
578	result.Response = autorest.Response{Response: resp}
579	return
580}
581
582// listBySubscriptionNextResults retrieves the next set of results, if any.
583func (client GlobalSchedulesClient) listBySubscriptionNextResults(ctx context.Context, lastResults ScheduleList) (result ScheduleList, err error) {
584	req, err := lastResults.scheduleListPreparer(ctx)
585	if err != nil {
586		return result, autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "listBySubscriptionNextResults", nil, "Failure preparing next results request")
587	}
588	if req == nil {
589		return
590	}
591	resp, err := client.ListBySubscriptionSender(req)
592	if err != nil {
593		result.Response = autorest.Response{Response: resp}
594		return result, autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "listBySubscriptionNextResults", resp, "Failure sending next results request")
595	}
596	result, err = client.ListBySubscriptionResponder(resp)
597	if err != nil {
598		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "listBySubscriptionNextResults", resp, "Failure responding to next results request")
599	}
600	return
601}
602
603// ListBySubscriptionComplete enumerates all values, automatically crossing page boundaries as required.
604func (client GlobalSchedulesClient) ListBySubscriptionComplete(ctx context.Context, expand string, filter string, top *int32, orderby string) (result ScheduleListIterator, err error) {
605	if tracing.IsEnabled() {
606		ctx = tracing.StartSpan(ctx, fqdn+"/GlobalSchedulesClient.ListBySubscription")
607		defer func() {
608			sc := -1
609			if result.Response().Response.Response != nil {
610				sc = result.page.Response().Response.Response.StatusCode
611			}
612			tracing.EndSpan(ctx, sc, err)
613		}()
614	}
615	result.page, err = client.ListBySubscription(ctx, expand, filter, top, orderby)
616	return
617}
618
619// Retarget updates a schedule's target resource Id. This operation can take a while to complete.
620// Parameters:
621// resourceGroupName - the name of the resource group.
622// name - the name of the schedule.
623// retargetScheduleProperties - properties for retargeting a virtual machine schedule.
624func (client GlobalSchedulesClient) Retarget(ctx context.Context, resourceGroupName string, name string, retargetScheduleProperties RetargetScheduleProperties) (result GlobalSchedulesRetargetFuture, err error) {
625	if tracing.IsEnabled() {
626		ctx = tracing.StartSpan(ctx, fqdn+"/GlobalSchedulesClient.Retarget")
627		defer func() {
628			sc := -1
629			if result.Response() != nil {
630				sc = result.Response().StatusCode
631			}
632			tracing.EndSpan(ctx, sc, err)
633		}()
634	}
635	req, err := client.RetargetPreparer(ctx, resourceGroupName, name, retargetScheduleProperties)
636	if err != nil {
637		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Retarget", nil, "Failure preparing request")
638		return
639	}
640
641	result, err = client.RetargetSender(req)
642	if err != nil {
643		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Retarget", result.Response(), "Failure sending request")
644		return
645	}
646
647	return
648}
649
650// RetargetPreparer prepares the Retarget request.
651func (client GlobalSchedulesClient) RetargetPreparer(ctx context.Context, resourceGroupName string, name string, retargetScheduleProperties RetargetScheduleProperties) (*http.Request, error) {
652	pathParameters := map[string]interface{}{
653		"name":              autorest.Encode("path", name),
654		"resourceGroupName": autorest.Encode("path", resourceGroupName),
655		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
656	}
657
658	const APIVersion = "2018-09-15"
659	queryParameters := map[string]interface{}{
660		"api-version": APIVersion,
661	}
662
663	preparer := autorest.CreatePreparer(
664		autorest.AsContentType("application/json; charset=utf-8"),
665		autorest.AsPost(),
666		autorest.WithBaseURL(client.BaseURI),
667		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}/retarget", pathParameters),
668		autorest.WithJSON(retargetScheduleProperties),
669		autorest.WithQueryParameters(queryParameters))
670	return preparer.Prepare((&http.Request{}).WithContext(ctx))
671}
672
673// RetargetSender sends the Retarget request. The method will close the
674// http.Response Body if it receives an error.
675func (client GlobalSchedulesClient) RetargetSender(req *http.Request) (future GlobalSchedulesRetargetFuture, err error) {
676	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
677	var resp *http.Response
678	resp, err = autorest.SendWithSender(client, req, sd...)
679	if err != nil {
680		return
681	}
682	future.Future, err = azure.NewFutureFromResponse(resp)
683	return
684}
685
686// RetargetResponder handles the response to the Retarget request. The method always
687// closes the http.Response Body.
688func (client GlobalSchedulesClient) RetargetResponder(resp *http.Response) (result autorest.Response, err error) {
689	err = autorest.Respond(
690		resp,
691		client.ByInspecting(),
692		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
693		autorest.ByClosing())
694	result.Response = resp
695	return
696}
697
698// Update allows modifying tags of schedules. All other properties will be ignored.
699// Parameters:
700// resourceGroupName - the name of the resource group.
701// name - the name of the schedule.
702// schedule - a schedule.
703func (client GlobalSchedulesClient) Update(ctx context.Context, resourceGroupName string, name string, schedule ScheduleFragment) (result Schedule, err error) {
704	if tracing.IsEnabled() {
705		ctx = tracing.StartSpan(ctx, fqdn+"/GlobalSchedulesClient.Update")
706		defer func() {
707			sc := -1
708			if result.Response.Response != nil {
709				sc = result.Response.Response.StatusCode
710			}
711			tracing.EndSpan(ctx, sc, err)
712		}()
713	}
714	req, err := client.UpdatePreparer(ctx, resourceGroupName, name, schedule)
715	if err != nil {
716		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Update", nil, "Failure preparing request")
717		return
718	}
719
720	resp, err := client.UpdateSender(req)
721	if err != nil {
722		result.Response = autorest.Response{Response: resp}
723		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Update", resp, "Failure sending request")
724		return
725	}
726
727	result, err = client.UpdateResponder(resp)
728	if err != nil {
729		err = autorest.NewErrorWithError(err, "dtl.GlobalSchedulesClient", "Update", resp, "Failure responding to request")
730	}
731
732	return
733}
734
735// UpdatePreparer prepares the Update request.
736func (client GlobalSchedulesClient) UpdatePreparer(ctx context.Context, resourceGroupName string, name string, schedule ScheduleFragment) (*http.Request, error) {
737	pathParameters := map[string]interface{}{
738		"name":              autorest.Encode("path", name),
739		"resourceGroupName": autorest.Encode("path", resourceGroupName),
740		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
741	}
742
743	const APIVersion = "2018-09-15"
744	queryParameters := map[string]interface{}{
745		"api-version": APIVersion,
746	}
747
748	preparer := autorest.CreatePreparer(
749		autorest.AsContentType("application/json; charset=utf-8"),
750		autorest.AsPatch(),
751		autorest.WithBaseURL(client.BaseURI),
752		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/schedules/{name}", pathParameters),
753		autorest.WithJSON(schedule),
754		autorest.WithQueryParameters(queryParameters))
755	return preparer.Prepare((&http.Request{}).WithContext(ctx))
756}
757
758// UpdateSender sends the Update request. The method will close the
759// http.Response Body if it receives an error.
760func (client GlobalSchedulesClient) UpdateSender(req *http.Request) (*http.Response, error) {
761	sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client))
762	return autorest.SendWithSender(client, req, sd...)
763}
764
765// UpdateResponder handles the response to the Update request. The method always
766// closes the http.Response Body.
767func (client GlobalSchedulesClient) UpdateResponder(resp *http.Response) (result Schedule, err error) {
768	err = autorest.Respond(
769		resp,
770		client.ByInspecting(),
771		azure.WithErrorUnlessStatusCode(http.StatusOK),
772		autorest.ByUnmarshallingJSON(&result),
773		autorest.ByClosing())
774	result.Response = autorest.Response{Response: resp}
775	return
776}
777