...

Source file src/github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2016-06-01/backup/protectionpolicyoperationstatuses.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  // ProtectionPolicyOperationStatusesClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
    18  type ProtectionPolicyOperationStatusesClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewProtectionPolicyOperationStatusesClient creates an instance of the ProtectionPolicyOperationStatusesClient
    23  // client.
    24  func NewProtectionPolicyOperationStatusesClient(subscriptionID string) ProtectionPolicyOperationStatusesClient {
    25  	return NewProtectionPolicyOperationStatusesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    26  }
    27  
    28  // NewProtectionPolicyOperationStatusesClientWithBaseURI creates an instance of the
    29  // ProtectionPolicyOperationStatusesClient client using a custom endpoint.  Use this when interacting with an Azure
    30  // cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    31  func NewProtectionPolicyOperationStatusesClientWithBaseURI(baseURI string, subscriptionID string) ProtectionPolicyOperationStatusesClient {
    32  	return ProtectionPolicyOperationStatusesClient{NewWithBaseURI(baseURI, subscriptionID)}
    33  }
    34  
    35  // Get provides the status of the asynchronous operations like backup or restore. The status can be: in progress,
    36  // completed, or failed. You can refer to the Operation Status enumeration for the possible states of an operation.
    37  // Some operations create jobs. This method returns the list of jobs associated with the operation.
    38  // Parameters:
    39  // vaultName - the name of the Recovery Services vault.
    40  // resourceGroupName - the name of the resource group associated with the Recovery Services vault.
    41  // policyName - the backup policy name used in this GET operation.
    42  // operationID - the ID associated with this GET operation.
    43  func (client ProtectionPolicyOperationStatusesClient) Get(ctx context.Context, vaultName string, resourceGroupName string, policyName string, operationID string) (result OperationStatus, err error) {
    44  	if tracing.IsEnabled() {
    45  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectionPolicyOperationStatusesClient.Get")
    46  		defer func() {
    47  			sc := -1
    48  			if result.Response.Response != nil {
    49  				sc = result.Response.Response.StatusCode
    50  			}
    51  			tracing.EndSpan(ctx, sc, err)
    52  		}()
    53  	}
    54  	req, err := client.GetPreparer(ctx, vaultName, resourceGroupName, policyName, operationID)
    55  	if err != nil {
    56  		err = autorest.NewErrorWithError(err, "backup.ProtectionPolicyOperationStatusesClient", "Get", nil, "Failure preparing request")
    57  		return
    58  	}
    59  
    60  	resp, err := client.GetSender(req)
    61  	if err != nil {
    62  		result.Response = autorest.Response{Response: resp}
    63  		err = autorest.NewErrorWithError(err, "backup.ProtectionPolicyOperationStatusesClient", "Get", resp, "Failure sending request")
    64  		return
    65  	}
    66  
    67  	result, err = client.GetResponder(resp)
    68  	if err != nil {
    69  		err = autorest.NewErrorWithError(err, "backup.ProtectionPolicyOperationStatusesClient", "Get", resp, "Failure responding to request")
    70  		return
    71  	}
    72  
    73  	return
    74  }
    75  
    76  // GetPreparer prepares the Get request.
    77  func (client ProtectionPolicyOperationStatusesClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string, policyName string, operationID string) (*http.Request, error) {
    78  	pathParameters := map[string]interface{}{
    79  		"operationId":       autorest.Encode("path", operationID),
    80  		"policyName":        autorest.Encode("path", policyName),
    81  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    82  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    83  		"vaultName":         autorest.Encode("path", vaultName),
    84  	}
    85  
    86  	const APIVersion = "2016-06-01"
    87  	queryParameters := map[string]interface{}{
    88  		"api-version": APIVersion,
    89  	}
    90  
    91  	preparer := autorest.CreatePreparer(
    92  		autorest.AsGet(),
    93  		autorest.WithBaseURL(client.BaseURI),
    94  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupPolicies/{policyName}/operations/{operationId}", pathParameters),
    95  		autorest.WithQueryParameters(queryParameters))
    96  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    97  }
    98  
    99  // GetSender sends the Get request. The method will close the
   100  // http.Response Body if it receives an error.
   101  func (client ProtectionPolicyOperationStatusesClient) GetSender(req *http.Request) (*http.Response, error) {
   102  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   103  }
   104  
   105  // GetResponder handles the response to the Get request. The method always
   106  // closes the http.Response Body.
   107  func (client ProtectionPolicyOperationStatusesClient) GetResponder(resp *http.Response) (result OperationStatus, err error) {
   108  	err = autorest.Respond(
   109  		resp,
   110  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   111  		autorest.ByUnmarshallingJSON(&result),
   112  		autorest.ByClosing())
   113  	result.Response = autorest.Response{Response: resp}
   114  	return
   115  }
   116  

View as plain text