1 package postgresqlflexibleservers
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/autorest/validation"
14 "github.com/Azure/go-autorest/tracing"
15 "net/http"
16 )
17
18
19
20
21 type ServersClient struct {
22 BaseClient
23 }
24
25
26 func NewServersClient(subscriptionID string) ServersClient {
27 return NewServersClientWithBaseURI(DefaultBaseURI, subscriptionID)
28 }
29
30
31
32 func NewServersClientWithBaseURI(baseURI string, subscriptionID string) ServersClient {
33 return ServersClient{NewWithBaseURI(baseURI, subscriptionID)}
34 }
35
36
37
38
39
40
41 func (client ServersClient) Create(ctx context.Context, resourceGroupName string, serverName string, parameters Server) (result ServersCreateFuture, err error) {
42 if tracing.IsEnabled() {
43 ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Create")
44 defer func() {
45 sc := -1
46 if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
47 sc = result.FutureAPI.Response().StatusCode
48 }
49 tracing.EndSpan(ctx, sc, err)
50 }()
51 }
52 if err := validation.Validate([]validation.Validation{
53 {TargetValue: client.SubscriptionID,
54 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
55 {TargetValue: resourceGroupName,
56 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
57 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
58 {TargetValue: parameters,
59 Constraints: []validation.Constraint{{Target: "parameters.Sku", Name: validation.Null, Rule: false,
60 Chain: []validation.Constraint{{Target: "parameters.Sku.Name", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil {
61 return result, validation.NewError("postgresqlflexibleservers.ServersClient", "Create", err.Error())
62 }
63
64 req, err := client.CreatePreparer(ctx, resourceGroupName, serverName, parameters)
65 if err != nil {
66 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Create", nil, "Failure preparing request")
67 return
68 }
69
70 result, err = client.CreateSender(req)
71 if err != nil {
72 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Create", result.Response(), "Failure sending request")
73 return
74 }
75
76 return
77 }
78
79
80 func (client ServersClient) CreatePreparer(ctx context.Context, resourceGroupName string, serverName string, parameters Server) (*http.Request, error) {
81 pathParameters := map[string]interface{}{
82 "resourceGroupName": autorest.Encode("path", resourceGroupName),
83 "serverName": autorest.Encode("path", serverName),
84 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
85 }
86
87 const APIVersion = "2021-06-01"
88 queryParameters := map[string]interface{}{
89 "api-version": APIVersion,
90 }
91
92 parameters.SystemData = nil
93 preparer := autorest.CreatePreparer(
94 autorest.AsContentType("application/json; charset=utf-8"),
95 autorest.AsPut(),
96 autorest.WithBaseURL(client.BaseURI),
97 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{serverName}", pathParameters),
98 autorest.WithJSON(parameters),
99 autorest.WithQueryParameters(queryParameters))
100 return preparer.Prepare((&http.Request{}).WithContext(ctx))
101 }
102
103
104
105 func (client ServersClient) CreateSender(req *http.Request) (future ServersCreateFuture, err error) {
106 var resp *http.Response
107 future.FutureAPI = &azure.Future{}
108 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
109 if err != nil {
110 return
111 }
112 var azf azure.Future
113 azf, err = azure.NewFutureFromResponse(resp)
114 future.FutureAPI = &azf
115 future.Result = future.result
116 return
117 }
118
119
120
121 func (client ServersClient) CreateResponder(resp *http.Response) (result Server, err error) {
122 err = autorest.Respond(
123 resp,
124 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted),
125 autorest.ByUnmarshallingJSON(&result),
126 autorest.ByClosing())
127 result.Response = autorest.Response{Response: resp}
128 return
129 }
130
131
132
133
134
135 func (client ServersClient) Delete(ctx context.Context, resourceGroupName string, serverName string) (result ServersDeleteFuture, err error) {
136 if tracing.IsEnabled() {
137 ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Delete")
138 defer func() {
139 sc := -1
140 if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
141 sc = result.FutureAPI.Response().StatusCode
142 }
143 tracing.EndSpan(ctx, sc, err)
144 }()
145 }
146 if err := validation.Validate([]validation.Validation{
147 {TargetValue: client.SubscriptionID,
148 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
149 {TargetValue: resourceGroupName,
150 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
151 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
152 return result, validation.NewError("postgresqlflexibleservers.ServersClient", "Delete", err.Error())
153 }
154
155 req, err := client.DeletePreparer(ctx, resourceGroupName, serverName)
156 if err != nil {
157 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Delete", nil, "Failure preparing request")
158 return
159 }
160
161 result, err = client.DeleteSender(req)
162 if err != nil {
163 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Delete", result.Response(), "Failure sending request")
164 return
165 }
166
167 return
168 }
169
170
171 func (client ServersClient) DeletePreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) {
172 pathParameters := map[string]interface{}{
173 "resourceGroupName": autorest.Encode("path", resourceGroupName),
174 "serverName": autorest.Encode("path", serverName),
175 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
176 }
177
178 const APIVersion = "2021-06-01"
179 queryParameters := map[string]interface{}{
180 "api-version": APIVersion,
181 }
182
183 preparer := autorest.CreatePreparer(
184 autorest.AsDelete(),
185 autorest.WithBaseURL(client.BaseURI),
186 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{serverName}", pathParameters),
187 autorest.WithQueryParameters(queryParameters))
188 return preparer.Prepare((&http.Request{}).WithContext(ctx))
189 }
190
191
192
193 func (client ServersClient) DeleteSender(req *http.Request) (future ServersDeleteFuture, err error) {
194 var resp *http.Response
195 future.FutureAPI = &azure.Future{}
196 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
197 if err != nil {
198 return
199 }
200 var azf azure.Future
201 azf, err = azure.NewFutureFromResponse(resp)
202 future.FutureAPI = &azf
203 future.Result = future.result
204 return
205 }
206
207
208
209 func (client ServersClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
210 err = autorest.Respond(
211 resp,
212 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
213 autorest.ByClosing())
214 result.Response = resp
215 return
216 }
217
218
219
220
221
222 func (client ServersClient) Get(ctx context.Context, resourceGroupName string, serverName string) (result Server, err error) {
223 if tracing.IsEnabled() {
224 ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Get")
225 defer func() {
226 sc := -1
227 if result.Response.Response != nil {
228 sc = result.Response.Response.StatusCode
229 }
230 tracing.EndSpan(ctx, sc, err)
231 }()
232 }
233 if err := validation.Validate([]validation.Validation{
234 {TargetValue: client.SubscriptionID,
235 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
236 {TargetValue: resourceGroupName,
237 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
238 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
239 return result, validation.NewError("postgresqlflexibleservers.ServersClient", "Get", err.Error())
240 }
241
242 req, err := client.GetPreparer(ctx, resourceGroupName, serverName)
243 if err != nil {
244 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Get", nil, "Failure preparing request")
245 return
246 }
247
248 resp, err := client.GetSender(req)
249 if err != nil {
250 result.Response = autorest.Response{Response: resp}
251 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Get", resp, "Failure sending request")
252 return
253 }
254
255 result, err = client.GetResponder(resp)
256 if err != nil {
257 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Get", resp, "Failure responding to request")
258 return
259 }
260
261 return
262 }
263
264
265 func (client ServersClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) {
266 pathParameters := map[string]interface{}{
267 "resourceGroupName": autorest.Encode("path", resourceGroupName),
268 "serverName": autorest.Encode("path", serverName),
269 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
270 }
271
272 const APIVersion = "2021-06-01"
273 queryParameters := map[string]interface{}{
274 "api-version": APIVersion,
275 }
276
277 preparer := autorest.CreatePreparer(
278 autorest.AsGet(),
279 autorest.WithBaseURL(client.BaseURI),
280 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{serverName}", pathParameters),
281 autorest.WithQueryParameters(queryParameters))
282 return preparer.Prepare((&http.Request{}).WithContext(ctx))
283 }
284
285
286
287 func (client ServersClient) GetSender(req *http.Request) (*http.Response, error) {
288 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
289 }
290
291
292
293 func (client ServersClient) GetResponder(resp *http.Response) (result Server, err error) {
294 err = autorest.Respond(
295 resp,
296 azure.WithErrorUnlessStatusCode(http.StatusOK),
297 autorest.ByUnmarshallingJSON(&result),
298 autorest.ByClosing())
299 result.Response = autorest.Response{Response: resp}
300 return
301 }
302
303
304 func (client ServersClient) List(ctx context.Context) (result ServerListResultPage, err error) {
305 if tracing.IsEnabled() {
306 ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.List")
307 defer func() {
308 sc := -1
309 if result.slr.Response.Response != nil {
310 sc = result.slr.Response.Response.StatusCode
311 }
312 tracing.EndSpan(ctx, sc, err)
313 }()
314 }
315 if err := validation.Validate([]validation.Validation{
316 {TargetValue: client.SubscriptionID,
317 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
318 return result, validation.NewError("postgresqlflexibleservers.ServersClient", "List", err.Error())
319 }
320
321 result.fn = client.listNextResults
322 req, err := client.ListPreparer(ctx)
323 if err != nil {
324 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "List", nil, "Failure preparing request")
325 return
326 }
327
328 resp, err := client.ListSender(req)
329 if err != nil {
330 result.slr.Response = autorest.Response{Response: resp}
331 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "List", resp, "Failure sending request")
332 return
333 }
334
335 result.slr, err = client.ListResponder(resp)
336 if err != nil {
337 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "List", resp, "Failure responding to request")
338 return
339 }
340 if result.slr.hasNextLink() && result.slr.IsEmpty() {
341 err = result.NextWithContext(ctx)
342 return
343 }
344
345 return
346 }
347
348
349 func (client ServersClient) ListPreparer(ctx context.Context) (*http.Request, error) {
350 pathParameters := map[string]interface{}{
351 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
352 }
353
354 const APIVersion = "2021-06-01"
355 queryParameters := map[string]interface{}{
356 "api-version": APIVersion,
357 }
358
359 preparer := autorest.CreatePreparer(
360 autorest.AsGet(),
361 autorest.WithBaseURL(client.BaseURI),
362 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DBforPostgreSQL/flexibleServers", pathParameters),
363 autorest.WithQueryParameters(queryParameters))
364 return preparer.Prepare((&http.Request{}).WithContext(ctx))
365 }
366
367
368
369 func (client ServersClient) ListSender(req *http.Request) (*http.Response, error) {
370 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
371 }
372
373
374
375 func (client ServersClient) ListResponder(resp *http.Response) (result ServerListResult, err error) {
376 err = autorest.Respond(
377 resp,
378 azure.WithErrorUnlessStatusCode(http.StatusOK),
379 autorest.ByUnmarshallingJSON(&result),
380 autorest.ByClosing())
381 result.Response = autorest.Response{Response: resp}
382 return
383 }
384
385
386 func (client ServersClient) listNextResults(ctx context.Context, lastResults ServerListResult) (result ServerListResult, err error) {
387 req, err := lastResults.serverListResultPreparer(ctx)
388 if err != nil {
389 return result, autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "listNextResults", nil, "Failure preparing next results request")
390 }
391 if req == nil {
392 return
393 }
394 resp, err := client.ListSender(req)
395 if err != nil {
396 result.Response = autorest.Response{Response: resp}
397 return result, autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "listNextResults", resp, "Failure sending next results request")
398 }
399 result, err = client.ListResponder(resp)
400 if err != nil {
401 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "listNextResults", resp, "Failure responding to next results request")
402 }
403 return
404 }
405
406
407 func (client ServersClient) ListComplete(ctx context.Context) (result ServerListResultIterator, err error) {
408 if tracing.IsEnabled() {
409 ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.List")
410 defer func() {
411 sc := -1
412 if result.Response().Response.Response != nil {
413 sc = result.page.Response().Response.Response.StatusCode
414 }
415 tracing.EndSpan(ctx, sc, err)
416 }()
417 }
418 result.page, err = client.List(ctx)
419 return
420 }
421
422
423
424
425 func (client ServersClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result ServerListResultPage, err error) {
426 if tracing.IsEnabled() {
427 ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.ListByResourceGroup")
428 defer func() {
429 sc := -1
430 if result.slr.Response.Response != nil {
431 sc = result.slr.Response.Response.StatusCode
432 }
433 tracing.EndSpan(ctx, sc, err)
434 }()
435 }
436 if err := validation.Validate([]validation.Validation{
437 {TargetValue: client.SubscriptionID,
438 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
439 {TargetValue: resourceGroupName,
440 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
441 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
442 return result, validation.NewError("postgresqlflexibleservers.ServersClient", "ListByResourceGroup", err.Error())
443 }
444
445 result.fn = client.listByResourceGroupNextResults
446 req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
447 if err != nil {
448 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "ListByResourceGroup", nil, "Failure preparing request")
449 return
450 }
451
452 resp, err := client.ListByResourceGroupSender(req)
453 if err != nil {
454 result.slr.Response = autorest.Response{Response: resp}
455 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "ListByResourceGroup", resp, "Failure sending request")
456 return
457 }
458
459 result.slr, err = client.ListByResourceGroupResponder(resp)
460 if err != nil {
461 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "ListByResourceGroup", resp, "Failure responding to request")
462 return
463 }
464 if result.slr.hasNextLink() && result.slr.IsEmpty() {
465 err = result.NextWithContext(ctx)
466 return
467 }
468
469 return
470 }
471
472
473 func (client ServersClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
474 pathParameters := map[string]interface{}{
475 "resourceGroupName": autorest.Encode("path", resourceGroupName),
476 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
477 }
478
479 const APIVersion = "2021-06-01"
480 queryParameters := map[string]interface{}{
481 "api-version": APIVersion,
482 }
483
484 preparer := autorest.CreatePreparer(
485 autorest.AsGet(),
486 autorest.WithBaseURL(client.BaseURI),
487 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/flexibleServers", pathParameters),
488 autorest.WithQueryParameters(queryParameters))
489 return preparer.Prepare((&http.Request{}).WithContext(ctx))
490 }
491
492
493
494 func (client ServersClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
495 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
496 }
497
498
499
500 func (client ServersClient) ListByResourceGroupResponder(resp *http.Response) (result ServerListResult, err error) {
501 err = autorest.Respond(
502 resp,
503 azure.WithErrorUnlessStatusCode(http.StatusOK),
504 autorest.ByUnmarshallingJSON(&result),
505 autorest.ByClosing())
506 result.Response = autorest.Response{Response: resp}
507 return
508 }
509
510
511 func (client ServersClient) listByResourceGroupNextResults(ctx context.Context, lastResults ServerListResult) (result ServerListResult, err error) {
512 req, err := lastResults.serverListResultPreparer(ctx)
513 if err != nil {
514 return result, autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request")
515 }
516 if req == nil {
517 return
518 }
519 resp, err := client.ListByResourceGroupSender(req)
520 if err != nil {
521 result.Response = autorest.Response{Response: resp}
522 return result, autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "listByResourceGroupNextResults", resp, "Failure sending next results request")
523 }
524 result, err = client.ListByResourceGroupResponder(resp)
525 if err != nil {
526 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request")
527 }
528 return
529 }
530
531
532 func (client ServersClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result ServerListResultIterator, err error) {
533 if tracing.IsEnabled() {
534 ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.ListByResourceGroup")
535 defer func() {
536 sc := -1
537 if result.Response().Response.Response != nil {
538 sc = result.page.Response().Response.Response.StatusCode
539 }
540 tracing.EndSpan(ctx, sc, err)
541 }()
542 }
543 result.page, err = client.ListByResourceGroup(ctx, resourceGroupName)
544 return
545 }
546
547
548
549
550
551
552 func (client ServersClient) Restart(ctx context.Context, resourceGroupName string, serverName string, parameters *RestartParameter) (result ServersRestartFuture, err error) {
553 if tracing.IsEnabled() {
554 ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Restart")
555 defer func() {
556 sc := -1
557 if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
558 sc = result.FutureAPI.Response().StatusCode
559 }
560 tracing.EndSpan(ctx, sc, err)
561 }()
562 }
563 if err := validation.Validate([]validation.Validation{
564 {TargetValue: client.SubscriptionID,
565 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
566 {TargetValue: resourceGroupName,
567 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
568 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
569 return result, validation.NewError("postgresqlflexibleservers.ServersClient", "Restart", err.Error())
570 }
571
572 req, err := client.RestartPreparer(ctx, resourceGroupName, serverName, parameters)
573 if err != nil {
574 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Restart", nil, "Failure preparing request")
575 return
576 }
577
578 result, err = client.RestartSender(req)
579 if err != nil {
580 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Restart", result.Response(), "Failure sending request")
581 return
582 }
583
584 return
585 }
586
587
588 func (client ServersClient) RestartPreparer(ctx context.Context, resourceGroupName string, serverName string, parameters *RestartParameter) (*http.Request, error) {
589 pathParameters := map[string]interface{}{
590 "resourceGroupName": autorest.Encode("path", resourceGroupName),
591 "serverName": autorest.Encode("path", serverName),
592 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
593 }
594
595 const APIVersion = "2021-06-01"
596 queryParameters := map[string]interface{}{
597 "api-version": APIVersion,
598 }
599
600 preparer := autorest.CreatePreparer(
601 autorest.AsContentType("application/json; charset=utf-8"),
602 autorest.AsPost(),
603 autorest.WithBaseURL(client.BaseURI),
604 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{serverName}/restart", pathParameters),
605 autorest.WithQueryParameters(queryParameters))
606 if parameters != nil {
607 preparer = autorest.DecoratePreparer(preparer,
608 autorest.WithJSON(parameters))
609 }
610 return preparer.Prepare((&http.Request{}).WithContext(ctx))
611 }
612
613
614
615 func (client ServersClient) RestartSender(req *http.Request) (future ServersRestartFuture, err error) {
616 var resp *http.Response
617 future.FutureAPI = &azure.Future{}
618 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
619 if err != nil {
620 return
621 }
622 var azf azure.Future
623 azf, err = azure.NewFutureFromResponse(resp)
624 future.FutureAPI = &azf
625 future.Result = future.result
626 return
627 }
628
629
630
631 func (client ServersClient) RestartResponder(resp *http.Response) (result autorest.Response, err error) {
632 err = autorest.Respond(
633 resp,
634 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
635 autorest.ByClosing())
636 result.Response = resp
637 return
638 }
639
640
641
642
643
644 func (client ServersClient) Start(ctx context.Context, resourceGroupName string, serverName string) (result ServersStartFuture, err error) {
645 if tracing.IsEnabled() {
646 ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Start")
647 defer func() {
648 sc := -1
649 if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
650 sc = result.FutureAPI.Response().StatusCode
651 }
652 tracing.EndSpan(ctx, sc, err)
653 }()
654 }
655 if err := validation.Validate([]validation.Validation{
656 {TargetValue: client.SubscriptionID,
657 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
658 {TargetValue: resourceGroupName,
659 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
660 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
661 return result, validation.NewError("postgresqlflexibleservers.ServersClient", "Start", err.Error())
662 }
663
664 req, err := client.StartPreparer(ctx, resourceGroupName, serverName)
665 if err != nil {
666 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Start", nil, "Failure preparing request")
667 return
668 }
669
670 result, err = client.StartSender(req)
671 if err != nil {
672 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Start", result.Response(), "Failure sending request")
673 return
674 }
675
676 return
677 }
678
679
680 func (client ServersClient) StartPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) {
681 pathParameters := map[string]interface{}{
682 "resourceGroupName": autorest.Encode("path", resourceGroupName),
683 "serverName": autorest.Encode("path", serverName),
684 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
685 }
686
687 const APIVersion = "2021-06-01"
688 queryParameters := map[string]interface{}{
689 "api-version": APIVersion,
690 }
691
692 preparer := autorest.CreatePreparer(
693 autorest.AsPost(),
694 autorest.WithBaseURL(client.BaseURI),
695 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{serverName}/start", pathParameters),
696 autorest.WithQueryParameters(queryParameters))
697 return preparer.Prepare((&http.Request{}).WithContext(ctx))
698 }
699
700
701
702 func (client ServersClient) StartSender(req *http.Request) (future ServersStartFuture, err error) {
703 var resp *http.Response
704 future.FutureAPI = &azure.Future{}
705 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
706 if err != nil {
707 return
708 }
709 var azf azure.Future
710 azf, err = azure.NewFutureFromResponse(resp)
711 future.FutureAPI = &azf
712 future.Result = future.result
713 return
714 }
715
716
717
718 func (client ServersClient) StartResponder(resp *http.Response) (result autorest.Response, err error) {
719 err = autorest.Respond(
720 resp,
721 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
722 autorest.ByClosing())
723 result.Response = resp
724 return
725 }
726
727
728
729
730
731 func (client ServersClient) Stop(ctx context.Context, resourceGroupName string, serverName string) (result ServersStopFuture, err error) {
732 if tracing.IsEnabled() {
733 ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Stop")
734 defer func() {
735 sc := -1
736 if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
737 sc = result.FutureAPI.Response().StatusCode
738 }
739 tracing.EndSpan(ctx, sc, err)
740 }()
741 }
742 if err := validation.Validate([]validation.Validation{
743 {TargetValue: client.SubscriptionID,
744 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
745 {TargetValue: resourceGroupName,
746 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
747 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
748 return result, validation.NewError("postgresqlflexibleservers.ServersClient", "Stop", err.Error())
749 }
750
751 req, err := client.StopPreparer(ctx, resourceGroupName, serverName)
752 if err != nil {
753 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Stop", nil, "Failure preparing request")
754 return
755 }
756
757 result, err = client.StopSender(req)
758 if err != nil {
759 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Stop", result.Response(), "Failure sending request")
760 return
761 }
762
763 return
764 }
765
766
767 func (client ServersClient) StopPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) {
768 pathParameters := map[string]interface{}{
769 "resourceGroupName": autorest.Encode("path", resourceGroupName),
770 "serverName": autorest.Encode("path", serverName),
771 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
772 }
773
774 const APIVersion = "2021-06-01"
775 queryParameters := map[string]interface{}{
776 "api-version": APIVersion,
777 }
778
779 preparer := autorest.CreatePreparer(
780 autorest.AsPost(),
781 autorest.WithBaseURL(client.BaseURI),
782 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{serverName}/stop", pathParameters),
783 autorest.WithQueryParameters(queryParameters))
784 return preparer.Prepare((&http.Request{}).WithContext(ctx))
785 }
786
787
788
789 func (client ServersClient) StopSender(req *http.Request) (future ServersStopFuture, err error) {
790 var resp *http.Response
791 future.FutureAPI = &azure.Future{}
792 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
793 if err != nil {
794 return
795 }
796 var azf azure.Future
797 azf, err = azure.NewFutureFromResponse(resp)
798 future.FutureAPI = &azf
799 future.Result = future.result
800 return
801 }
802
803
804
805 func (client ServersClient) StopResponder(resp *http.Response) (result autorest.Response, err error) {
806 err = autorest.Respond(
807 resp,
808 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
809 autorest.ByClosing())
810 result.Response = resp
811 return
812 }
813
814
815
816
817
818
819
820 func (client ServersClient) Update(ctx context.Context, resourceGroupName string, serverName string, parameters ServerForUpdate) (result ServersUpdateFuture, err error) {
821 if tracing.IsEnabled() {
822 ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Update")
823 defer func() {
824 sc := -1
825 if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
826 sc = result.FutureAPI.Response().StatusCode
827 }
828 tracing.EndSpan(ctx, sc, err)
829 }()
830 }
831 if err := validation.Validate([]validation.Validation{
832 {TargetValue: client.SubscriptionID,
833 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
834 {TargetValue: resourceGroupName,
835 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
836 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
837 return result, validation.NewError("postgresqlflexibleservers.ServersClient", "Update", err.Error())
838 }
839
840 req, err := client.UpdatePreparer(ctx, resourceGroupName, serverName, parameters)
841 if err != nil {
842 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Update", nil, "Failure preparing request")
843 return
844 }
845
846 result, err = client.UpdateSender(req)
847 if err != nil {
848 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Update", result.Response(), "Failure sending request")
849 return
850 }
851
852 return
853 }
854
855
856 func (client ServersClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, parameters ServerForUpdate) (*http.Request, error) {
857 pathParameters := map[string]interface{}{
858 "resourceGroupName": autorest.Encode("path", resourceGroupName),
859 "serverName": autorest.Encode("path", serverName),
860 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
861 }
862
863 const APIVersion = "2021-06-01"
864 queryParameters := map[string]interface{}{
865 "api-version": APIVersion,
866 }
867
868 preparer := autorest.CreatePreparer(
869 autorest.AsContentType("application/json; charset=utf-8"),
870 autorest.AsPatch(),
871 autorest.WithBaseURL(client.BaseURI),
872 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforPostgreSQL/flexibleServers/{serverName}", pathParameters),
873 autorest.WithJSON(parameters),
874 autorest.WithQueryParameters(queryParameters))
875 return preparer.Prepare((&http.Request{}).WithContext(ctx))
876 }
877
878
879
880 func (client ServersClient) UpdateSender(req *http.Request) (future ServersUpdateFuture, err error) {
881 var resp *http.Response
882 future.FutureAPI = &azure.Future{}
883 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
884 if err != nil {
885 return
886 }
887 var azf azure.Future
888 azf, err = azure.NewFutureFromResponse(resp)
889 future.FutureAPI = &azf
890 future.Result = future.result
891 return
892 }
893
894
895
896 func (client ServersClient) UpdateResponder(resp *http.Response) (result Server, err error) {
897 err = autorest.Respond(
898 resp,
899 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
900 autorest.ByUnmarshallingJSON(&result),
901 autorest.ByClosing())
902 result.Response = autorest.Response{Response: resp}
903 return
904 }
905
View as plain text