...

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

View as plain text