1package backup
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/tracing"
25	"net/http"
26)
27
28// ProtectionContainersClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
29type ProtectionContainersClient struct {
30	BaseClient
31}
32
33// NewProtectionContainersClient creates an instance of the ProtectionContainersClient client.
34func NewProtectionContainersClient(subscriptionID string) ProtectionContainersClient {
35	return NewProtectionContainersClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewProtectionContainersClientWithBaseURI creates an instance of the ProtectionContainersClient client using a custom
39// endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure
40// stack).
41func NewProtectionContainersClientWithBaseURI(baseURI string, subscriptionID string) ProtectionContainersClient {
42	return ProtectionContainersClient{NewWithBaseURI(baseURI, subscriptionID)}
43}
44
45// Get gets details of the specific container registered to your Recovery Services Vault.
46// Parameters:
47// vaultName - the name of the recovery services vault.
48// resourceGroupName - the name of the resource group where the recovery services vault is present.
49// fabricName - name of the fabric where the container belongs.
50// containerName - name of the container whose details need to be fetched.
51func (client ProtectionContainersClient) Get(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string) (result ProtectionContainerResource, err error) {
52	if tracing.IsEnabled() {
53		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionContainersClient.Get")
54		defer func() {
55			sc := -1
56			if result.Response.Response != nil {
57				sc = result.Response.Response.StatusCode
58			}
59			tracing.EndSpan(ctx, sc, err)
60		}()
61	}
62	req, err := client.GetPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Get", nil, "Failure preparing request")
65		return
66	}
67
68	resp, err := client.GetSender(req)
69	if err != nil {
70		result.Response = autorest.Response{Response: resp}
71		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Get", resp, "Failure sending request")
72		return
73	}
74
75	result, err = client.GetResponder(resp)
76	if err != nil {
77		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Get", resp, "Failure responding to request")
78	}
79
80	return
81}
82
83// GetPreparer prepares the Get request.
84func (client ProtectionContainersClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string) (*http.Request, error) {
85	pathParameters := map[string]interface{}{
86		"containerName":     autorest.Encode("path", containerName),
87		"fabricName":        autorest.Encode("path", fabricName),
88		"resourceGroupName": autorest.Encode("path", resourceGroupName),
89		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
90		"vaultName":         autorest.Encode("path", vaultName),
91	}
92
93	const APIVersion = "2016-12-01"
94	queryParameters := map[string]interface{}{
95		"api-version": APIVersion,
96	}
97
98	preparer := autorest.CreatePreparer(
99		autorest.AsGet(),
100		autorest.WithBaseURL(client.BaseURI),
101		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}", pathParameters),
102		autorest.WithQueryParameters(queryParameters))
103	return preparer.Prepare((&http.Request{}).WithContext(ctx))
104}
105
106// GetSender sends the Get request. The method will close the
107// http.Response Body if it receives an error.
108func (client ProtectionContainersClient) GetSender(req *http.Request) (*http.Response, error) {
109	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
110}
111
112// GetResponder handles the response to the Get request. The method always
113// closes the http.Response Body.
114func (client ProtectionContainersClient) GetResponder(resp *http.Response) (result ProtectionContainerResource, err error) {
115	err = autorest.Respond(
116		resp,
117		client.ByInspecting(),
118		azure.WithErrorUnlessStatusCode(http.StatusOK),
119		autorest.ByUnmarshallingJSON(&result),
120		autorest.ByClosing())
121	result.Response = autorest.Response{Response: resp}
122	return
123}
124
125// Inquire this is an async operation and the results should be tracked using location header or Azure-async-url.
126// Parameters:
127// vaultName - the name of the recovery services vault.
128// resourceGroupName - the name of the resource group where the recovery services vault is present.
129// fabricName - fabric Name associated with the container.
130// containerName - name of the container in which inquiry needs to be triggered.
131// filter - oData filter options.
132func (client ProtectionContainersClient) Inquire(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, filter string) (result autorest.Response, err error) {
133	if tracing.IsEnabled() {
134		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionContainersClient.Inquire")
135		defer func() {
136			sc := -1
137			if result.Response != nil {
138				sc = result.Response.StatusCode
139			}
140			tracing.EndSpan(ctx, sc, err)
141		}()
142	}
143	req, err := client.InquirePreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, filter)
144	if err != nil {
145		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Inquire", nil, "Failure preparing request")
146		return
147	}
148
149	resp, err := client.InquireSender(req)
150	if err != nil {
151		result.Response = resp
152		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Inquire", resp, "Failure sending request")
153		return
154	}
155
156	result, err = client.InquireResponder(resp)
157	if err != nil {
158		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Inquire", resp, "Failure responding to request")
159	}
160
161	return
162}
163
164// InquirePreparer prepares the Inquire request.
165func (client ProtectionContainersClient) InquirePreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, filter string) (*http.Request, error) {
166	pathParameters := map[string]interface{}{
167		"containerName":     autorest.Encode("path", containerName),
168		"fabricName":        autorest.Encode("path", fabricName),
169		"resourceGroupName": autorest.Encode("path", resourceGroupName),
170		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
171		"vaultName":         autorest.Encode("path", vaultName),
172	}
173
174	const APIVersion = "2016-12-01"
175	queryParameters := map[string]interface{}{
176		"api-version": APIVersion,
177	}
178	if len(filter) > 0 {
179		queryParameters["$filter"] = autorest.Encode("query", filter)
180	}
181
182	preparer := autorest.CreatePreparer(
183		autorest.AsPost(),
184		autorest.WithBaseURL(client.BaseURI),
185		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/inquire", pathParameters),
186		autorest.WithQueryParameters(queryParameters))
187	return preparer.Prepare((&http.Request{}).WithContext(ctx))
188}
189
190// InquireSender sends the Inquire request. The method will close the
191// http.Response Body if it receives an error.
192func (client ProtectionContainersClient) InquireSender(req *http.Request) (*http.Response, error) {
193	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
194}
195
196// InquireResponder handles the response to the Inquire request. The method always
197// closes the http.Response Body.
198func (client ProtectionContainersClient) InquireResponder(resp *http.Response) (result autorest.Response, err error) {
199	err = autorest.Respond(
200		resp,
201		client.ByInspecting(),
202		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
203		autorest.ByClosing())
204	result.Response = resp
205	return
206}
207
208// Refresh discovers all the containers in the subscription that can be backed up to Recovery Services Vault. This is
209// an
210// asynchronous operation. To know the status of the operation, call GetRefreshOperationResult API.
211// Parameters:
212// vaultName - the name of the recovery services vault.
213// resourceGroupName - the name of the resource group where the recovery services vault is present.
214// fabricName - fabric name associated the container.
215// filter - oData filter options.
216func (client ProtectionContainersClient) Refresh(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, filter string) (result autorest.Response, err error) {
217	if tracing.IsEnabled() {
218		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionContainersClient.Refresh")
219		defer func() {
220			sc := -1
221			if result.Response != nil {
222				sc = result.Response.StatusCode
223			}
224			tracing.EndSpan(ctx, sc, err)
225		}()
226	}
227	req, err := client.RefreshPreparer(ctx, vaultName, resourceGroupName, fabricName, filter)
228	if err != nil {
229		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Refresh", nil, "Failure preparing request")
230		return
231	}
232
233	resp, err := client.RefreshSender(req)
234	if err != nil {
235		result.Response = resp
236		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Refresh", resp, "Failure sending request")
237		return
238	}
239
240	result, err = client.RefreshResponder(resp)
241	if err != nil {
242		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Refresh", resp, "Failure responding to request")
243	}
244
245	return
246}
247
248// RefreshPreparer prepares the Refresh request.
249func (client ProtectionContainersClient) RefreshPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, filter string) (*http.Request, error) {
250	pathParameters := map[string]interface{}{
251		"fabricName":        autorest.Encode("path", fabricName),
252		"resourceGroupName": autorest.Encode("path", resourceGroupName),
253		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
254		"vaultName":         autorest.Encode("path", vaultName),
255	}
256
257	const APIVersion = "2016-12-01"
258	queryParameters := map[string]interface{}{
259		"api-version": APIVersion,
260	}
261	if len(filter) > 0 {
262		queryParameters["$filter"] = autorest.Encode("query", filter)
263	}
264
265	preparer := autorest.CreatePreparer(
266		autorest.AsPost(),
267		autorest.WithBaseURL(client.BaseURI),
268		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/refreshContainers", pathParameters),
269		autorest.WithQueryParameters(queryParameters))
270	return preparer.Prepare((&http.Request{}).WithContext(ctx))
271}
272
273// RefreshSender sends the Refresh request. The method will close the
274// http.Response Body if it receives an error.
275func (client ProtectionContainersClient) RefreshSender(req *http.Request) (*http.Response, error) {
276	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
277}
278
279// RefreshResponder handles the response to the Refresh request. The method always
280// closes the http.Response Body.
281func (client ProtectionContainersClient) RefreshResponder(resp *http.Response) (result autorest.Response, err error) {
282	err = autorest.Respond(
283		resp,
284		client.ByInspecting(),
285		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
286		autorest.ByClosing())
287	result.Response = resp
288	return
289}
290
291// Register registers the container with Recovery Services vault.
292// This is an asynchronous operation. To track the operation status, use location header to call get latest status of
293// the operation.
294// Parameters:
295// vaultName - the name of the recovery services vault.
296// resourceGroupName - the name of the resource group where the recovery services vault is present.
297// fabricName - fabric name associated with the container.
298// containerName - name of the container to be registered.
299// parameters - request body for operation
300func (client ProtectionContainersClient) Register(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, parameters ProtectionContainerResource) (result ProtectionContainerResource, err error) {
301	if tracing.IsEnabled() {
302		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionContainersClient.Register")
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.RegisterPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, parameters)
312	if err != nil {
313		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Register", nil, "Failure preparing request")
314		return
315	}
316
317	resp, err := client.RegisterSender(req)
318	if err != nil {
319		result.Response = autorest.Response{Response: resp}
320		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Register", resp, "Failure sending request")
321		return
322	}
323
324	result, err = client.RegisterResponder(resp)
325	if err != nil {
326		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Register", resp, "Failure responding to request")
327	}
328
329	return
330}
331
332// RegisterPreparer prepares the Register request.
333func (client ProtectionContainersClient) RegisterPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, parameters ProtectionContainerResource) (*http.Request, error) {
334	pathParameters := map[string]interface{}{
335		"containerName":     autorest.Encode("path", containerName),
336		"fabricName":        autorest.Encode("path", fabricName),
337		"resourceGroupName": autorest.Encode("path", resourceGroupName),
338		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
339		"vaultName":         autorest.Encode("path", vaultName),
340	}
341
342	const APIVersion = "2016-12-01"
343	queryParameters := map[string]interface{}{
344		"api-version": APIVersion,
345	}
346
347	preparer := autorest.CreatePreparer(
348		autorest.AsContentType("application/json; charset=utf-8"),
349		autorest.AsPut(),
350		autorest.WithBaseURL(client.BaseURI),
351		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}", pathParameters),
352		autorest.WithJSON(parameters),
353		autorest.WithQueryParameters(queryParameters))
354	return preparer.Prepare((&http.Request{}).WithContext(ctx))
355}
356
357// RegisterSender sends the Register request. The method will close the
358// http.Response Body if it receives an error.
359func (client ProtectionContainersClient) RegisterSender(req *http.Request) (*http.Response, error) {
360	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
361}
362
363// RegisterResponder handles the response to the Register request. The method always
364// closes the http.Response Body.
365func (client ProtectionContainersClient) RegisterResponder(resp *http.Response) (result ProtectionContainerResource, err error) {
366	err = autorest.Respond(
367		resp,
368		client.ByInspecting(),
369		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
370		autorest.ByUnmarshallingJSON(&result),
371		autorest.ByClosing())
372	result.Response = autorest.Response{Response: resp}
373	return
374}
375
376// Unregister unregisters the given container from your Recovery Services Vault. This is an asynchronous operation. To
377// determine
378// whether the backend service has finished processing the request, call Get Container Operation Result API.
379// Parameters:
380// vaultName - the name of the recovery services vault.
381// resourceGroupName - the name of the resource group where the recovery services vault is present.
382// fabricName - name of the fabric where the container belongs.
383// containerName - name of the container which needs to be unregistered from the Recovery Services Vault.
384func (client ProtectionContainersClient) Unregister(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string) (result autorest.Response, err error) {
385	if tracing.IsEnabled() {
386		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionContainersClient.Unregister")
387		defer func() {
388			sc := -1
389			if result.Response != nil {
390				sc = result.Response.StatusCode
391			}
392			tracing.EndSpan(ctx, sc, err)
393		}()
394	}
395	req, err := client.UnregisterPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName)
396	if err != nil {
397		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Unregister", nil, "Failure preparing request")
398		return
399	}
400
401	resp, err := client.UnregisterSender(req)
402	if err != nil {
403		result.Response = resp
404		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Unregister", resp, "Failure sending request")
405		return
406	}
407
408	result, err = client.UnregisterResponder(resp)
409	if err != nil {
410		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Unregister", resp, "Failure responding to request")
411	}
412
413	return
414}
415
416// UnregisterPreparer prepares the Unregister request.
417func (client ProtectionContainersClient) UnregisterPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string) (*http.Request, error) {
418	pathParameters := map[string]interface{}{
419		"containerName":     autorest.Encode("path", containerName),
420		"fabricName":        autorest.Encode("path", fabricName),
421		"resourceGroupName": autorest.Encode("path", resourceGroupName),
422		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
423		"vaultName":         autorest.Encode("path", vaultName),
424	}
425
426	const APIVersion = "2016-12-01"
427	queryParameters := map[string]interface{}{
428		"api-version": APIVersion,
429	}
430
431	preparer := autorest.CreatePreparer(
432		autorest.AsDelete(),
433		autorest.WithBaseURL(client.BaseURI),
434		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}", pathParameters),
435		autorest.WithQueryParameters(queryParameters))
436	return preparer.Prepare((&http.Request{}).WithContext(ctx))
437}
438
439// UnregisterSender sends the Unregister request. The method will close the
440// http.Response Body if it receives an error.
441func (client ProtectionContainersClient) UnregisterSender(req *http.Request) (*http.Response, error) {
442	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
443}
444
445// UnregisterResponder handles the response to the Unregister request. The method always
446// closes the http.Response Body.
447func (client ProtectionContainersClient) UnregisterResponder(resp *http.Response) (result autorest.Response, err error) {
448	err = autorest.Respond(
449		resp,
450		client.ByInspecting(),
451		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
452		autorest.ByClosing())
453	result.Response = resp
454	return
455}
456