...

Source file src/github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2019-05-13/backup/backups.go

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2019-05-13/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  // BackupsClient is the open API 2.0 Specs for Azure RecoveryServices Backup service
    18  type BackupsClient struct {
    19  	BaseClient
    20  }
    21  
    22  // NewBackupsClient creates an instance of the BackupsClient client.
    23  func NewBackupsClient(subscriptionID string) BackupsClient {
    24  	return NewBackupsClientWithBaseURI(DefaultBaseURI, subscriptionID)
    25  }
    26  
    27  // NewBackupsClientWithBaseURI creates an instance of the BackupsClient client using a custom endpoint.  Use this when
    28  // interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
    29  func NewBackupsClientWithBaseURI(baseURI string, subscriptionID string) BackupsClient {
    30  	return BackupsClient{NewWithBaseURI(baseURI, subscriptionID)}
    31  }
    32  
    33  // Trigger triggers backup for specified backed up item. This is an asynchronous operation. To know the status of the
    34  // operation, call GetProtectedItemOperationResult API.
    35  // Parameters:
    36  // vaultName - the name of the recovery services vault.
    37  // resourceGroupName - the name of the resource group where the recovery services vault is present.
    38  // fabricName - fabric name associated with the backup item.
    39  // containerName - container name associated with the backup item.
    40  // protectedItemName - backup item for which backup needs to be triggered.
    41  // parameters - resource backup request
    42  func (client BackupsClient) Trigger(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, parameters RequestResource) (result autorest.Response, err error) {
    43  	if tracing.IsEnabled() {
    44  		ctx = tracing.StartSpan(ctx, fqdn+"/BackupsClient.Trigger")
    45  		defer func() {
    46  			sc := -1
    47  			if result.Response != nil {
    48  				sc = result.Response.StatusCode
    49  			}
    50  			tracing.EndSpan(ctx, sc, err)
    51  		}()
    52  	}
    53  	req, err := client.TriggerPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, protectedItemName, parameters)
    54  	if err != nil {
    55  		err = autorest.NewErrorWithError(err, "backup.BackupsClient", "Trigger", nil, "Failure preparing request")
    56  		return
    57  	}
    58  
    59  	resp, err := client.TriggerSender(req)
    60  	if err != nil {
    61  		result.Response = resp
    62  		err = autorest.NewErrorWithError(err, "backup.BackupsClient", "Trigger", resp, "Failure sending request")
    63  		return
    64  	}
    65  
    66  	result, err = client.TriggerResponder(resp)
    67  	if err != nil {
    68  		err = autorest.NewErrorWithError(err, "backup.BackupsClient", "Trigger", resp, "Failure responding to request")
    69  		return
    70  	}
    71  
    72  	return
    73  }
    74  
    75  // TriggerPreparer prepares the Trigger request.
    76  func (client BackupsClient) TriggerPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, parameters RequestResource) (*http.Request, error) {
    77  	pathParameters := map[string]interface{}{
    78  		"containerName":     autorest.Encode("path", containerName),
    79  		"fabricName":        autorest.Encode("path", fabricName),
    80  		"protectedItemName": autorest.Encode("path", protectedItemName),
    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-12-01"
    87  	queryParameters := map[string]interface{}{
    88  		"api-version": APIVersion,
    89  	}
    90  
    91  	preparer := autorest.CreatePreparer(
    92  		autorest.AsContentType("application/json; charset=utf-8"),
    93  		autorest.AsPost(),
    94  		autorest.WithBaseURL(client.BaseURI),
    95  		autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}/backup", pathParameters),
    96  		autorest.WithJSON(parameters),
    97  		autorest.WithQueryParameters(queryParameters))
    98  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    99  }
   100  
   101  // TriggerSender sends the Trigger request. The method will close the
   102  // http.Response Body if it receives an error.
   103  func (client BackupsClient) TriggerSender(req *http.Request) (*http.Response, error) {
   104  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   105  }
   106  
   107  // TriggerResponder handles the response to the Trigger request. The method always
   108  // closes the http.Response Body.
   109  func (client BackupsClient) TriggerResponder(resp *http.Response) (result autorest.Response, err error) {
   110  	err = autorest.Respond(
   111  		resp,
   112  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   113  		autorest.ByClosing())
   114  	result.Response = resp
   115  	return
   116  }
   117  

View as plain text