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 where the recovery services vault is present. 38// fabricName - name of the fabric where the container belongs. 39// containerName - name of the container whose details need to be fetched. 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 = "2021-01-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// Inquire this is an async operation and the results should be tracked using location header or Azure-async-url. 115// Parameters: 116// vaultName - the name of the recovery services vault. 117// resourceGroupName - the name of the resource group where the recovery services vault is present. 118// fabricName - fabric Name associated with the container. 119// containerName - name of the container in which inquiry needs to be triggered. 120// filter - oData filter options. 121func (client ProtectionContainersClient) Inquire(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, filter string) (result autorest.Response, err error) { 122 if tracing.IsEnabled() { 123 ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionContainersClient.Inquire") 124 defer func() { 125 sc := -1 126 if result.Response != nil { 127 sc = result.Response.StatusCode 128 } 129 tracing.EndSpan(ctx, sc, err) 130 }() 131 } 132 req, err := client.InquirePreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, filter) 133 if err != nil { 134 err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Inquire", nil, "Failure preparing request") 135 return 136 } 137 138 resp, err := client.InquireSender(req) 139 if err != nil { 140 result.Response = resp 141 err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Inquire", resp, "Failure sending request") 142 return 143 } 144 145 result, err = client.InquireResponder(resp) 146 if err != nil { 147 err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Inquire", resp, "Failure responding to request") 148 return 149 } 150 151 return 152} 153 154// InquirePreparer prepares the Inquire request. 155func (client ProtectionContainersClient) InquirePreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, filter string) (*http.Request, error) { 156 pathParameters := map[string]interface{}{ 157 "containerName": autorest.Encode("path", containerName), 158 "fabricName": autorest.Encode("path", fabricName), 159 "resourceGroupName": autorest.Encode("path", resourceGroupName), 160 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 161 "vaultName": autorest.Encode("path", vaultName), 162 } 163 164 const APIVersion = "2021-01-01" 165 queryParameters := map[string]interface{}{ 166 "api-version": APIVersion, 167 } 168 if len(filter) > 0 { 169 queryParameters["$filter"] = autorest.Encode("query", filter) 170 } 171 172 preparer := autorest.CreatePreparer( 173 autorest.AsPost(), 174 autorest.WithBaseURL(client.BaseURI), 175 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/inquire", pathParameters), 176 autorest.WithQueryParameters(queryParameters)) 177 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 178} 179 180// InquireSender sends the Inquire request. The method will close the 181// http.Response Body if it receives an error. 182func (client ProtectionContainersClient) InquireSender(req *http.Request) (*http.Response, error) { 183 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 184} 185 186// InquireResponder handles the response to the Inquire request. The method always 187// closes the http.Response Body. 188func (client ProtectionContainersClient) InquireResponder(resp *http.Response) (result autorest.Response, err error) { 189 err = autorest.Respond( 190 resp, 191 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 192 autorest.ByClosing()) 193 result.Response = resp 194 return 195} 196 197// Refresh discovers all the containers in the subscription that can be backed up to Recovery Services Vault. This is 198// an 199// asynchronous operation. To know the status of the operation, call GetRefreshOperationResult API. 200// Parameters: 201// vaultName - the name of the recovery services vault. 202// resourceGroupName - the name of the resource group where the recovery services vault is present. 203// fabricName - fabric name associated the container. 204// filter - oData filter options. 205func (client ProtectionContainersClient) Refresh(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, filter string) (result autorest.Response, err error) { 206 if tracing.IsEnabled() { 207 ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionContainersClient.Refresh") 208 defer func() { 209 sc := -1 210 if result.Response != nil { 211 sc = result.Response.StatusCode 212 } 213 tracing.EndSpan(ctx, sc, err) 214 }() 215 } 216 req, err := client.RefreshPreparer(ctx, vaultName, resourceGroupName, fabricName, filter) 217 if err != nil { 218 err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Refresh", nil, "Failure preparing request") 219 return 220 } 221 222 resp, err := client.RefreshSender(req) 223 if err != nil { 224 result.Response = resp 225 err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Refresh", resp, "Failure sending request") 226 return 227 } 228 229 result, err = client.RefreshResponder(resp) 230 if err != nil { 231 err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Refresh", resp, "Failure responding to request") 232 return 233 } 234 235 return 236} 237 238// RefreshPreparer prepares the Refresh request. 239func (client ProtectionContainersClient) RefreshPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, filter string) (*http.Request, error) { 240 pathParameters := map[string]interface{}{ 241 "fabricName": autorest.Encode("path", fabricName), 242 "resourceGroupName": autorest.Encode("path", resourceGroupName), 243 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 244 "vaultName": autorest.Encode("path", vaultName), 245 } 246 247 const APIVersion = "2021-01-01" 248 queryParameters := map[string]interface{}{ 249 "api-version": APIVersion, 250 } 251 if len(filter) > 0 { 252 queryParameters["$filter"] = autorest.Encode("query", filter) 253 } 254 255 preparer := autorest.CreatePreparer( 256 autorest.AsPost(), 257 autorest.WithBaseURL(client.BaseURI), 258 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/refreshContainers", pathParameters), 259 autorest.WithQueryParameters(queryParameters)) 260 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 261} 262 263// RefreshSender sends the Refresh request. The method will close the 264// http.Response Body if it receives an error. 265func (client ProtectionContainersClient) RefreshSender(req *http.Request) (*http.Response, error) { 266 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 267} 268 269// RefreshResponder handles the response to the Refresh request. The method always 270// closes the http.Response Body. 271func (client ProtectionContainersClient) RefreshResponder(resp *http.Response) (result autorest.Response, err error) { 272 err = autorest.Respond( 273 resp, 274 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 275 autorest.ByClosing()) 276 result.Response = resp 277 return 278} 279 280// Register registers the container with Recovery Services vault. 281// This is an asynchronous operation. To track the operation status, use location header to call get latest status of 282// the operation. 283// Parameters: 284// vaultName - the name of the recovery services vault. 285// resourceGroupName - the name of the resource group where the recovery services vault is present. 286// fabricName - fabric name associated with the container. 287// containerName - name of the container to be registered. 288// parameters - request body for operation 289func (client ProtectionContainersClient) Register(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, parameters ProtectionContainerResource) (result ProtectionContainerResource, err error) { 290 if tracing.IsEnabled() { 291 ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionContainersClient.Register") 292 defer func() { 293 sc := -1 294 if result.Response.Response != nil { 295 sc = result.Response.Response.StatusCode 296 } 297 tracing.EndSpan(ctx, sc, err) 298 }() 299 } 300 req, err := client.RegisterPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, parameters) 301 if err != nil { 302 err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Register", nil, "Failure preparing request") 303 return 304 } 305 306 resp, err := client.RegisterSender(req) 307 if err != nil { 308 result.Response = autorest.Response{Response: resp} 309 err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Register", resp, "Failure sending request") 310 return 311 } 312 313 result, err = client.RegisterResponder(resp) 314 if err != nil { 315 err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Register", resp, "Failure responding to request") 316 return 317 } 318 319 return 320} 321 322// RegisterPreparer prepares the Register request. 323func (client ProtectionContainersClient) RegisterPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, parameters ProtectionContainerResource) (*http.Request, error) { 324 pathParameters := map[string]interface{}{ 325 "containerName": autorest.Encode("path", containerName), 326 "fabricName": autorest.Encode("path", fabricName), 327 "resourceGroupName": autorest.Encode("path", resourceGroupName), 328 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 329 "vaultName": autorest.Encode("path", vaultName), 330 } 331 332 const APIVersion = "2021-01-01" 333 queryParameters := map[string]interface{}{ 334 "api-version": APIVersion, 335 } 336 337 preparer := autorest.CreatePreparer( 338 autorest.AsContentType("application/json; charset=utf-8"), 339 autorest.AsPut(), 340 autorest.WithBaseURL(client.BaseURI), 341 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}", pathParameters), 342 autorest.WithJSON(parameters), 343 autorest.WithQueryParameters(queryParameters)) 344 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 345} 346 347// RegisterSender sends the Register request. The method will close the 348// http.Response Body if it receives an error. 349func (client ProtectionContainersClient) RegisterSender(req *http.Request) (*http.Response, error) { 350 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 351} 352 353// RegisterResponder handles the response to the Register request. The method always 354// closes the http.Response Body. 355func (client ProtectionContainersClient) RegisterResponder(resp *http.Response) (result ProtectionContainerResource, err error) { 356 err = autorest.Respond( 357 resp, 358 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 359 autorest.ByUnmarshallingJSON(&result), 360 autorest.ByClosing()) 361 result.Response = autorest.Response{Response: resp} 362 return 363} 364 365// Unregister unregisters the given container from your Recovery Services Vault. This is an asynchronous operation. To 366// determine 367// whether the backend service has finished processing the request, call Get Container Operation Result API. 368// Parameters: 369// vaultName - the name of the recovery services vault. 370// resourceGroupName - the name of the resource group where the recovery services vault is present. 371// fabricName - name of the fabric where the container belongs. 372// containerName - name of the container which needs to be unregistered from the Recovery Services Vault. 373func (client ProtectionContainersClient) Unregister(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string) (result autorest.Response, err error) { 374 if tracing.IsEnabled() { 375 ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionContainersClient.Unregister") 376 defer func() { 377 sc := -1 378 if result.Response != nil { 379 sc = result.Response.StatusCode 380 } 381 tracing.EndSpan(ctx, sc, err) 382 }() 383 } 384 req, err := client.UnregisterPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName) 385 if err != nil { 386 err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Unregister", nil, "Failure preparing request") 387 return 388 } 389 390 resp, err := client.UnregisterSender(req) 391 if err != nil { 392 result.Response = resp 393 err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Unregister", resp, "Failure sending request") 394 return 395 } 396 397 result, err = client.UnregisterResponder(resp) 398 if err != nil { 399 err = autorest.NewErrorWithError(err, "backup.ProtectionContainersClient", "Unregister", resp, "Failure responding to request") 400 return 401 } 402 403 return 404} 405 406// UnregisterPreparer prepares the Unregister request. 407func (client ProtectionContainersClient) UnregisterPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string) (*http.Request, error) { 408 pathParameters := map[string]interface{}{ 409 "containerName": autorest.Encode("path", containerName), 410 "fabricName": autorest.Encode("path", fabricName), 411 "resourceGroupName": autorest.Encode("path", resourceGroupName), 412 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 413 "vaultName": autorest.Encode("path", vaultName), 414 } 415 416 const APIVersion = "2021-01-01" 417 queryParameters := map[string]interface{}{ 418 "api-version": APIVersion, 419 } 420 421 preparer := autorest.CreatePreparer( 422 autorest.AsDelete(), 423 autorest.WithBaseURL(client.BaseURI), 424 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}", pathParameters), 425 autorest.WithQueryParameters(queryParameters)) 426 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 427} 428 429// UnregisterSender sends the Unregister request. The method will close the 430// http.Response Body if it receives an error. 431func (client ProtectionContainersClient) UnregisterSender(req *http.Request) (*http.Response, error) { 432 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 433} 434 435// UnregisterResponder handles the response to the Unregister request. The method always 436// closes the http.Response Body. 437func (client ProtectionContainersClient) UnregisterResponder(resp *http.Response) (result autorest.Response, err error) { 438 err = autorest.Respond( 439 resp, 440 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 441 autorest.ByClosing()) 442 result.Response = resp 443 return 444} 445