...

Source file src/github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2021-01-01/backup/protectionpolicies.go

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2021-01-01/backup

     1  package 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  
     9  import (
    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  // ProtectionPoliciesClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
    18  type ProtectionPoliciesClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewProtectionPoliciesClient creates an instance of the ProtectionPoliciesClient client.
    23  func NewProtectionPoliciesClient(subscriptionID string) ProtectionPoliciesClient {
    24  	return NewProtectionPoliciesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewProtectionPoliciesClientWithBaseURI creates an instance of the ProtectionPoliciesClient 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).
    30  func NewProtectionPoliciesClientWithBaseURI(baseURI string, subscriptionID string) ProtectionPoliciesClient {
    31  	return ProtectionPoliciesClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // CreateOrUpdate creates or modifies a backup policy. This is an asynchronous operation. Status of the operation can
    35  // be fetched
    36  // using GetPolicyOperationResult API.
    37  // Parameters:
    38  // vaultName - the name of the recovery services vault.
    39  // resourceGroupName - the name of the resource group where the recovery services vault is present.
    40  // policyName - backup policy to be created.
    41  // parameters - resource backup policy
    42  func (client ProtectionPoliciesClient) CreateOrUpdate(ctx context.Context, vaultName string, resourceGroupName string, policyName string, parameters ProtectionPolicyResource) (result ProtectionPolicyResource, err error) {
    43  	if tracing.IsEnabled() {
    44  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionPoliciesClient.CreateOrUpdate")
    45  		defer func() {
    46  			sc := -1
    47  			if result.Response.Response != nil {
    48  				sc = result.Response.Response.StatusCode
    49  			}
    50  			tracing.EndSpan(ctx, sc, err)
    51  		}()
    52  	}
    53  	req, err := client.CreateOrUpdatePreparer(ctx, vaultName, resourceGroupName, policyName, parameters)
    54  	if err != nil {
    55  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "CreateOrUpdate", nil, "Failure preparing request")
    56  		return
    57  	}
    58  
    59  	resp, err := client.CreateOrUpdateSender(req)
    60  	if err != nil {
    61  		result.Response = autorest.Response{Response: resp}
    62  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "CreateOrUpdate", resp, "Failure sending request")
    63  		return
    64  	}
    65  
    66  	result, err = client.CreateOrUpdateResponder(resp)
    67  	if err != nil {
    68  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "CreateOrUpdate", resp, "Failure responding to request")
    69  		return
    70  	}
    71  
    72  	return
    73  }
    74  
    75  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    76  func (client ProtectionPoliciesClient) CreateOrUpdatePreparer(ctx context.Context, vaultName string, resourceGroupName string, policyName string, parameters ProtectionPolicyResource) (*http.Request, error) {
    77  	pathParameters := map[string]interface{}{
    78  		"policyName":        autorest.Encode("path", policyName),
    79  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    80  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    81  		"vaultName":         autorest.Encode("path", vaultName),
    82  	}
    83  
    84  	const APIVersion = "2021-01-01"
    85  	queryParameters := map[string]interface{}{
    86  		"api-version": APIVersion,
    87  	}
    88  
    89  	preparer := autorest.CreatePreparer(
    90  		autorest.AsContentType("application/json; charset=utf-8"),
    91  		autorest.AsPut(),
    92  		autorest.WithBaseURL(client.BaseURI),
    93  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies/{policyName}", pathParameters),
    94  		autorest.WithJSON(parameters),
    95  		autorest.WithQueryParameters(queryParameters))
    96  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    97  }
    98  
    99  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
   100  // http.Response Body if it receives an error.
   101  func (client ProtectionPoliciesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   102  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   103  }
   104  
   105  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   106  // closes the http.Response Body.
   107  func (client ProtectionPoliciesClient) CreateOrUpdateResponder(resp *http.Response) (result ProtectionPolicyResource, err error) {
   108  	err = autorest.Respond(
   109  		resp,
   110  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   111  		autorest.ByUnmarshallingJSON(&result),
   112  		autorest.ByClosing())
   113  	result.Response = autorest.Response{Response: resp}
   114  	return
   115  }
   116  
   117  // Delete deletes specified backup policy from your Recovery Services Vault. This is an asynchronous operation. Status
   118  // of the
   119  // operation can be fetched using GetProtectionPolicyOperationResult API.
   120  // Parameters:
   121  // vaultName - the name of the recovery services vault.
   122  // resourceGroupName - the name of the resource group where the recovery services vault is present.
   123  // policyName - backup policy to be deleted.
   124  func (client ProtectionPoliciesClient) Delete(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (result ProtectionPoliciesDeleteFuture, err error) {
   125  	if tracing.IsEnabled() {
   126  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionPoliciesClient.Delete")
   127  		defer func() {
   128  			sc := -1
   129  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   130  				sc = result.FutureAPI.Response().StatusCode
   131  			}
   132  			tracing.EndSpan(ctx, sc, err)
   133  		}()
   134  	}
   135  	req, err := client.DeletePreparer(ctx, vaultName, resourceGroupName, policyName)
   136  	if err != nil {
   137  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Delete", nil, "Failure preparing request")
   138  		return
   139  	}
   140  
   141  	result, err = client.DeleteSender(req)
   142  	if err != nil {
   143  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Delete", result.Response(), "Failure sending request")
   144  		return
   145  	}
   146  
   147  	return
   148  }
   149  
   150  // DeletePreparer prepares the Delete request.
   151  func (client ProtectionPoliciesClient) DeletePreparer(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (*http.Request, error) {
   152  	pathParameters := map[string]interface{}{
   153  		"policyName":        autorest.Encode("path", policyName),
   154  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   155  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   156  		"vaultName":         autorest.Encode("path", vaultName),
   157  	}
   158  
   159  	const APIVersion = "2021-01-01"
   160  	queryParameters := map[string]interface{}{
   161  		"api-version": APIVersion,
   162  	}
   163  
   164  	preparer := autorest.CreatePreparer(
   165  		autorest.AsDelete(),
   166  		autorest.WithBaseURL(client.BaseURI),
   167  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies/{policyName}", pathParameters),
   168  		autorest.WithQueryParameters(queryParameters))
   169  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   170  }
   171  
   172  // DeleteSender sends the Delete request. The method will close the
   173  // http.Response Body if it receives an error.
   174  func (client ProtectionPoliciesClient) DeleteSender(req *http.Request) (future ProtectionPoliciesDeleteFuture, err error) {
   175  	var resp *http.Response
   176  	future.FutureAPI = &azure.Future{}
   177  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   178  	if err != nil {
   179  		return
   180  	}
   181  	var azf azure.Future
   182  	azf, err = azure.NewFutureFromResponse(resp)
   183  	future.FutureAPI = &azf
   184  	future.Result = future.result
   185  	return
   186  }
   187  
   188  // DeleteResponder handles the response to the Delete request. The method always
   189  // closes the http.Response Body.
   190  func (client ProtectionPoliciesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   191  	err = autorest.Respond(
   192  		resp,
   193  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   194  		autorest.ByClosing())
   195  	result.Response = resp
   196  	return
   197  }
   198  
   199  // Get provides the details of the backup policies associated to Recovery Services Vault. This is an asynchronous
   200  // operation. Status of the operation can be fetched using GetPolicyOperationResult API.
   201  // Parameters:
   202  // vaultName - the name of the recovery services vault.
   203  // resourceGroupName - the name of the resource group where the recovery services vault is present.
   204  // policyName - backup policy information to be fetched.
   205  func (client ProtectionPoliciesClient) Get(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (result ProtectionPolicyResource, err error) {
   206  	if tracing.IsEnabled() {
   207  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionPoliciesClient.Get")
   208  		defer func() {
   209  			sc := -1
   210  			if result.Response.Response != nil {
   211  				sc = result.Response.Response.StatusCode
   212  			}
   213  			tracing.EndSpan(ctx, sc, err)
   214  		}()
   215  	}
   216  	req, err := client.GetPreparer(ctx, vaultName, resourceGroupName, policyName)
   217  	if err != nil {
   218  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Get", nil, "Failure preparing request")
   219  		return
   220  	}
   221  
   222  	resp, err := client.GetSender(req)
   223  	if err != nil {
   224  		result.Response = autorest.Response{Response: resp}
   225  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Get", resp, "Failure sending request")
   226  		return
   227  	}
   228  
   229  	result, err = client.GetResponder(resp)
   230  	if err != nil {
   231  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Get", resp, "Failure responding to request")
   232  		return
   233  	}
   234  
   235  	return
   236  }
   237  
   238  // GetPreparer prepares the Get request.
   239  func (client ProtectionPoliciesClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (*http.Request, error) {
   240  	pathParameters := map[string]interface{}{
   241  		"policyName":        autorest.Encode("path", policyName),
   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  
   252  	preparer := autorest.CreatePreparer(
   253  		autorest.AsGet(),
   254  		autorest.WithBaseURL(client.BaseURI),
   255  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies/{policyName}", pathParameters),
   256  		autorest.WithQueryParameters(queryParameters))
   257  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   258  }
   259  
   260  // GetSender sends the Get request. The method will close the
   261  // http.Response Body if it receives an error.
   262  func (client ProtectionPoliciesClient) GetSender(req *http.Request) (*http.Response, error) {
   263  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   264  }
   265  
   266  // GetResponder handles the response to the Get request. The method always
   267  // closes the http.Response Body.
   268  func (client ProtectionPoliciesClient) GetResponder(resp *http.Response) (result ProtectionPolicyResource, err error) {
   269  	err = autorest.Respond(
   270  		resp,
   271  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   272  		autorest.ByUnmarshallingJSON(&result),
   273  		autorest.ByClosing())
   274  	result.Response = autorest.Response{Response: resp}
   275  	return
   276  }
   277  

View as plain text