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