1package storsimple
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	"net/http"
26)
27
28// BackupSchedulesClient is the client for the BackupSchedules methods of the Storsimple service.
29type BackupSchedulesClient struct {
30	BaseClient
31}
32
33// NewBackupSchedulesClient creates an instance of the BackupSchedulesClient client.
34func NewBackupSchedulesClient(subscriptionID string) BackupSchedulesClient {
35	return NewBackupSchedulesClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewBackupSchedulesClientWithBaseURI creates an instance of the BackupSchedulesClient client.
39func NewBackupSchedulesClientWithBaseURI(baseURI string, subscriptionID string) BackupSchedulesClient {
40	return BackupSchedulesClient{NewWithBaseURI(baseURI, subscriptionID)}
41}
42
43// CreateOrUpdate creates or updates the backup schedule.
44// Parameters:
45// deviceName - the device name
46// backupPolicyName - the backup policy name.
47// backupScheduleName - the backup schedule name.
48// parameters - the backup schedule.
49// resourceGroupName - the resource group name
50// managerName - the manager name
51func (client BackupSchedulesClient) CreateOrUpdate(ctx context.Context, deviceName string, backupPolicyName string, backupScheduleName string, parameters BackupSchedule, resourceGroupName string, managerName string) (result BackupSchedulesCreateOrUpdateFuture, err error) {
52	if err := validation.Validate([]validation.Validation{
53		{TargetValue: parameters,
54			Constraints: []validation.Constraint{{Target: "parameters.BackupScheduleProperties", Name: validation.Null, Rule: true,
55				Chain: []validation.Constraint{{Target: "parameters.BackupScheduleProperties.ScheduleRecurrence", Name: validation.Null, Rule: true,
56					Chain: []validation.Constraint{{Target: "parameters.BackupScheduleProperties.ScheduleRecurrence.RecurrenceValue", Name: validation.Null, Rule: true, Chain: nil}}},
57					{Target: "parameters.BackupScheduleProperties.RetentionCount", Name: validation.Null, Rule: true, Chain: nil},
58					{Target: "parameters.BackupScheduleProperties.StartTime", Name: validation.Null, Rule: true, Chain: nil},
59				}}}},
60		{TargetValue: managerName,
61			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
62				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
63		return result, validation.NewError("storsimple.BackupSchedulesClient", "CreateOrUpdate", err.Error())
64	}
65
66	req, err := client.CreateOrUpdatePreparer(ctx, deviceName, backupPolicyName, backupScheduleName, parameters, resourceGroupName, managerName)
67	if err != nil {
68		err = autorest.NewErrorWithError(err, "storsimple.BackupSchedulesClient", "CreateOrUpdate", nil, "Failure preparing request")
69		return
70	}
71
72	result, err = client.CreateOrUpdateSender(req)
73	if err != nil {
74		err = autorest.NewErrorWithError(err, "storsimple.BackupSchedulesClient", "CreateOrUpdate", result.Response(), "Failure sending request")
75		return
76	}
77
78	return
79}
80
81// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
82func (client BackupSchedulesClient) CreateOrUpdatePreparer(ctx context.Context, deviceName string, backupPolicyName string, backupScheduleName string, parameters BackupSchedule, resourceGroupName string, managerName string) (*http.Request, error) {
83	pathParameters := map[string]interface{}{
84		"backupPolicyName":   backupPolicyName,
85		"backupScheduleName": backupScheduleName,
86		"deviceName":         deviceName,
87		"managerName":        managerName,
88		"resourceGroupName":  resourceGroupName,
89		"subscriptionId":     client.SubscriptionID,
90	}
91
92	const APIVersion = "2017-06-01"
93	queryParameters := map[string]interface{}{
94		"api-version": APIVersion,
95	}
96
97	preparer := autorest.CreatePreparer(
98		autorest.AsContentType("application/json; charset=utf-8"),
99		autorest.AsPut(),
100		autorest.WithBaseURL(client.BaseURI),
101		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/backupPolicies/{backupPolicyName}/schedules/{backupScheduleName}", pathParameters),
102		autorest.WithJSON(parameters),
103		autorest.WithQueryParameters(queryParameters))
104	return preparer.Prepare((&http.Request{}).WithContext(ctx))
105}
106
107// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
108// http.Response Body if it receives an error.
109func (client BackupSchedulesClient) CreateOrUpdateSender(req *http.Request) (future BackupSchedulesCreateOrUpdateFuture, err error) {
110	sender := autorest.DecorateSender(client, azure.DoRetryWithRegistration(client.Client))
111	future.Future = azure.NewFuture(req)
112	future.req = req
113	_, err = future.Done(sender)
114	if err != nil {
115		return
116	}
117	err = autorest.Respond(future.Response(),
118		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted))
119	return
120}
121
122// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
123// closes the http.Response Body.
124func (client BackupSchedulesClient) CreateOrUpdateResponder(resp *http.Response) (result BackupSchedule, err error) {
125	err = autorest.Respond(
126		resp,
127		client.ByInspecting(),
128		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
129		autorest.ByUnmarshallingJSON(&result),
130		autorest.ByClosing())
131	result.Response = autorest.Response{Response: resp}
132	return
133}
134
135// Delete deletes the backup schedule.
136// Parameters:
137// deviceName - the device name
138// backupPolicyName - the backup policy name.
139// backupScheduleName - the name the backup schedule.
140// resourceGroupName - the resource group name
141// managerName - the manager name
142func (client BackupSchedulesClient) Delete(ctx context.Context, deviceName string, backupPolicyName string, backupScheduleName string, resourceGroupName string, managerName string) (result BackupSchedulesDeleteFuture, err error) {
143	if err := validation.Validate([]validation.Validation{
144		{TargetValue: managerName,
145			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
146				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
147		return result, validation.NewError("storsimple.BackupSchedulesClient", "Delete", err.Error())
148	}
149
150	req, err := client.DeletePreparer(ctx, deviceName, backupPolicyName, backupScheduleName, resourceGroupName, managerName)
151	if err != nil {
152		err = autorest.NewErrorWithError(err, "storsimple.BackupSchedulesClient", "Delete", nil, "Failure preparing request")
153		return
154	}
155
156	result, err = client.DeleteSender(req)
157	if err != nil {
158		err = autorest.NewErrorWithError(err, "storsimple.BackupSchedulesClient", "Delete", result.Response(), "Failure sending request")
159		return
160	}
161
162	return
163}
164
165// DeletePreparer prepares the Delete request.
166func (client BackupSchedulesClient) DeletePreparer(ctx context.Context, deviceName string, backupPolicyName string, backupScheduleName string, resourceGroupName string, managerName string) (*http.Request, error) {
167	pathParameters := map[string]interface{}{
168		"backupPolicyName":   backupPolicyName,
169		"backupScheduleName": backupScheduleName,
170		"deviceName":         deviceName,
171		"managerName":        managerName,
172		"resourceGroupName":  resourceGroupName,
173		"subscriptionId":     client.SubscriptionID,
174	}
175
176	const APIVersion = "2017-06-01"
177	queryParameters := map[string]interface{}{
178		"api-version": APIVersion,
179	}
180
181	preparer := autorest.CreatePreparer(
182		autorest.AsDelete(),
183		autorest.WithBaseURL(client.BaseURI),
184		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/backupPolicies/{backupPolicyName}/schedules/{backupScheduleName}", pathParameters),
185		autorest.WithQueryParameters(queryParameters))
186	return preparer.Prepare((&http.Request{}).WithContext(ctx))
187}
188
189// DeleteSender sends the Delete request. The method will close the
190// http.Response Body if it receives an error.
191func (client BackupSchedulesClient) DeleteSender(req *http.Request) (future BackupSchedulesDeleteFuture, err error) {
192	sender := autorest.DecorateSender(client, azure.DoRetryWithRegistration(client.Client))
193	future.Future = azure.NewFuture(req)
194	future.req = req
195	_, err = future.Done(sender)
196	if err != nil {
197		return
198	}
199	err = autorest.Respond(future.Response(),
200		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent))
201	return
202}
203
204// DeleteResponder handles the response to the Delete request. The method always
205// closes the http.Response Body.
206func (client BackupSchedulesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
207	err = autorest.Respond(
208		resp,
209		client.ByInspecting(),
210		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
211		autorest.ByClosing())
212	result.Response = resp
213	return
214}
215
216// Get gets the properties of the specified backup schedule name.
217// Parameters:
218// deviceName - the device name
219// backupPolicyName - the backup policy name.
220// backupScheduleName - the name of the backup schedule to be fetched
221// resourceGroupName - the resource group name
222// managerName - the manager name
223func (client BackupSchedulesClient) Get(ctx context.Context, deviceName string, backupPolicyName string, backupScheduleName string, resourceGroupName string, managerName string) (result BackupSchedule, err error) {
224	if err := validation.Validate([]validation.Validation{
225		{TargetValue: managerName,
226			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
227				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
228		return result, validation.NewError("storsimple.BackupSchedulesClient", "Get", err.Error())
229	}
230
231	req, err := client.GetPreparer(ctx, deviceName, backupPolicyName, backupScheduleName, resourceGroupName, managerName)
232	if err != nil {
233		err = autorest.NewErrorWithError(err, "storsimple.BackupSchedulesClient", "Get", nil, "Failure preparing request")
234		return
235	}
236
237	resp, err := client.GetSender(req)
238	if err != nil {
239		result.Response = autorest.Response{Response: resp}
240		err = autorest.NewErrorWithError(err, "storsimple.BackupSchedulesClient", "Get", resp, "Failure sending request")
241		return
242	}
243
244	result, err = client.GetResponder(resp)
245	if err != nil {
246		err = autorest.NewErrorWithError(err, "storsimple.BackupSchedulesClient", "Get", resp, "Failure responding to request")
247	}
248
249	return
250}
251
252// GetPreparer prepares the Get request.
253func (client BackupSchedulesClient) GetPreparer(ctx context.Context, deviceName string, backupPolicyName string, backupScheduleName string, resourceGroupName string, managerName string) (*http.Request, error) {
254	pathParameters := map[string]interface{}{
255		"backupPolicyName":   backupPolicyName,
256		"backupScheduleName": backupScheduleName,
257		"deviceName":         deviceName,
258		"managerName":        managerName,
259		"resourceGroupName":  resourceGroupName,
260		"subscriptionId":     client.SubscriptionID,
261	}
262
263	const APIVersion = "2017-06-01"
264	queryParameters := map[string]interface{}{
265		"api-version": APIVersion,
266	}
267
268	preparer := autorest.CreatePreparer(
269		autorest.AsGet(),
270		autorest.WithBaseURL(client.BaseURI),
271		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/backupPolicies/{backupPolicyName}/schedules/{backupScheduleName}", pathParameters),
272		autorest.WithQueryParameters(queryParameters))
273	return preparer.Prepare((&http.Request{}).WithContext(ctx))
274}
275
276// GetSender sends the Get request. The method will close the
277// http.Response Body if it receives an error.
278func (client BackupSchedulesClient) GetSender(req *http.Request) (*http.Response, error) {
279	return autorest.SendWithSender(client, req,
280		azure.DoRetryWithRegistration(client.Client))
281}
282
283// GetResponder handles the response to the Get request. The method always
284// closes the http.Response Body.
285func (client BackupSchedulesClient) GetResponder(resp *http.Response) (result BackupSchedule, err error) {
286	err = autorest.Respond(
287		resp,
288		client.ByInspecting(),
289		azure.WithErrorUnlessStatusCode(http.StatusOK),
290		autorest.ByUnmarshallingJSON(&result),
291		autorest.ByClosing())
292	result.Response = autorest.Response{Response: resp}
293	return
294}
295
296// ListByBackupPolicy gets all the backup schedules in a backup policy.
297// Parameters:
298// deviceName - the device name
299// backupPolicyName - the backup policy name.
300// resourceGroupName - the resource group name
301// managerName - the manager name
302func (client BackupSchedulesClient) ListByBackupPolicy(ctx context.Context, deviceName string, backupPolicyName string, resourceGroupName string, managerName string) (result BackupScheduleList, err error) {
303	if err := validation.Validate([]validation.Validation{
304		{TargetValue: managerName,
305			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
306				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
307		return result, validation.NewError("storsimple.BackupSchedulesClient", "ListByBackupPolicy", err.Error())
308	}
309
310	req, err := client.ListByBackupPolicyPreparer(ctx, deviceName, backupPolicyName, resourceGroupName, managerName)
311	if err != nil {
312		err = autorest.NewErrorWithError(err, "storsimple.BackupSchedulesClient", "ListByBackupPolicy", nil, "Failure preparing request")
313		return
314	}
315
316	resp, err := client.ListByBackupPolicySender(req)
317	if err != nil {
318		result.Response = autorest.Response{Response: resp}
319		err = autorest.NewErrorWithError(err, "storsimple.BackupSchedulesClient", "ListByBackupPolicy", resp, "Failure sending request")
320		return
321	}
322
323	result, err = client.ListByBackupPolicyResponder(resp)
324	if err != nil {
325		err = autorest.NewErrorWithError(err, "storsimple.BackupSchedulesClient", "ListByBackupPolicy", resp, "Failure responding to request")
326	}
327
328	return
329}
330
331// ListByBackupPolicyPreparer prepares the ListByBackupPolicy request.
332func (client BackupSchedulesClient) ListByBackupPolicyPreparer(ctx context.Context, deviceName string, backupPolicyName string, resourceGroupName string, managerName string) (*http.Request, error) {
333	pathParameters := map[string]interface{}{
334		"backupPolicyName":  backupPolicyName,
335		"deviceName":        deviceName,
336		"managerName":       managerName,
337		"resourceGroupName": resourceGroupName,
338		"subscriptionId":    client.SubscriptionID,
339	}
340
341	const APIVersion = "2017-06-01"
342	queryParameters := map[string]interface{}{
343		"api-version": APIVersion,
344	}
345
346	preparer := autorest.CreatePreparer(
347		autorest.AsGet(),
348		autorest.WithBaseURL(client.BaseURI),
349		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/backupPolicies/{backupPolicyName}/schedules", pathParameters),
350		autorest.WithQueryParameters(queryParameters))
351	return preparer.Prepare((&http.Request{}).WithContext(ctx))
352}
353
354// ListByBackupPolicySender sends the ListByBackupPolicy request. The method will close the
355// http.Response Body if it receives an error.
356func (client BackupSchedulesClient) ListByBackupPolicySender(req *http.Request) (*http.Response, error) {
357	return autorest.SendWithSender(client, req,
358		azure.DoRetryWithRegistration(client.Client))
359}
360
361// ListByBackupPolicyResponder handles the response to the ListByBackupPolicy request. The method always
362// closes the http.Response Body.
363func (client BackupSchedulesClient) ListByBackupPolicyResponder(resp *http.Response) (result BackupScheduleList, err error) {
364	err = autorest.Respond(
365		resp,
366		client.ByInspecting(),
367		azure.WithErrorUnlessStatusCode(http.StatusOK),
368		autorest.ByUnmarshallingJSON(&result),
369		autorest.ByClosing())
370	result.Response = autorest.Response{Response: resp}
371	return
372}
373