1package storsimple
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// BackupPoliciesClient is the client for the BackupPolicies methods of the Storsimple service.
19type BackupPoliciesClient struct {
20	BaseClient
21}
22
23// NewBackupPoliciesClient creates an instance of the BackupPoliciesClient client.
24func NewBackupPoliciesClient(subscriptionID string) BackupPoliciesClient {
25	return NewBackupPoliciesClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewBackupPoliciesClientWithBaseURI creates an instance of the BackupPoliciesClient 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 NewBackupPoliciesClientWithBaseURI(baseURI string, subscriptionID string) BackupPoliciesClient {
31	return BackupPoliciesClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// BackupNow backup the backup policy now.
35// Parameters:
36// deviceName - the device name
37// backupPolicyName - the backup policy name.
38// backupType - the backup Type. This can be cloudSnapshot or localSnapshot.
39// resourceGroupName - the resource group name
40// managerName - the manager name
41func (client BackupPoliciesClient) BackupNow(ctx context.Context, deviceName string, backupPolicyName string, backupType string, resourceGroupName string, managerName string) (result BackupPoliciesBackupNowFuture, err error) {
42	if tracing.IsEnabled() {
43		ctx = tracing.StartSpan(ctx, fqdn+"/BackupPoliciesClient.BackupNow")
44		defer func() {
45			sc := -1
46			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
47				sc = result.FutureAPI.Response().StatusCode
48			}
49			tracing.EndSpan(ctx, sc, err)
50		}()
51	}
52	if err := validation.Validate([]validation.Validation{
53		{TargetValue: managerName,
54			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
55				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
56		return result, validation.NewError("storsimple.BackupPoliciesClient", "BackupNow", err.Error())
57	}
58
59	req, err := client.BackupNowPreparer(ctx, deviceName, backupPolicyName, backupType, resourceGroupName, managerName)
60	if err != nil {
61		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "BackupNow", nil, "Failure preparing request")
62		return
63	}
64
65	result, err = client.BackupNowSender(req)
66	if err != nil {
67		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "BackupNow", nil, "Failure sending request")
68		return
69	}
70
71	return
72}
73
74// BackupNowPreparer prepares the BackupNow request.
75func (client BackupPoliciesClient) BackupNowPreparer(ctx context.Context, deviceName string, backupPolicyName string, backupType string, resourceGroupName string, managerName string) (*http.Request, error) {
76	pathParameters := map[string]interface{}{
77		"backupPolicyName":  backupPolicyName,
78		"deviceName":        deviceName,
79		"managerName":       managerName,
80		"resourceGroupName": resourceGroupName,
81		"subscriptionId":    client.SubscriptionID,
82	}
83
84	const APIVersion = "2017-06-01"
85	queryParameters := map[string]interface{}{
86		"api-version": APIVersion,
87		"backupType":  backupType,
88	}
89
90	preparer := autorest.CreatePreparer(
91		autorest.AsPost(),
92		autorest.WithBaseURL(client.BaseURI),
93		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/backupPolicies/{backupPolicyName}/backup", pathParameters),
94		autorest.WithQueryParameters(queryParameters))
95	return preparer.Prepare((&http.Request{}).WithContext(ctx))
96}
97
98// BackupNowSender sends the BackupNow request. The method will close the
99// http.Response Body if it receives an error.
100func (client BackupPoliciesClient) BackupNowSender(req *http.Request) (future BackupPoliciesBackupNowFuture, err error) {
101	var resp *http.Response
102	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
103	if err != nil {
104		return
105	}
106	var azf azure.Future
107	azf, err = azure.NewFutureFromResponse(resp)
108	future.FutureAPI = &azf
109	future.Result = future.result
110	return
111}
112
113// BackupNowResponder handles the response to the BackupNow request. The method always
114// closes the http.Response Body.
115func (client BackupPoliciesClient) BackupNowResponder(resp *http.Response) (result autorest.Response, err error) {
116	err = autorest.Respond(
117		resp,
118		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
119		autorest.ByClosing())
120	result.Response = resp
121	return
122}
123
124// CreateOrUpdate creates or updates the backup policy.
125// Parameters:
126// deviceName - the device name
127// backupPolicyName - the name of the backup policy to be created/updated.
128// parameters - the backup policy.
129// resourceGroupName - the resource group name
130// managerName - the manager name
131func (client BackupPoliciesClient) CreateOrUpdate(ctx context.Context, deviceName string, backupPolicyName string, parameters BackupPolicy, resourceGroupName string, managerName string) (result BackupPoliciesCreateOrUpdateFuture, err error) {
132	if tracing.IsEnabled() {
133		ctx = tracing.StartSpan(ctx, fqdn+"/BackupPoliciesClient.CreateOrUpdate")
134		defer func() {
135			sc := -1
136			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
137				sc = result.FutureAPI.Response().StatusCode
138			}
139			tracing.EndSpan(ctx, sc, err)
140		}()
141	}
142	if err := validation.Validate([]validation.Validation{
143		{TargetValue: parameters,
144			Constraints: []validation.Constraint{{Target: "parameters.BackupPolicyProperties", Name: validation.Null, Rule: true,
145				Chain: []validation.Constraint{{Target: "parameters.BackupPolicyProperties.VolumeIds", Name: validation.Null, Rule: true, Chain: nil}}}}},
146		{TargetValue: managerName,
147			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
148				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
149		return result, validation.NewError("storsimple.BackupPoliciesClient", "CreateOrUpdate", err.Error())
150	}
151
152	req, err := client.CreateOrUpdatePreparer(ctx, deviceName, backupPolicyName, parameters, resourceGroupName, managerName)
153	if err != nil {
154		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "CreateOrUpdate", nil, "Failure preparing request")
155		return
156	}
157
158	result, err = client.CreateOrUpdateSender(req)
159	if err != nil {
160		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "CreateOrUpdate", nil, "Failure sending request")
161		return
162	}
163
164	return
165}
166
167// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
168func (client BackupPoliciesClient) CreateOrUpdatePreparer(ctx context.Context, deviceName string, backupPolicyName string, parameters BackupPolicy, resourceGroupName string, managerName string) (*http.Request, error) {
169	pathParameters := map[string]interface{}{
170		"backupPolicyName":  backupPolicyName,
171		"deviceName":        deviceName,
172		"managerName":       managerName,
173		"resourceGroupName": resourceGroupName,
174		"subscriptionId":    client.SubscriptionID,
175	}
176
177	const APIVersion = "2017-06-01"
178	queryParameters := map[string]interface{}{
179		"api-version": APIVersion,
180	}
181
182	preparer := autorest.CreatePreparer(
183		autorest.AsContentType("application/json; charset=utf-8"),
184		autorest.AsPut(),
185		autorest.WithBaseURL(client.BaseURI),
186		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/backupPolicies/{backupPolicyName}", pathParameters),
187		autorest.WithJSON(parameters),
188		autorest.WithQueryParameters(queryParameters))
189	return preparer.Prepare((&http.Request{}).WithContext(ctx))
190}
191
192// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
193// http.Response Body if it receives an error.
194func (client BackupPoliciesClient) CreateOrUpdateSender(req *http.Request) (future BackupPoliciesCreateOrUpdateFuture, err error) {
195	var resp *http.Response
196	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
197	if err != nil {
198		return
199	}
200	var azf azure.Future
201	azf, err = azure.NewFutureFromResponse(resp)
202	future.FutureAPI = &azf
203	future.Result = future.result
204	return
205}
206
207// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
208// closes the http.Response Body.
209func (client BackupPoliciesClient) CreateOrUpdateResponder(resp *http.Response) (result BackupPolicy, err error) {
210	err = autorest.Respond(
211		resp,
212		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
213		autorest.ByUnmarshallingJSON(&result),
214		autorest.ByClosing())
215	result.Response = autorest.Response{Response: resp}
216	return
217}
218
219// Delete deletes the backup policy.
220// Parameters:
221// deviceName - the device name
222// backupPolicyName - the name of the backup policy.
223// resourceGroupName - the resource group name
224// managerName - the manager name
225func (client BackupPoliciesClient) Delete(ctx context.Context, deviceName string, backupPolicyName string, resourceGroupName string, managerName string) (result BackupPoliciesDeleteFuture, err error) {
226	if tracing.IsEnabled() {
227		ctx = tracing.StartSpan(ctx, fqdn+"/BackupPoliciesClient.Delete")
228		defer func() {
229			sc := -1
230			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
231				sc = result.FutureAPI.Response().StatusCode
232			}
233			tracing.EndSpan(ctx, sc, err)
234		}()
235	}
236	if err := validation.Validate([]validation.Validation{
237		{TargetValue: managerName,
238			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
239				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
240		return result, validation.NewError("storsimple.BackupPoliciesClient", "Delete", err.Error())
241	}
242
243	req, err := client.DeletePreparer(ctx, deviceName, backupPolicyName, resourceGroupName, managerName)
244	if err != nil {
245		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "Delete", nil, "Failure preparing request")
246		return
247	}
248
249	result, err = client.DeleteSender(req)
250	if err != nil {
251		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "Delete", nil, "Failure sending request")
252		return
253	}
254
255	return
256}
257
258// DeletePreparer prepares the Delete request.
259func (client BackupPoliciesClient) DeletePreparer(ctx context.Context, deviceName string, backupPolicyName string, resourceGroupName string, managerName string) (*http.Request, error) {
260	pathParameters := map[string]interface{}{
261		"backupPolicyName":  backupPolicyName,
262		"deviceName":        deviceName,
263		"managerName":       managerName,
264		"resourceGroupName": resourceGroupName,
265		"subscriptionId":    client.SubscriptionID,
266	}
267
268	const APIVersion = "2017-06-01"
269	queryParameters := map[string]interface{}{
270		"api-version": APIVersion,
271	}
272
273	preparer := autorest.CreatePreparer(
274		autorest.AsDelete(),
275		autorest.WithBaseURL(client.BaseURI),
276		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/backupPolicies/{backupPolicyName}", pathParameters),
277		autorest.WithQueryParameters(queryParameters))
278	return preparer.Prepare((&http.Request{}).WithContext(ctx))
279}
280
281// DeleteSender sends the Delete request. The method will close the
282// http.Response Body if it receives an error.
283func (client BackupPoliciesClient) DeleteSender(req *http.Request) (future BackupPoliciesDeleteFuture, err error) {
284	var resp *http.Response
285	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
286	if err != nil {
287		return
288	}
289	var azf azure.Future
290	azf, err = azure.NewFutureFromResponse(resp)
291	future.FutureAPI = &azf
292	future.Result = future.result
293	return
294}
295
296// DeleteResponder handles the response to the Delete request. The method always
297// closes the http.Response Body.
298func (client BackupPoliciesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
299	err = autorest.Respond(
300		resp,
301		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
302		autorest.ByClosing())
303	result.Response = resp
304	return
305}
306
307// Get gets the properties of the specified backup policy name.
308// Parameters:
309// deviceName - the device name
310// backupPolicyName - the name of backup policy to be fetched.
311// resourceGroupName - the resource group name
312// managerName - the manager name
313func (client BackupPoliciesClient) Get(ctx context.Context, deviceName string, backupPolicyName string, resourceGroupName string, managerName string) (result BackupPolicy, err error) {
314	if tracing.IsEnabled() {
315		ctx = tracing.StartSpan(ctx, fqdn+"/BackupPoliciesClient.Get")
316		defer func() {
317			sc := -1
318			if result.Response.Response != nil {
319				sc = result.Response.Response.StatusCode
320			}
321			tracing.EndSpan(ctx, sc, err)
322		}()
323	}
324	if err := validation.Validate([]validation.Validation{
325		{TargetValue: managerName,
326			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
327				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
328		return result, validation.NewError("storsimple.BackupPoliciesClient", "Get", err.Error())
329	}
330
331	req, err := client.GetPreparer(ctx, deviceName, backupPolicyName, resourceGroupName, managerName)
332	if err != nil {
333		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "Get", nil, "Failure preparing request")
334		return
335	}
336
337	resp, err := client.GetSender(req)
338	if err != nil {
339		result.Response = autorest.Response{Response: resp}
340		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "Get", resp, "Failure sending request")
341		return
342	}
343
344	result, err = client.GetResponder(resp)
345	if err != nil {
346		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "Get", resp, "Failure responding to request")
347		return
348	}
349
350	return
351}
352
353// GetPreparer prepares the Get request.
354func (client BackupPoliciesClient) GetPreparer(ctx context.Context, deviceName string, backupPolicyName string, resourceGroupName string, managerName string) (*http.Request, error) {
355	pathParameters := map[string]interface{}{
356		"backupPolicyName":  backupPolicyName,
357		"deviceName":        deviceName,
358		"managerName":       managerName,
359		"resourceGroupName": resourceGroupName,
360		"subscriptionId":    client.SubscriptionID,
361	}
362
363	const APIVersion = "2017-06-01"
364	queryParameters := map[string]interface{}{
365		"api-version": APIVersion,
366	}
367
368	preparer := autorest.CreatePreparer(
369		autorest.AsGet(),
370		autorest.WithBaseURL(client.BaseURI),
371		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/backupPolicies/{backupPolicyName}", pathParameters),
372		autorest.WithQueryParameters(queryParameters))
373	return preparer.Prepare((&http.Request{}).WithContext(ctx))
374}
375
376// GetSender sends the Get request. The method will close the
377// http.Response Body if it receives an error.
378func (client BackupPoliciesClient) GetSender(req *http.Request) (*http.Response, error) {
379	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
380}
381
382// GetResponder handles the response to the Get request. The method always
383// closes the http.Response Body.
384func (client BackupPoliciesClient) GetResponder(resp *http.Response) (result BackupPolicy, err error) {
385	err = autorest.Respond(
386		resp,
387		azure.WithErrorUnlessStatusCode(http.StatusOK),
388		autorest.ByUnmarshallingJSON(&result),
389		autorest.ByClosing())
390	result.Response = autorest.Response{Response: resp}
391	return
392}
393
394// ListByDevice gets all the backup policies in a device.
395// Parameters:
396// deviceName - the device name
397// resourceGroupName - the resource group name
398// managerName - the manager name
399func (client BackupPoliciesClient) ListByDevice(ctx context.Context, deviceName string, resourceGroupName string, managerName string) (result BackupPolicyList, err error) {
400	if tracing.IsEnabled() {
401		ctx = tracing.StartSpan(ctx, fqdn+"/BackupPoliciesClient.ListByDevice")
402		defer func() {
403			sc := -1
404			if result.Response.Response != nil {
405				sc = result.Response.Response.StatusCode
406			}
407			tracing.EndSpan(ctx, sc, err)
408		}()
409	}
410	if err := validation.Validate([]validation.Validation{
411		{TargetValue: managerName,
412			Constraints: []validation.Constraint{{Target: "managerName", Name: validation.MaxLength, Rule: 50, Chain: nil},
413				{Target: "managerName", Name: validation.MinLength, Rule: 2, Chain: nil}}}}); err != nil {
414		return result, validation.NewError("storsimple.BackupPoliciesClient", "ListByDevice", err.Error())
415	}
416
417	req, err := client.ListByDevicePreparer(ctx, deviceName, resourceGroupName, managerName)
418	if err != nil {
419		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "ListByDevice", nil, "Failure preparing request")
420		return
421	}
422
423	resp, err := client.ListByDeviceSender(req)
424	if err != nil {
425		result.Response = autorest.Response{Response: resp}
426		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "ListByDevice", resp, "Failure sending request")
427		return
428	}
429
430	result, err = client.ListByDeviceResponder(resp)
431	if err != nil {
432		err = autorest.NewErrorWithError(err, "storsimple.BackupPoliciesClient", "ListByDevice", resp, "Failure responding to request")
433		return
434	}
435
436	return
437}
438
439// ListByDevicePreparer prepares the ListByDevice request.
440func (client BackupPoliciesClient) ListByDevicePreparer(ctx context.Context, deviceName string, resourceGroupName string, managerName string) (*http.Request, error) {
441	pathParameters := map[string]interface{}{
442		"deviceName":        deviceName,
443		"managerName":       managerName,
444		"resourceGroupName": resourceGroupName,
445		"subscriptionId":    client.SubscriptionID,
446	}
447
448	const APIVersion = "2017-06-01"
449	queryParameters := map[string]interface{}{
450		"api-version": APIVersion,
451	}
452
453	preparer := autorest.CreatePreparer(
454		autorest.AsGet(),
455		autorest.WithBaseURL(client.BaseURI),
456		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorSimple/managers/{managerName}/devices/{deviceName}/backupPolicies", pathParameters),
457		autorest.WithQueryParameters(queryParameters))
458	return preparer.Prepare((&http.Request{}).WithContext(ctx))
459}
460
461// ListByDeviceSender sends the ListByDevice request. The method will close the
462// http.Response Body if it receives an error.
463func (client BackupPoliciesClient) ListByDeviceSender(req *http.Request) (*http.Response, error) {
464	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
465}
466
467// ListByDeviceResponder handles the response to the ListByDevice request. The method always
468// closes the http.Response Body.
469func (client BackupPoliciesClient) ListByDeviceResponder(resp *http.Response) (result BackupPolicyList, err error) {
470	err = autorest.Respond(
471		resp,
472		azure.WithErrorUnlessStatusCode(http.StatusOK),
473		autorest.ByUnmarshallingJSON(&result),
474		autorest.ByClosing())
475	result.Response = autorest.Response{Response: resp}
476	return
477}
478