...

Source file src/github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2022-03-01/backup/restores.go

Documentation: github.com/Azure/azure-sdk-for-go/services/recoveryservices/mgmt/2022-03-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  // 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 RestoresTriggerFuture, err error) {
    45  	if tracing.IsEnabled() {
    46  		ctx = tracing.StartSpan(ctx, fqdn+"/RestoresClient.Trigger")
    47  		defer func() {
    48  			sc := -1
    49  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
    50  				sc = result.FutureAPI.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  	result, err = client.TriggerSender(req)
    62  	if err != nil {
    63  		err = autorest.NewErrorWithError(err, "backup.RestoresClient", "Trigger", result.Response(), "Failure sending request")
    64  		return
    65  	}
    66  
    67  	return
    68  }
    69  
    70  // TriggerPreparer prepares the Trigger request.
    71  func (client RestoresClient) TriggerPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, recoveryPointID string, parameters RestoreRequestResource) (*http.Request, error) {
    72  	pathParameters := map[string]interface{}{
    73  		"containerName":     autorest.Encode("path", containerName),
    74  		"fabricName":        autorest.Encode("path", fabricName),
    75  		"protectedItemName": autorest.Encode("path", protectedItemName),
    76  		"recoveryPointId":   autorest.Encode("path", recoveryPointID),
    77  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
    78  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
    79  		"vaultName":         autorest.Encode("path", vaultName),
    80  	}
    81  
    82  	const APIVersion = "2022-03-01"
    83  	queryParameters := map[string]interface{}{
    84  		"api-version": APIVersion,
    85  	}
    86  
    87  	preparer := autorest.CreatePreparer(
    88  		autorest.AsContentType("application/json; charset=utf-8"),
    89  		autorest.AsPost(),
    90  		autorest.WithBaseURL(client.BaseURI),
    91  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}/recoveryPoints/{recoveryPointId}/restore", pathParameters),
    92  		autorest.WithJSON(parameters),
    93  		autorest.WithQueryParameters(queryParameters))
    94  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
    95  }
    96  
    97  // TriggerSender sends the Trigger request. The method will close the
    98  // http.Response Body if it receives an error.
    99  func (client RestoresClient) TriggerSender(req *http.Request) (future RestoresTriggerFuture, err error) {
   100  	var resp *http.Response
   101  	future.FutureAPI = &azure.Future{}
   102  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   103  	if err != nil {
   104  		return
   105  	}
   106  	var azf azure.Future
   107  	azf, err = azure.NewFutureFromResponse(resp)
   108  	future.FutureAPI = &azf
   109  	future.Result = future.result
   110  	return
   111  }
   112  
   113  // TriggerResponder handles the response to the Trigger request. The method always
   114  // closes the http.Response Body.
   115  func (client RestoresClient) TriggerResponder(resp *http.Response) (result autorest.Response, err error) {
   116  	err = autorest.Respond(
   117  		resp,
   118  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   119  		autorest.ByClosing())
   120  	result.Response = resp
   121  	return
   122  }
   123  

View as plain text