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