...

Source file src/github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2021-07-01/backup/protecteditemoperationstatuses.go

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2021-07-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  // ProtectedItemOperationStatusesClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
    18  type ProtectedItemOperationStatusesClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewProtectedItemOperationStatusesClient creates an instance of the ProtectedItemOperationStatusesClient client.
    23  func NewProtectedItemOperationStatusesClient(subscriptionID string) ProtectedItemOperationStatusesClient {
    24  	return NewProtectedItemOperationStatusesClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewProtectedItemOperationStatusesClientWithBaseURI creates an instance of the ProtectedItemOperationStatusesClient
    28  // client using a custom endpoint.  Use this when interacting with an Azure cloud that uses a non-standard base URI
    29  // (sovereign clouds, Azure stack).
    30  func NewProtectedItemOperationStatusesClientWithBaseURI(baseURI string, subscriptionID string) ProtectedItemOperationStatusesClient {
    31  	return ProtectedItemOperationStatusesClient{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 the operation. Some operations
    37  // 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 where the recovery services vault is present.
    41  // fabricName - fabric name associated with the backup item.
    42  // containerName - container name associated with the backup item.
    43  // protectedItemName - backup item name whose details are to be fetched.
    44  // operationID - operationID represents the operation whose status needs to be fetched.
    45  func (client ProtectedItemOperationStatusesClient) Get(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, operationID string) (result OperationStatus, err error) {
    46  	if tracing.IsEnabled() {
    47  		ctx = tracing.StartSpan(ctx, fqdn+"/ProtectedItemOperationStatusesClient.Get")
    48  		defer func() {
    49  			sc := -1
    50  			if result.Response.Response != nil {
    51  				sc = result.Response.Response.StatusCode
    52  			}
    53  			tracing.EndSpan(ctx, sc, err)
    54  		}()
    55  	}
    56  	req, err := client.GetPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, protectedItemName, operationID)
    57  	if err != nil {
    58  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemOperationStatusesClient", "Get", nil, "Failure preparing request")
    59  		return
    60  	}
    61  
    62  	resp, err := client.GetSender(req)
    63  	if err != nil {
    64  		result.Response = autorest.Response{Response: resp}
    65  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemOperationStatusesClient", "Get", resp, "Failure sending request")
    66  		return
    67  	}
    68  
    69  	result, err = client.GetResponder(resp)
    70  	if err != nil {
    71  		err = autorest.NewErrorWithError(err, "backup.ProtectedItemOperationStatusesClient", "Get", resp, "Failure responding to request")
    72  		return
    73  	}
    74  
    75  	return
    76  }
    77  
    78  // GetPreparer prepares the Get request.
    79  func (client ProtectedItemOperationStatusesClient) GetPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, operationID string) (*http.Request, error) {
    80  	pathParameters := map[string]interface{}{
    81  		"containerName":     autorest.Encode("path", containerName),
    82  		"fabricName":        autorest.Encode("path", fabricName),
    83  		"operationId":       autorest.Encode("path", operationID),
    84  		"protectedItemName": autorest.Encode("path", protectedItemName),
    85  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    86  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    87  		"vaultName":         autorest.Encode("path", vaultName),
    88  	}
    89  
    90  	const APIVersion = "2021-07-01"
    91  	queryParameters := map[string]interface{}{
    92  		"api-version": APIVersion,
    93  	}
    94  
    95  	preparer := autorest.CreatePreparer(
    96  		autorest.AsGet(),
    97  		autorest.WithBaseURL(client.BaseURI),
    98  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}/operationsStatus/{operationId}", pathParameters),
    99  		autorest.WithQueryParameters(queryParameters))
   100  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   101  }
   102  
   103  // GetSender sends the Get request. The method will close the
   104  // http.Response Body if it receives an error.
   105  func (client ProtectedItemOperationStatusesClient) GetSender(req *http.Request) (*http.Response, error) {
   106  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   107  }
   108  
   109  // GetResponder handles the response to the Get request. The method always
   110  // closes the http.Response Body.
   111  func (client ProtectedItemOperationStatusesClient) GetResponder(resp *http.Response) (result OperationStatus, err error) {
   112  	err = autorest.Respond(
   113  		resp,
   114  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   115  		autorest.ByUnmarshallingJSON(&result),
   116  		autorest.ByClosing())
   117  	result.Response = autorest.Response{Response: resp}
   118  	return
   119  }
   120  

View as plain text