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