...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2016-12-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  // Delete deletes specified backup policy from your Recovery Services Vault. This is an asynchronous operation. Status
    35  // of the
    36  // operation can be fetched 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 deleted.
    41  func (client ProtectionPoliciesClient) Delete(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (result autorest.Response, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionPoliciesClient.Delete")
    44  		defer func() {
    45  			sc := -1
    46  			if result.Response != nil {
    47  				sc = result.Response.StatusCode
    48  			}
    49  			tracing.EndSpan(ctx, sc, err)
    50  		}()
    51  	}
    52  	req, err := client.DeletePreparer(ctx, vaultName, resourceGroupName, policyName)
    53  	if err != nil {
    54  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Delete", nil, "Failure preparing request")
    55  		return
    56  	}
    57  
    58  	resp, err := client.DeleteSender(req)
    59  	if err != nil {
    60  		result.Response = resp
    61  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Delete", resp, "Failure sending request")
    62  		return
    63  	}
    64  
    65  	result, err = client.DeleteResponder(resp)
    66  	if err != nil {
    67  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Delete", resp, "Failure responding to request")
    68  		return
    69  	}
    70  
    71  	return
    72  }
    73  
    74  // DeletePreparer prepares the Delete request.
    75  func (client ProtectionPoliciesClient) DeletePreparer(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (*http.Request, error) {
    76  	pathParameters := map[string]interface{}{
    77  		"policyName":        autorest.Encode("path", policyName),
    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-12-01"
    84  	queryParameters := map[string]interface{}{
    85  		"api-version": APIVersion,
    86  	}
    87  
    88  	preparer := autorest.CreatePreparer(
    89  		autorest.AsDelete(),
    90  		autorest.WithBaseURL(client.BaseURI),
    91  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies/{policyName}", pathParameters),
    92  		autorest.WithQueryParameters(queryParameters))
    93  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    94  }
    95  
    96  // DeleteSender sends the Delete request. The method will close the
    97  // http.Response Body if it receives an error.
    98  func (client ProtectionPoliciesClient) DeleteSender(req *http.Request) (*http.Response, error) {
    99  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   100  }
   101  
   102  // DeleteResponder handles the response to the Delete request. The method always
   103  // closes the http.Response Body.
   104  func (client ProtectionPoliciesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   105  	err = autorest.Respond(
   106  		resp,
   107  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   108  		autorest.ByClosing())
   109  	result.Response = resp
   110  	return
   111  }
   112  

View as plain text