...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2020-02-02/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 = "2019-06-15"
    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 GetPolicyOperationResult 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 autorest.Response, err error) {
   125  	if tracing.IsEnabled() {
   126  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionPoliciesClient.Delete")
   127  		defer func() {
   128  			sc := -1
   129  			if result.Response != nil {
   130  				sc = result.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  	resp, err := client.DeleteSender(req)
   142  	if err != nil {
   143  		result.Response = resp
   144  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Delete", resp, "Failure sending request")
   145  		return
   146  	}
   147  
   148  	result, err = client.DeleteResponder(resp)
   149  	if err != nil {
   150  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Delete", resp, "Failure responding to request")
   151  		return
   152  	}
   153  
   154  	return
   155  }
   156  
   157  // DeletePreparer prepares the Delete request.
   158  func (client ProtectionPoliciesClient) DeletePreparer(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (*http.Request, error) {
   159  	pathParameters := map[string]interface{}{
   160  		"policyName":        autorest.Encode("path", policyName),
   161  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   162  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   163  		"vaultName":         autorest.Encode("path", vaultName),
   164  	}
   165  
   166  	const APIVersion = "2016-12-01"
   167  	queryParameters := map[string]interface{}{
   168  		"api-version": APIVersion,
   169  	}
   170  
   171  	preparer := autorest.CreatePreparer(
   172  		autorest.AsDelete(),
   173  		autorest.WithBaseURL(client.BaseURI),
   174  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies/{policyName}", pathParameters),
   175  		autorest.WithQueryParameters(queryParameters))
   176  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   177  }
   178  
   179  // DeleteSender sends the Delete request. The method will close the
   180  // http.Response Body if it receives an error.
   181  func (client ProtectionPoliciesClient) DeleteSender(req *http.Request) (*http.Response, error) {
   182  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   183  }
   184  
   185  // DeleteResponder handles the response to the Delete request. The method always
   186  // closes the http.Response Body.
   187  func (client ProtectionPoliciesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   188  	err = autorest.Respond(
   189  		resp,
   190  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   191  		autorest.ByClosing())
   192  	result.Response = resp
   193  	return
   194  }
   195  
   196  // Get provides the details of the backup policies associated to Recovery Services Vault. This is an asynchronous
   197  // operation. Status of the operation can be fetched using GetPolicyOperationResult API.
   198  // Parameters:
   199  // vaultName - the name of the recovery services vault.
   200  // resourceGroupName - the name of the resource group where the recovery services vault is present.
   201  // policyName - backup policy information to be fetched.
   202  func (client ProtectionPoliciesClient) Get(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (result ProtectionPolicyResource, err error) {
   203  	if tracing.IsEnabled() {
   204  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionPoliciesClient.Get")
   205  		defer func() {
   206  			sc := -1
   207  			if result.Response.Response != nil {
   208  				sc = result.Response.Response.StatusCode
   209  			}
   210  			tracing.EndSpan(ctx, sc, err)
   211  		}()
   212  	}
   213  	req, err := client.GetPreparer(ctx, vaultName, resourceGroupName, policyName)
   214  	if err != nil {
   215  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Get", nil, "Failure preparing request")
   216  		return
   217  	}
   218  
   219  	resp, err := client.GetSender(req)
   220  	if err != nil {
   221  		result.Response = autorest.Response{Response: resp}
   222  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Get", resp, "Failure sending request")
   223  		return
   224  	}
   225  
   226  	result, err = client.GetResponder(resp)
   227  	if err != nil {
   228  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Get", resp, "Failure responding to request")
   229  		return
   230  	}
   231  
   232  	return
   233  }
   234  
   235  // GetPreparer prepares the Get request.
   236  func (client ProtectionPoliciesClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (*http.Request, error) {
   237  	pathParameters := map[string]interface{}{
   238  		"policyName":        autorest.Encode("path", policyName),
   239  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   240  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   241  		"vaultName":         autorest.Encode("path", vaultName),
   242  	}
   243  
   244  	const APIVersion = "2019-06-15"
   245  	queryParameters := map[string]interface{}{
   246  		"api-version": APIVersion,
   247  	}
   248  
   249  	preparer := autorest.CreatePreparer(
   250  		autorest.AsGet(),
   251  		autorest.WithBaseURL(client.BaseURI),
   252  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies/{policyName}", pathParameters),
   253  		autorest.WithQueryParameters(queryParameters))
   254  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   255  }
   256  
   257  // GetSender sends the Get request. The method will close the
   258  // http.Response Body if it receives an error.
   259  func (client ProtectionPoliciesClient) GetSender(req *http.Request) (*http.Response, error) {
   260  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   261  }
   262  
   263  // GetResponder handles the response to the Get request. The method always
   264  // closes the http.Response Body.
   265  func (client ProtectionPoliciesClient) GetResponder(resp *http.Response) (result ProtectionPolicyResource, err error) {
   266  	err = autorest.Respond(
   267  		resp,
   268  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   269  		autorest.ByUnmarshallingJSON(&result),
   270  		autorest.ByClosing())
   271  	result.Response = autorest.Response{Response: resp}
   272  	return
   273  }
   274  

View as plain text