1 package siterecovery
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
19 type ReplicationProtectionIntentsClient struct {
20 BaseClient
21 }
22
23
24 func NewReplicationProtectionIntentsClient(subscriptionID string, resourceGroupName string, resourceName string) ReplicationProtectionIntentsClient {
25 return NewReplicationProtectionIntentsClientWithBaseURI(DefaultBaseURI, subscriptionID, resourceGroupName, resourceName)
26 }
27
28
29
30
31 func NewReplicationProtectionIntentsClientWithBaseURI(baseURI string, subscriptionID string, resourceGroupName string, resourceName string) ReplicationProtectionIntentsClient {
32 return ReplicationProtectionIntentsClient{NewWithBaseURI(baseURI, subscriptionID, resourceGroupName, resourceName)}
33 }
34
35
36
37
38
39 func (client ReplicationProtectionIntentsClient) Create(ctx context.Context, intentObjectName string, input CreateProtectionIntentInput) (result ReplicationProtectionIntent, err error) {
40 if tracing.IsEnabled() {
41 ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionIntentsClient.Create")
42 defer func() {
43 sc := -1
44 if result.Response.Response != nil {
45 sc = result.Response.Response.StatusCode
46 }
47 tracing.EndSpan(ctx, sc, err)
48 }()
49 }
50 req, err := client.CreatePreparer(ctx, intentObjectName, input)
51 if err != nil {
52 err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionIntentsClient", "Create", nil, "Failure preparing request")
53 return
54 }
55
56 resp, err := client.CreateSender(req)
57 if err != nil {
58 result.Response = autorest.Response{Response: resp}
59 err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionIntentsClient", "Create", resp, "Failure sending request")
60 return
61 }
62
63 result, err = client.CreateResponder(resp)
64 if err != nil {
65 err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionIntentsClient", "Create", resp, "Failure responding to request")
66 return
67 }
68
69 return
70 }
71
72
73 func (client ReplicationProtectionIntentsClient) CreatePreparer(ctx context.Context, intentObjectName string, input CreateProtectionIntentInput) (*http.Request, error) {
74 pathParameters := map[string]interface{}{
75 "intentObjectName": autorest.Encode("path", intentObjectName),
76 "resourceGroupName": autorest.Encode("path", client.ResourceGroupName),
77 "resourceName": autorest.Encode("path", client.ResourceName),
78 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
79 }
80
81 const APIVersion = "2018-07-10"
82 queryParameters := map[string]interface{}{
83 "api-version": APIVersion,
84 }
85
86 preparer := autorest.CreatePreparer(
87 autorest.AsContentType("application/json; charset=utf-8"),
88 autorest.AsPut(),
89 autorest.WithBaseURL(client.BaseURI),
90 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationProtectionIntents/{intentObjectName}", pathParameters),
91 autorest.WithJSON(input),
92 autorest.WithQueryParameters(queryParameters))
93 return preparer.Prepare((&http.Request{}).WithContext(ctx))
94 }
95
96
97
98 func (client ReplicationProtectionIntentsClient) CreateSender(req *http.Request) (*http.Response, error) {
99 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
100 }
101
102
103
104 func (client ReplicationProtectionIntentsClient) CreateResponder(resp *http.Response) (result ReplicationProtectionIntent, err error) {
105 err = autorest.Respond(
106 resp,
107 azure.WithErrorUnlessStatusCode(http.StatusOK),
108 autorest.ByUnmarshallingJSON(&result),
109 autorest.ByClosing())
110 result.Response = autorest.Response{Response: resp}
111 return
112 }
113
114
115
116
117 func (client ReplicationProtectionIntentsClient) Get(ctx context.Context, intentObjectName string) (result ReplicationProtectionIntent, err error) {
118 if tracing.IsEnabled() {
119 ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionIntentsClient.Get")
120 defer func() {
121 sc := -1
122 if result.Response.Response != nil {
123 sc = result.Response.Response.StatusCode
124 }
125 tracing.EndSpan(ctx, sc, err)
126 }()
127 }
128 req, err := client.GetPreparer(ctx, intentObjectName)
129 if err != nil {
130 err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionIntentsClient", "Get", nil, "Failure preparing request")
131 return
132 }
133
134 resp, err := client.GetSender(req)
135 if err != nil {
136 result.Response = autorest.Response{Response: resp}
137 err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionIntentsClient", "Get", resp, "Failure sending request")
138 return
139 }
140
141 result, err = client.GetResponder(resp)
142 if err != nil {
143 err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionIntentsClient", "Get", resp, "Failure responding to request")
144 return
145 }
146
147 return
148 }
149
150
151 func (client ReplicationProtectionIntentsClient) GetPreparer(ctx context.Context, intentObjectName string) (*http.Request, error) {
152 pathParameters := map[string]interface{}{
153 "intentObjectName": autorest.Encode("path", intentObjectName),
154 "resourceGroupName": autorest.Encode("path", client.ResourceGroupName),
155 "resourceName": autorest.Encode("path", client.ResourceName),
156 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
157 }
158
159 const APIVersion = "2018-07-10"
160 queryParameters := map[string]interface{}{
161 "api-version": APIVersion,
162 }
163
164 preparer := autorest.CreatePreparer(
165 autorest.AsGet(),
166 autorest.WithBaseURL(client.BaseURI),
167 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationProtectionIntents/{intentObjectName}", pathParameters),
168 autorest.WithQueryParameters(queryParameters))
169 return preparer.Prepare((&http.Request{}).WithContext(ctx))
170 }
171
172
173
174 func (client ReplicationProtectionIntentsClient) GetSender(req *http.Request) (*http.Response, error) {
175 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
176 }
177
178
179
180 func (client ReplicationProtectionIntentsClient) GetResponder(resp *http.Response) (result ReplicationProtectionIntent, err error) {
181 err = autorest.Respond(
182 resp,
183 azure.WithErrorUnlessStatusCode(http.StatusOK),
184 autorest.ByUnmarshallingJSON(&result),
185 autorest.ByClosing())
186 result.Response = autorest.Response{Response: resp}
187 return
188 }
189
190
191 func (client ReplicationProtectionIntentsClient) List(ctx context.Context) (result ReplicationProtectionIntentCollectionPage, err error) {
192 if tracing.IsEnabled() {
193 ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionIntentsClient.List")
194 defer func() {
195 sc := -1
196 if result.rpic.Response.Response != nil {
197 sc = result.rpic.Response.Response.StatusCode
198 }
199 tracing.EndSpan(ctx, sc, err)
200 }()
201 }
202 result.fn = client.listNextResults
203 req, err := client.ListPreparer(ctx)
204 if err != nil {
205 err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionIntentsClient", "List", nil, "Failure preparing request")
206 return
207 }
208
209 resp, err := client.ListSender(req)
210 if err != nil {
211 result.rpic.Response = autorest.Response{Response: resp}
212 err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionIntentsClient", "List", resp, "Failure sending request")
213 return
214 }
215
216 result.rpic, err = client.ListResponder(resp)
217 if err != nil {
218 err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionIntentsClient", "List", resp, "Failure responding to request")
219 return
220 }
221 if result.rpic.hasNextLink() && result.rpic.IsEmpty() {
222 err = result.NextWithContext(ctx)
223 return
224 }
225
226 return
227 }
228
229
230 func (client ReplicationProtectionIntentsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
231 pathParameters := map[string]interface{}{
232 "resourceGroupName": autorest.Encode("path", client.ResourceGroupName),
233 "resourceName": autorest.Encode("path", client.ResourceName),
234 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
235 }
236
237 const APIVersion = "2018-07-10"
238 queryParameters := map[string]interface{}{
239 "api-version": APIVersion,
240 }
241
242 preparer := autorest.CreatePreparer(
243 autorest.AsGet(),
244 autorest.WithBaseURL(client.BaseURI),
245 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.RecoveryServices/vaults/{resourceName}/replicationProtectionIntents", pathParameters),
246 autorest.WithQueryParameters(queryParameters))
247 return preparer.Prepare((&http.Request{}).WithContext(ctx))
248 }
249
250
251
252 func (client ReplicationProtectionIntentsClient) ListSender(req *http.Request) (*http.Response, error) {
253 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
254 }
255
256
257
258 func (client ReplicationProtectionIntentsClient) ListResponder(resp *http.Response) (result ReplicationProtectionIntentCollection, err error) {
259 err = autorest.Respond(
260 resp,
261 azure.WithErrorUnlessStatusCode(http.StatusOK),
262 autorest.ByUnmarshallingJSON(&result),
263 autorest.ByClosing())
264 result.Response = autorest.Response{Response: resp}
265 return
266 }
267
268
269 func (client ReplicationProtectionIntentsClient) listNextResults(ctx context.Context, lastResults ReplicationProtectionIntentCollection) (result ReplicationProtectionIntentCollection, err error) {
270 req, err := lastResults.replicationProtectionIntentCollectionPreparer(ctx)
271 if err != nil {
272 return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionIntentsClient", "listNextResults", nil, "Failure preparing next results request")
273 }
274 if req == nil {
275 return
276 }
277 resp, err := client.ListSender(req)
278 if err != nil {
279 result.Response = autorest.Response{Response: resp}
280 return result, autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionIntentsClient", "listNextResults", resp, "Failure sending next results request")
281 }
282 result, err = client.ListResponder(resp)
283 if err != nil {
284 err = autorest.NewErrorWithError(err, "siterecovery.ReplicationProtectionIntentsClient", "listNextResults", resp, "Failure responding to next results request")
285 }
286 return
287 }
288
289
290 func (client ReplicationProtectionIntentsClient) ListComplete(ctx context.Context) (result ReplicationProtectionIntentCollectionIterator, err error) {
291 if tracing.IsEnabled() {
292 ctx = tracing.StartSpan(ctx, fqdn+"/ReplicationProtectionIntentsClient.List")
293 defer func() {
294 sc := -1
295 if result.Response().Response.Response != nil {
296 sc = result.page.Response().Response.Response.StatusCode
297 }
298 tracing.EndSpan(ctx, sc, err)
299 }()
300 }
301 result.page, err = client.List(ctx)
302 return
303 }
304
View as plain text