1package backup 2 3// Copyright (c) Microsoft and contributors. All rights reserved. 4// 5// Licensed under the Apache License, Version 2.0 (the "License"); 6// you may not use this file except in compliance with the License. 7// You may obtain a copy of the License at 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// 14// See the License for the specific language governing permissions and 15// limitations under the License. 16// 17// Code generated by Microsoft (R) AutoRest Code Generator. 18// Changes may cause incorrect behavior and will be lost if the code is regenerated. 19 20import ( 21 "context" 22 "github.com/Azure/go-autorest/autorest" 23 "github.com/Azure/go-autorest/autorest/azure" 24 "net/http" 25) 26 27// RestoresClient is the open API 2.0 Specs for Azure RecoveryServices Backup service 28type RestoresClient struct { 29 BaseClient 30} 31 32// NewRestoresClient creates an instance of the RestoresClient client. 33func NewRestoresClient(subscriptionID string) RestoresClient { 34 return NewRestoresClientWithBaseURI(DefaultBaseURI, subscriptionID) 35} 36 37// NewRestoresClientWithBaseURI creates an instance of the RestoresClient client. 38func NewRestoresClientWithBaseURI(baseURI string, subscriptionID string) RestoresClient { 39 return RestoresClient{NewWithBaseURI(baseURI, subscriptionID)} 40} 41 42// Trigger restores the specified backed up data. This is an asynchronous operation. To know the status of this API 43// call, use 44// GetProtectedItemOperationResult API. 45// Parameters: 46// vaultName - the name of the recovery services vault. 47// resourceGroupName - the name of the resource group where the recovery services vault is present. 48// fabricName - fabric name associated with the backed up items. 49// containerName - container name associated with the backed up items. 50// protectedItemName - backed up item to be restored. 51// recoveryPointID - recovery point ID which represents the backed up data to be restored. 52// parameters - resource restore request 53func (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) { 54 req, err := client.TriggerPreparer(ctx, vaultName, resourceGroupName, fabricName, containerName, protectedItemName, recoveryPointID, parameters) 55 if err != nil { 56 err = autorest.NewErrorWithError(err, "backup.RestoresClient", "Trigger", nil, "Failure preparing request") 57 return 58 } 59 60 resp, err := client.TriggerSender(req) 61 if err != nil { 62 result.Response = resp 63 err = autorest.NewErrorWithError(err, "backup.RestoresClient", "Trigger", resp, "Failure sending request") 64 return 65 } 66 67 result, err = client.TriggerResponder(resp) 68 if err != nil { 69 err = autorest.NewErrorWithError(err, "backup.RestoresClient", "Trigger", resp, "Failure responding to request") 70 } 71 72 return 73} 74 75// TriggerPreparer prepares the Trigger request. 76func (client RestoresClient) TriggerPreparer(ctx context.Context, vaultName string, resourceGroupName string, fabricName string, containerName string, protectedItemName string, recoveryPointID string, parameters RestoreRequestResource) (*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 "recoveryPointId": autorest.Encode("path", recoveryPointID), 82 "resourceGroupName": autorest.Encode("path", resourceGroupName), 83 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 84 "vaultName": autorest.Encode("path", vaultName), 85 } 86 87 const APIVersion = "2016-12-01" 88 queryParameters := map[string]interface{}{ 89 "api-version": APIVersion, 90 } 91 92 preparer := autorest.CreatePreparer( 93 autorest.AsContentType("application/json; charset=utf-8"), 94 autorest.AsPost(), 95 autorest.WithBaseURL(client.BaseURI), 96 autorest.WithPathParameters("/Subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{vaultName}/backupFabrics/{fabricName}/protectionContainers/{containerName}/protectedItems/{protectedItemName}/recoveryPoints/{recoveryPointId}/restore", pathParameters), 97 autorest.WithJSON(parameters), 98 autorest.WithQueryParameters(queryParameters)) 99 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 100} 101 102// TriggerSender sends the Trigger request. The method will close the 103// http.Response Body if it receives an error. 104func (client RestoresClient) TriggerSender(req *http.Request) (*http.Response, error) { 105 return autorest.SendWithSender(client, req, 106 azure.DoRetryWithRegistration(client.Client)) 107} 108 109// TriggerResponder handles the response to the Trigger request. The method always 110// closes the http.Response Body. 111func (client RestoresClient) TriggerResponder(resp *http.Response) (result autorest.Response, err error) { 112 err = autorest.Respond( 113 resp, 114 client.ByInspecting(), 115 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 116 autorest.ByClosing()) 117 result.Response = resp 118 return 119} 120