...

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

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2016-06-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. Use the
    35  // GetPolicyOperationResult API to Get the operation status.
    36  // Parameters:
    37  // vaultName - the name of the Recovery Services vault.
    38  // resourceGroupName - the name of the resource group associated with the Recovery Services vault.
    39  // policyName - the backup policy to be created.
    40  // resourceProtectionPolicy - the resource backup policy.
    41  func (client ProtectionPoliciesClient) CreateOrUpdate(ctx context.Context, vaultName string, resourceGroupName string, policyName string, resourceProtectionPolicy ProtectionPolicyResource) (result ProtectionPolicyResource, err error) {
    42  	if tracing.IsEnabled() {
    43  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionPoliciesClient.CreateOrUpdate")
    44  		defer func() {
    45  			sc := -1
    46  			if result.Response.Response != nil {
    47  				sc = result.Response.Response.StatusCode
    48  			}
    49  			tracing.EndSpan(ctx, sc, err)
    50  		}()
    51  	}
    52  	req, err := client.CreateOrUpdatePreparer(ctx, vaultName, resourceGroupName, policyName, resourceProtectionPolicy)
    53  	if err != nil {
    54  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "CreateOrUpdate", nil, "Failure preparing request")
    55  		return
    56  	}
    57  
    58  	resp, err := client.CreateOrUpdateSender(req)
    59  	if err != nil {
    60  		result.Response = autorest.Response{Response: resp}
    61  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "CreateOrUpdate", resp, "Failure sending request")
    62  		return
    63  	}
    64  
    65  	result, err = client.CreateOrUpdateResponder(resp)
    66  	if err != nil {
    67  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "CreateOrUpdate", resp, "Failure responding to request")
    68  		return
    69  	}
    70  
    71  	return
    72  }
    73  
    74  // CreateOrUpdatePreparer prepares the CreateOrUpdate request.
    75  func (client ProtectionPoliciesClient) CreateOrUpdatePreparer(ctx context.Context, vaultName string, resourceGroupName string, policyName string, resourceProtectionPolicy ProtectionPolicyResource) (*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-06-01"
    84  	queryParameters := map[string]interface{}{
    85  		"api-version": APIVersion,
    86  	}
    87  
    88  	preparer := autorest.CreatePreparer(
    89  		autorest.AsContentType("application/json; charset=utf-8"),
    90  		autorest.AsPut(),
    91  		autorest.WithBaseURL(client.BaseURI),
    92  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies/{policyName}", pathParameters),
    93  		autorest.WithJSON(resourceProtectionPolicy),
    94  		autorest.WithQueryParameters(queryParameters))
    95  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    96  }
    97  
    98  // CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
    99  // http.Response Body if it receives an error.
   100  func (client ProtectionPoliciesClient) CreateOrUpdateSender(req *http.Request) (*http.Response, error) {
   101  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   102  }
   103  
   104  // CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
   105  // closes the http.Response Body.
   106  func (client ProtectionPoliciesClient) CreateOrUpdateResponder(resp *http.Response) (result ProtectionPolicyResource, err error) {
   107  	err = autorest.Respond(
   108  		resp,
   109  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   110  		autorest.ByUnmarshallingJSON(&result),
   111  		autorest.ByClosing())
   112  	result.Response = autorest.Response{Response: resp}
   113  	return
   114  }
   115  
   116  // Delete deletes the specified backup policy from your Recovery Services vault. This is an asynchronous operation. Use
   117  // the GetPolicyOperationResult API to Get the operation status.
   118  // Parameters:
   119  // vaultName - the name of the Recovery Services vault.
   120  // resourceGroupName - the name of the resource group associated with the Recovery Services vault.
   121  // policyName - the name of the backup policy to be deleted.
   122  func (client ProtectionPoliciesClient) Delete(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (result autorest.Response, err error) {
   123  	if tracing.IsEnabled() {
   124  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionPoliciesClient.Delete")
   125  		defer func() {
   126  			sc := -1
   127  			if result.Response != nil {
   128  				sc = result.Response.StatusCode
   129  			}
   130  			tracing.EndSpan(ctx, sc, err)
   131  		}()
   132  	}
   133  	req, err := client.DeletePreparer(ctx, vaultName, resourceGroupName, policyName)
   134  	if err != nil {
   135  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Delete", nil, "Failure preparing request")
   136  		return
   137  	}
   138  
   139  	resp, err := client.DeleteSender(req)
   140  	if err != nil {
   141  		result.Response = resp
   142  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Delete", resp, "Failure sending request")
   143  		return
   144  	}
   145  
   146  	result, err = client.DeleteResponder(resp)
   147  	if err != nil {
   148  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Delete", resp, "Failure responding to request")
   149  		return
   150  	}
   151  
   152  	return
   153  }
   154  
   155  // DeletePreparer prepares the Delete request.
   156  func (client ProtectionPoliciesClient) DeletePreparer(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (*http.Request, error) {
   157  	pathParameters := map[string]interface{}{
   158  		"policyName":        autorest.Encode("path", policyName),
   159  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   160  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   161  		"vaultName":         autorest.Encode("path", vaultName),
   162  	}
   163  
   164  	const APIVersion = "2016-06-01"
   165  	queryParameters := map[string]interface{}{
   166  		"api-version": APIVersion,
   167  	}
   168  
   169  	preparer := autorest.CreatePreparer(
   170  		autorest.AsDelete(),
   171  		autorest.WithBaseURL(client.BaseURI),
   172  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies/{policyName}", pathParameters),
   173  		autorest.WithQueryParameters(queryParameters))
   174  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   175  }
   176  
   177  // DeleteSender sends the Delete request. The method will close the
   178  // http.Response Body if it receives an error.
   179  func (client ProtectionPoliciesClient) DeleteSender(req *http.Request) (*http.Response, error) {
   180  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   181  }
   182  
   183  // DeleteResponder handles the response to the Delete request. The method always
   184  // closes the http.Response Body.
   185  func (client ProtectionPoliciesClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   186  	err = autorest.Respond(
   187  		resp,
   188  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
   189  		autorest.ByClosing())
   190  	result.Response = resp
   191  	return
   192  }
   193  
   194  // Get gets the details of the backup policy associated with the Recovery Services vault. This is an asynchronous
   195  // operation. Use the GetPolicyOperationResult API to Get the operation status.
   196  // Parameters:
   197  // vaultName - the name of the Recovery Services vault.
   198  // resourceGroupName - the name of the resource group associated with the Recovery Services vault.
   199  // policyName - the backup policy name used in this GET operation.
   200  func (client ProtectionPoliciesClient) Get(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (result ProtectionPolicyResource, err error) {
   201  	if tracing.IsEnabled() {
   202  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionPoliciesClient.Get")
   203  		defer func() {
   204  			sc := -1
   205  			if result.Response.Response != nil {
   206  				sc = result.Response.Response.StatusCode
   207  			}
   208  			tracing.EndSpan(ctx, sc, err)
   209  		}()
   210  	}
   211  	req, err := client.GetPreparer(ctx, vaultName, resourceGroupName, policyName)
   212  	if err != nil {
   213  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Get", nil, "Failure preparing request")
   214  		return
   215  	}
   216  
   217  	resp, err := client.GetSender(req)
   218  	if err != nil {
   219  		result.Response = autorest.Response{Response: resp}
   220  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Get", resp, "Failure sending request")
   221  		return
   222  	}
   223  
   224  	result, err = client.GetResponder(resp)
   225  	if err != nil {
   226  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "Get", resp, "Failure responding to request")
   227  		return
   228  	}
   229  
   230  	return
   231  }
   232  
   233  // GetPreparer prepares the Get request.
   234  func (client ProtectionPoliciesClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string, policyName string) (*http.Request, error) {
   235  	pathParameters := map[string]interface{}{
   236  		"policyName":        autorest.Encode("path", policyName),
   237  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   238  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   239  		"vaultName":         autorest.Encode("path", vaultName),
   240  	}
   241  
   242  	const APIVersion = "2016-06-01"
   243  	queryParameters := map[string]interface{}{
   244  		"api-version": APIVersion,
   245  	}
   246  
   247  	preparer := autorest.CreatePreparer(
   248  		autorest.AsGet(),
   249  		autorest.WithBaseURL(client.BaseURI),
   250  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies/{policyName}", pathParameters),
   251  		autorest.WithQueryParameters(queryParameters))
   252  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   253  }
   254  
   255  // GetSender sends the Get request. The method will close the
   256  // http.Response Body if it receives an error.
   257  func (client ProtectionPoliciesClient) GetSender(req *http.Request) (*http.Response, error) {
   258  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   259  }
   260  
   261  // GetResponder handles the response to the Get request. The method always
   262  // closes the http.Response Body.
   263  func (client ProtectionPoliciesClient) GetResponder(resp *http.Response) (result ProtectionPolicyResource, err error) {
   264  	err = autorest.Respond(
   265  		resp,
   266  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   267  		autorest.ByUnmarshallingJSON(&result),
   268  		autorest.ByClosing())
   269  	result.Response = autorest.Response{Response: resp}
   270  	return
   271  }
   272  
   273  // List lists the backup policies associated with the Recovery Services vault. The API provides parameters to Get
   274  // scoped results.
   275  // Parameters:
   276  // vaultName - the name of the Recovery Services vault.
   277  // resourceGroupName - the name of the resource group associated with the Recovery Services vault.
   278  // filter - the following equation can be used to filter the list of backup policies. backupManagementType eq
   279  // {AzureIaasVM, MAB, DPM, AzureBackupServer, AzureSql}.
   280  func (client ProtectionPoliciesClient) List(ctx context.Context, vaultName string, resourceGroupName string, filter string) (result ProtectionPolicyResourceList, err error) {
   281  	if tracing.IsEnabled() {
   282  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionPoliciesClient.List")
   283  		defer func() {
   284  			sc := -1
   285  			if result.Response.Response != nil {
   286  				sc = result.Response.Response.StatusCode
   287  			}
   288  			tracing.EndSpan(ctx, sc, err)
   289  		}()
   290  	}
   291  	req, err := client.ListPreparer(ctx, vaultName, resourceGroupName, filter)
   292  	if err != nil {
   293  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "List", nil, "Failure preparing request")
   294  		return
   295  	}
   296  
   297  	resp, err := client.ListSender(req)
   298  	if err != nil {
   299  		result.Response = autorest.Response{Response: resp}
   300  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "List", resp, "Failure sending request")
   301  		return
   302  	}
   303  
   304  	result, err = client.ListResponder(resp)
   305  	if err != nil {
   306  		err = autorest.NewErrorWithError(err, "backup.ProtectionPoliciesClient", "List", resp, "Failure responding to request")
   307  		return
   308  	}
   309  
   310  	return
   311  }
   312  
   313  // ListPreparer prepares the List request.
   314  func (client ProtectionPoliciesClient) ListPreparer(ctx context.Context, vaultName string, resourceGroupName string, filter string) (*http.Request, error) {
   315  	pathParameters := map[string]interface{}{
   316  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   317  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   318  		"vaultName":         autorest.Encode("path", vaultName),
   319  	}
   320  
   321  	const APIVersion = "2016-06-01"
   322  	queryParameters := map[string]interface{}{
   323  		"api-version": APIVersion,
   324  	}
   325  	if len(filter) > 0 {
   326  		queryParameters["$filter"] = autorest.Encode("query", filter)
   327  	}
   328  
   329  	preparer := autorest.CreatePreparer(
   330  		autorest.AsGet(),
   331  		autorest.WithBaseURL(client.BaseURI),
   332  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies", pathParameters),
   333  		autorest.WithQueryParameters(queryParameters))
   334  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   335  }
   336  
   337  // ListSender sends the List request. The method will close the
   338  // http.Response Body if it receives an error.
   339  func (client ProtectionPoliciesClient) ListSender(req *http.Request) (*http.Response, error) {
   340  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   341  }
   342  
   343  // ListResponder handles the response to the List request. The method always
   344  // closes the http.Response Body.
   345  func (client ProtectionPoliciesClient) ListResponder(resp *http.Response) (result ProtectionPolicyResourceList, err error) {
   346  	err = autorest.Respond(
   347  		resp,
   348  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   349  		autorest.ByUnmarshallingJSON(&result),
   350  		autorest.ByClosing())
   351  	result.Response = autorest.Response{Response: resp}
   352  	return
   353  }
   354  

View as plain text