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	"net/http"
25)
26
27// ProtectionContainersClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
28type ProtectionContainersClient struct {
29	BaseClient
30}
31
32// NewProtectionContainersClient creates an instance of the ProtectionContainersClient client.
33func NewProtectionContainersClient(subscriptionID string) ProtectionContainersClient {
34	return NewProtectionContainersClientWithBaseURI(DefaultBaseURI, subscriptionID)
35}
36
37// NewProtectionContainersClientWithBaseURI creates an instance of the ProtectionContainersClient client.
38func NewProtectionContainersClientWithBaseURI(baseURI string, subscriptionID string) ProtectionContainersClient {
39	return ProtectionContainersClient{NewWithBaseURI(baseURI, subscriptionID)}
40}
41
42// Get gets details of the specific container registered to your Recovery Services vault.
43// Parameters:
44// vaultName - the name of the Recovery Services vault.
45// resourceGroupName - the name of the resource group associated with the Recovery Services vault.
46// fabricName - the fabric name associated with the container.
47// containerName - the container name used for this GET operation.
48func (client ProtectionContainersClient) Get(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string) (result ProtectionContainerResource, err error) {
49	req, err := client.GetPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName)
50	if err != nil {
51		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Get", nil, "Failure preparing request")
52		return
53	}
54
55	resp, err := client.GetSender(req)
56	if err != nil {
57		result.Response = autorest.Response{Response: resp}
58		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Get", resp, "Failure sending request")
59		return
60	}
61
62	result, err = client.GetResponder(resp)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Get", resp, "Failure responding to request")
65	}
66
67	return
68}
69
70// GetPreparer prepares the Get request.
71func (client ProtectionContainersClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string) (*http.Request, error) {
72	pathParameters := map[string]interface{}{
73		"containerName":     autorest.Encode("path", containerName),
74		"fabricName":        autorest.Encode("path", fabricName),
75		"resourceGroupName": autorest.Encode("path", resourceGroupName),
76		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
77		"vaultName":         autorest.Encode("path", vaultName),
78	}
79
80	const APIVersion = "2016-06-01"
81	queryParameters := map[string]interface{}{
82		"api-version": APIVersion,
83	}
84
85	preparer := autorest.CreatePreparer(
86		autorest.AsGet(),
87		autorest.WithBaseURL(client.BaseURI),
88		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}", pathParameters),
89		autorest.WithQueryParameters(queryParameters))
90	return preparer.Prepare((&http.Request{}).WithContext(ctx))
91}
92
93// GetSender sends the Get request. The method will close the
94// http.Response Body if it receives an error.
95func (client ProtectionContainersClient) GetSender(req *http.Request) (*http.Response, error) {
96	return autorest.SendWithSender(client, req,
97		azure.DoRetryWithRegistration(client.Client))
98}
99
100// GetResponder handles the response to the Get request. The method always
101// closes the http.Response Body.
102func (client ProtectionContainersClient) GetResponder(resp *http.Response) (result ProtectionContainerResource, err error) {
103	err = autorest.Respond(
104		resp,
105		client.ByInspecting(),
106		azure.WithErrorUnlessStatusCode(http.StatusOK),
107		autorest.ByUnmarshallingJSON(&result),
108		autorest.ByClosing())
109	result.Response = autorest.Response{Response: resp}
110	return
111}
112
113// List lists the containers registered to the Recovery Services vault.
114// Parameters:
115// vaultName - the name of the Recovery Services vault.
116// resourceGroupName - the name of the resource group associated with the Recovery Services vault.
117// filter - the following equation is used to sort or filter the containers registered to the vault.
118// providerType eq {AzureIaasVM, MAB, DPM, AzureBackupServer, AzureSql} and status eq {Unknown, NotRegistered,
119// Registered, Registering} and friendlyName eq {containername} and backupManagementType eq {AzureIaasVM, MAB,
120// DPM, AzureBackupServer, AzureSql}.
121func (client ProtectionContainersClient) List(ctx context.Context, vaultName string, resourceGroupName string, filter string) (result ProtectionContainerResourceList, err error) {
122	req, err := client.ListPreparer(ctx, vaultName, resourceGroupName, filter)
123	if err != nil {
124		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "List", nil, "Failure preparing request")
125		return
126	}
127
128	resp, err := client.ListSender(req)
129	if err != nil {
130		result.Response = autorest.Response{Response: resp}
131		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "List", resp, "Failure sending request")
132		return
133	}
134
135	result, err = client.ListResponder(resp)
136	if err != nil {
137		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "List", resp, "Failure responding to request")
138	}
139
140	return
141}
142
143// ListPreparer prepares the List request.
144func (client ProtectionContainersClient) ListPreparer(ctx context.Context, vaultName string, resourceGroupName string, filter string) (*http.Request, error) {
145	pathParameters := map[string]interface{}{
146		"resourceGroupName": autorest.Encode("path", resourceGroupName),
147		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
148		"vaultName":         autorest.Encode("path", vaultName),
149	}
150
151	const APIVersion = "2016-06-01"
152	queryParameters := map[string]interface{}{
153		"api-version": APIVersion,
154	}
155	if len(filter) > 0 {
156		queryParameters["$filter"] = autorest.Encode("query", filter)
157	}
158
159	preparer := autorest.CreatePreparer(
160		autorest.AsGet(),
161		autorest.WithBaseURL(client.BaseURI),
162		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupProtectionContainers", pathParameters),
163		autorest.WithQueryParameters(queryParameters))
164	return preparer.Prepare((&http.Request{}).WithContext(ctx))
165}
166
167// ListSender sends the List request. The method will close the
168// http.Response Body if it receives an error.
169func (client ProtectionContainersClient) ListSender(req *http.Request) (*http.Response, error) {
170	return autorest.SendWithSender(client, req,
171		azure.DoRetryWithRegistration(client.Client))
172}
173
174// ListResponder handles the response to the List request. The method always
175// closes the http.Response Body.
176func (client ProtectionContainersClient) ListResponder(resp *http.Response) (result ProtectionContainerResourceList, err error) {
177	err = autorest.Respond(
178		resp,
179		client.ByInspecting(),
180		azure.WithErrorUnlessStatusCode(http.StatusOK),
181		autorest.ByUnmarshallingJSON(&result),
182		autorest.ByClosing())
183	result.Response = autorest.Response{Response: resp}
184	return
185}
186
187// Refresh discovers the containers in the subscription that can be protected in a Recovery Services vault. This is an
188// asynchronous operation. To learn the status of the operation, use the GetRefreshOperationResult API.
189// Parameters:
190// vaultName - the name of the Recovery Services vault.
191// resourceGroupName - the name of the resource group associated with the Recovery Services vault.
192// fabricName - the fabric name associated with the container.
193func (client ProtectionContainersClient) Refresh(ctx context.Context, vaultName string, resourceGroupName string, fabricName string) (result autorest.Response, err error) {
194	req, err := client.RefreshPreparer(ctx, vaultName, resourceGroupName, fabricName)
195	if err != nil {
196		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Refresh", nil, "Failure preparing request")
197		return
198	}
199
200	resp, err := client.RefreshSender(req)
201	if err != nil {
202		result.Response = resp
203		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Refresh", resp, "Failure sending request")
204		return
205	}
206
207	result, err = client.RefreshResponder(resp)
208	if err != nil {
209		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Refresh", resp, "Failure responding to request")
210	}
211
212	return
213}
214
215// RefreshPreparer prepares the Refresh request.
216func (client ProtectionContainersClient) RefreshPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string) (*http.Request, error) {
217	pathParameters := map[string]interface{}{
218		"fabricName":        autorest.Encode("path", fabricName),
219		"resourceGroupName": autorest.Encode("path", resourceGroupName),
220		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
221		"vaultName":         autorest.Encode("path", vaultName),
222	}
223
224	const APIVersion = "2016-06-01"
225	queryParameters := map[string]interface{}{
226		"api-version": APIVersion,
227	}
228
229	preparer := autorest.CreatePreparer(
230		autorest.AsPost(),
231		autorest.WithBaseURL(client.BaseURI),
232		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/refreshContainers", pathParameters),
233		autorest.WithQueryParameters(queryParameters))
234	return preparer.Prepare((&http.Request{}).WithContext(ctx))
235}
236
237// RefreshSender sends the Refresh request. The method will close the
238// http.Response Body if it receives an error.
239func (client ProtectionContainersClient) RefreshSender(req *http.Request) (*http.Response, error) {
240	return autorest.SendWithSender(client, req,
241		azure.DoRetryWithRegistration(client.Client))
242}
243
244// RefreshResponder handles the response to the Refresh request. The method always
245// closes the http.Response Body.
246func (client ProtectionContainersClient) RefreshResponder(resp *http.Response) (result autorest.Response, err error) {
247	err = autorest.Respond(
248		resp,
249		client.ByInspecting(),
250		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
251		autorest.ByClosing())
252	result.Response = resp
253	return
254}
255
256// Unregister unregisters the given container from your Recovery Services vault.
257// Parameters:
258// resourceGroupName - the name of the resource group associated with the Recovery Services vault.
259// vaultName - the name of the Recovery Services vault.
260// identityName - name of the protection container to unregister.
261func (client ProtectionContainersClient) Unregister(ctx context.Context, resourceGroupName string, vaultName string, identityName string) (result autorest.Response, err error) {
262	req, err := client.UnregisterPreparer(ctx, resourceGroupName, vaultName, identityName)
263	if err != nil {
264		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Unregister", nil, "Failure preparing request")
265		return
266	}
267
268	resp, err := client.UnregisterSender(req)
269	if err != nil {
270		result.Response = resp
271		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Unregister", resp, "Failure sending request")
272		return
273	}
274
275	result, err = client.UnregisterResponder(resp)
276	if err != nil {
277		err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Unregister", resp, "Failure responding to request")
278	}
279
280	return
281}
282
283// UnregisterPreparer prepares the Unregister request.
284func (client ProtectionContainersClient) UnregisterPreparer(ctx context.Context, resourceGroupName string, vaultName string, identityName string) (*http.Request, error) {
285	pathParameters := map[string]interface{}{
286		"identityName":      autorest.Encode("path", identityName),
287		"resourceGroupName": autorest.Encode("path", resourceGroupName),
288		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
289		"vaultName":         autorest.Encode("path", vaultName),
290	}
291
292	const APIVersion = "2016-06-01"
293	queryParameters := map[string]interface{}{
294		"api-version": APIVersion,
295	}
296
297	preparer := autorest.CreatePreparer(
298		autorest.AsDelete(),
299		autorest.WithBaseURL(client.BaseURI),
300		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/registeredIdentities/{identityName}", pathParameters),
301		autorest.WithQueryParameters(queryParameters))
302	return preparer.Prepare((&http.Request{}).WithContext(ctx))
303}
304
305// UnregisterSender sends the Unregister request. The method will close the
306// http.Response Body if it receives an error.
307func (client ProtectionContainersClient) UnregisterSender(req *http.Request) (*http.Response, error) {
308	return autorest.SendWithSender(client, req,
309		azure.DoRetryWithRegistration(client.Client))
310}
311
312// UnregisterResponder handles the response to the Unregister request. The method always
313// closes the http.Response Body.
314func (client ProtectionContainersClient) UnregisterResponder(resp *http.Response) (result autorest.Response, err error) {
315	err = autorest.Respond(
316		resp,
317		client.ByInspecting(),
318		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
319		autorest.ByClosing())
320	result.Response = resp
321	return
322}
323