1 package backup
2
3
4
5
6
7
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
18 type RestoresClient struct {
19 BaseClient
20 }
21
22
23 func NewRestoresClient(subscriptionID string) RestoresClient {
24 return NewRestoresClientWithBaseURI(DefaultBaseURI, subscriptionID)
25 }
26
27
28
29 func NewRestoresClientWithBaseURI(baseURI string, subscriptionID string) RestoresClient {
30 return RestoresClient{NewWithBaseURI(baseURI, subscriptionID)}
31 }
32
33
34
35
36
37
38
39
40
41
42
43
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
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 = "2021-12-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
98
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
114
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