1package 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 9import ( 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 18type RestoresClient struct { 19 BaseClient 20} 21 22// NewRestoresClient creates an instance of the RestoresClient client. 23func 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). 29func 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 44func (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", nil, "Failure sending request") 64 return 65 } 66 67 return 68} 69 70// TriggerPreparer prepares the Trigger request. 71func (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 = "2021-01-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. 99func (client RestoresClient) TriggerSender(req *http.Request) (future RestoresTriggerFuture, err error) { 100 var resp *http.Response 101 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 102 if err != nil { 103 return 104 } 105 var azf azure.Future 106 azf, err = azure.NewFutureFromResponse(resp) 107 future.FutureAPI = &azf 108 future.Result = future.result 109 return 110} 111 112// TriggerResponder handles the response to the Trigger request. The method always 113// closes the http.Response Body. 114func (client RestoresClient) TriggerResponder(resp *http.Response) (result autorest.Response, err error) { 115 err = autorest.Respond( 116 resp, 117 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 118 autorest.ByClosing()) 119 result.Response = resp 120 return 121} 122