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 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
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-05-13"
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
105
106 func (client RestoresClient) TriggerSender(req *http.Request) (*http.Response, error) {
107 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
108 }
109
110
111
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