...

Source file src/github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2019-06-15/backup/operationstatuses.go

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2019-06-15/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  // OperationStatusesClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
    18  type OperationStatusesClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewOperationStatusesClient creates an instance of the OperationStatusesClient client.
    23  func NewOperationStatusesClient(subscriptionID string) OperationStatusesClient {
    24  	return NewOperationStatusesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewOperationStatusesClientWithBaseURI creates an instance of the OperationStatusesClient 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 NewOperationStatusesClientWithBaseURI(baseURI string, subscriptionID string) OperationStatusesClient {
    31  	return OperationStatusesClient{NewWithBaseURI(baseURI, subscriptionID)}
    32  }
    33  
    34  // Get fetches the status of an operation such as triggering a backup, restore. The status can be in progress,
    35  // completed
    36  // or failed. You can refer to the OperationStatus enum for all the possible states of an operation. Some operations
    37  // create jobs. This method returns the list of jobs when the operation is complete.
    38  // Parameters:
    39  // vaultName - the name of the recovery services vault.
    40  // resourceGroupName - the name of the resource group where the recovery services vault is present.
    41  // operationID - operationID which represents the operation.
    42  func (client OperationStatusesClient) Get(ctx context.Context, vaultName string, resourceGroupName string, operationID string) (result OperationStatus, err error) {
    43  	if tracing.IsEnabled() {
    44  		ctx = tracing.StartSpan(ctx, fqdn+"/OperationStatusesClient.Get")
    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.GetPreparer(ctx, vaultName, resourceGroupName, operationID)
    54  	if err != nil {
    55  		err = autorest.NewErrorWithError(err, "backup.OperationStatusesClient", "Get", nil, "Failure preparing request")
    56  		return
    57  	}
    58  
    59  	resp, err := client.GetSender(req)
    60  	if err != nil {
    61  		result.Response = autorest.Response{Response: resp}
    62  		err = autorest.NewErrorWithError(err, "backup.OperationStatusesClient", "Get", resp, "Failure sending request")
    63  		return
    64  	}
    65  
    66  	result, err = client.GetResponder(resp)
    67  	if err != nil {
    68  		err = autorest.NewErrorWithError(err, "backup.OperationStatusesClient", "Get", resp, "Failure responding to request")
    69  		return
    70  	}
    71  
    72  	return
    73  }
    74  
    75  // GetPreparer prepares the Get request.
    76  func (client OperationStatusesClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string, operationID string) (*http.Request, error) {
    77  	pathParameters := map[string]interface{}{
    78  		"operationId":       autorest.Encode("path", operationID),
    79  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    80  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    81  		"vaultName":         autorest.Encode("path", vaultName),
    82  	}
    83  
    84  	const APIVersion = "2016-12-01"
    85  	queryParameters := map[string]interface{}{
    86  		"api-version": APIVersion,
    87  	}
    88  
    89  	preparer := autorest.CreatePreparer(
    90  		autorest.AsGet(),
    91  		autorest.WithBaseURL(client.BaseURI),
    92  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupOperations/{operationId}", pathParameters),
    93  		autorest.WithQueryParameters(queryParameters))
    94  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    95  }
    96  
    97  // GetSender sends the Get request. The method will close the
    98  // http.Response Body if it receives an error.
    99  func (client OperationStatusesClient) GetSender(req *http.Request) (*http.Response, error) {
   100  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   101  }
   102  
   103  // GetResponder handles the response to the Get request. The method always
   104  // closes the http.Response Body.
   105  func (client OperationStatusesClient) GetResponder(resp *http.Response) (result OperationStatus, err error) {
   106  	err = autorest.Respond(
   107  		resp,
   108  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   109  		autorest.ByUnmarshallingJSON(&result),
   110  		autorest.ByClosing())
   111  	result.Response = autorest.Response{Response: resp}
   112  	return
   113  }
   114  

View as plain text