1package postgresqlflexibleservers 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// 6// Code generated by Microsoft (R) AutoRest Code Generator. 7// Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9import ( 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// ServersClient is the the Microsoft Azure management API provides create, read, update, and delete functionality for 19// Azure PostgreSQL resources including servers, databases, firewall rules, VNET rules, security alert policies, log 20// files and configurations with new business model. 21type ServersClient struct { 22 BaseClient 23} 24 25// NewServersClient creates an instance of the ServersClient client. 26func NewServersClient(subscriptionID string) ServersClient { 27 return NewServersClientWithBaseURI(DefaultBaseURI, subscriptionID) 28} 29 30// NewServersClientWithBaseURI creates an instance of the ServersClient client using a custom endpoint. Use this when 31// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 32func NewServersClientWithBaseURI(baseURI string, subscriptionID string) ServersClient { 33 return ServersClient{NewWithBaseURI(baseURI, subscriptionID)} 34} 35 36// Create creates a new server. 37// Parameters: 38// resourceGroupName - the name of the resource group. The name is case insensitive. 39// serverName - the name of the server. 40// parameters - the required parameters for creating or updating a server. 41func (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 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}, 59 {TargetValue: parameters, 60 Constraints: []validation.Constraint{{Target: "parameters.Sku", Name: validation.Null, Rule: false, 61 Chain: []validation.Constraint{{Target: "parameters.Sku.Name", Name: validation.Null, Rule: true, Chain: nil}}}}}}); err != nil { 62 return result, validation.NewError("postgresqlflexibleservers.ServersClient", "Create", err.Error()) 63 } 64 65 req, err := client.CreatePreparer(ctx, resourceGroupName, serverName, parameters) 66 if err != nil { 67 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Create", nil, "Failure preparing request") 68 return 69 } 70 71 result, err = client.CreateSender(req) 72 if err != nil { 73 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Create", nil, "Failure sending request") 74 return 75 } 76 77 return 78} 79 80// CreatePreparer prepares the Create request. 81func (client ServersClient) CreatePreparer(ctx context.Context, resourceGroupName string, serverName string, parameters Server) (*http.Request, error) { 82 pathParameters := map[string]interface{}{ 83 "resourceGroupName": autorest.Encode("path", resourceGroupName), 84 "serverName": autorest.Encode("path", serverName), 85 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 86 } 87 88 const APIVersion = "2020-02-14-preview" 89 queryParameters := map[string]interface{}{ 90 "api-version": APIVersion, 91 } 92 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// CreateSender sends the Create request. The method will close the 104// http.Response Body if it receives an error. 105func (client ServersClient) CreateSender(req *http.Request) (future ServersCreateFuture, err error) { 106 var resp *http.Response 107 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 108 if err != nil { 109 return 110 } 111 var azf azure.Future 112 azf, err = azure.NewFutureFromResponse(resp) 113 future.FutureAPI = &azf 114 future.Result = future.result 115 return 116} 117 118// CreateResponder handles the response to the Create request. The method always 119// closes the http.Response Body. 120func (client ServersClient) CreateResponder(resp *http.Response) (result Server, err error) { 121 err = autorest.Respond( 122 resp, 123 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted), 124 autorest.ByUnmarshallingJSON(&result), 125 autorest.ByClosing()) 126 result.Response = autorest.Response{Response: resp} 127 return 128} 129 130// Delete deletes a server. 131// Parameters: 132// resourceGroupName - the name of the resource group. The name is case insensitive. 133// serverName - the name of the server. 134func (client ServersClient) Delete(ctx context.Context, resourceGroupName string, serverName string) (result ServersDeleteFuture, err error) { 135 if tracing.IsEnabled() { 136 ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Delete") 137 defer func() { 138 sc := -1 139 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 140 sc = result.FutureAPI.Response().StatusCode 141 } 142 tracing.EndSpan(ctx, sc, err) 143 }() 144 } 145 if err := validation.Validate([]validation.Validation{ 146 {TargetValue: client.SubscriptionID, 147 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 148 {TargetValue: resourceGroupName, 149 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 150 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 151 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, 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", nil, "Failure sending request") 164 return 165 } 166 167 return 168} 169 170// DeletePreparer prepares the Delete request. 171func (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 = "2020-02-14-preview" 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// DeleteSender sends the Delete request. The method will close the 192// http.Response Body if it receives an error. 193func (client ServersClient) DeleteSender(req *http.Request) (future ServersDeleteFuture, err error) { 194 var resp *http.Response 195 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 196 if err != nil { 197 return 198 } 199 var azf azure.Future 200 azf, err = azure.NewFutureFromResponse(resp) 201 future.FutureAPI = &azf 202 future.Result = future.result 203 return 204} 205 206// DeleteResponder handles the response to the Delete request. The method always 207// closes the http.Response Body. 208func (client ServersClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 209 err = autorest.Respond( 210 resp, 211 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 212 autorest.ByClosing()) 213 result.Response = resp 214 return 215} 216 217// Get gets information about a server. 218// Parameters: 219// resourceGroupName - the name of the resource group. The name is case insensitive. 220// serverName - the name of the server. 221func (client ServersClient) Get(ctx context.Context, resourceGroupName string, serverName string) (result Server, err error) { 222 if tracing.IsEnabled() { 223 ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Get") 224 defer func() { 225 sc := -1 226 if result.Response.Response != nil { 227 sc = result.Response.Response.StatusCode 228 } 229 tracing.EndSpan(ctx, sc, err) 230 }() 231 } 232 if err := validation.Validate([]validation.Validation{ 233 {TargetValue: client.SubscriptionID, 234 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 235 {TargetValue: resourceGroupName, 236 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 237 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 238 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, 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// GetPreparer prepares the Get request. 265func (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 = "2020-02-14-preview" 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// GetSender sends the Get request. The method will close the 286// http.Response Body if it receives an error. 287func (client ServersClient) GetSender(req *http.Request) (*http.Response, error) { 288 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 289} 290 291// GetResponder handles the response to the Get request. The method always 292// closes the http.Response Body. 293func (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// List list all the servers in a given subscription. 304func (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// ListPreparer prepares the List request. 349func (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 = "2020-02-14-preview" 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// ListSender sends the List request. The method will close the 368// http.Response Body if it receives an error. 369func (client ServersClient) ListSender(req *http.Request) (*http.Response, error) { 370 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 371} 372 373// ListResponder handles the response to the List request. The method always 374// closes the http.Response Body. 375func (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// listNextResults retrieves the next set of results, if any. 386func (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// ListComplete enumerates all values, automatically crossing page boundaries as required. 407func (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// ListByResourceGroup list all the servers in a given resource group. 423// Parameters: 424// resourceGroupName - the name of the resource group. The name is case insensitive. 425func (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}, 442 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 443 return result, validation.NewError("postgresqlflexibleservers.ServersClient", "ListByResourceGroup", err.Error()) 444 } 445 446 result.fn = client.listByResourceGroupNextResults 447 req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName) 448 if err != nil { 449 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "ListByResourceGroup", nil, "Failure preparing request") 450 return 451 } 452 453 resp, err := client.ListByResourceGroupSender(req) 454 if err != nil { 455 result.slr.Response = autorest.Response{Response: resp} 456 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "ListByResourceGroup", resp, "Failure sending request") 457 return 458 } 459 460 result.slr, err = client.ListByResourceGroupResponder(resp) 461 if err != nil { 462 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "ListByResourceGroup", resp, "Failure responding to request") 463 return 464 } 465 if result.slr.hasNextLink() && result.slr.IsEmpty() { 466 err = result.NextWithContext(ctx) 467 return 468 } 469 470 return 471} 472 473// ListByResourceGroupPreparer prepares the ListByResourceGroup request. 474func (client ServersClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) { 475 pathParameters := map[string]interface{}{ 476 "resourceGroupName": autorest.Encode("path", resourceGroupName), 477 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 478 } 479 480 const APIVersion = "2020-02-14-preview" 481 queryParameters := map[string]interface{}{ 482 "api-version": APIVersion, 483 } 484 485 preparer := autorest.CreatePreparer( 486 autorest.AsGet(), 487 autorest.WithBaseURL(client.BaseURI), 488 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/flexibleServers", pathParameters), 489 autorest.WithQueryParameters(queryParameters)) 490 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 491} 492 493// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the 494// http.Response Body if it receives an error. 495func (client ServersClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) { 496 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 497} 498 499// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always 500// closes the http.Response Body. 501func (client ServersClient) ListByResourceGroupResponder(resp *http.Response) (result ServerListResult, err error) { 502 err = autorest.Respond( 503 resp, 504 azure.WithErrorUnlessStatusCode(http.StatusOK), 505 autorest.ByUnmarshallingJSON(&result), 506 autorest.ByClosing()) 507 result.Response = autorest.Response{Response: resp} 508 return 509} 510 511// listByResourceGroupNextResults retrieves the next set of results, if any. 512func (client ServersClient) listByResourceGroupNextResults(ctx context.Context, lastResults ServerListResult) (result ServerListResult, err error) { 513 req, err := lastResults.serverListResultPreparer(ctx) 514 if err != nil { 515 return result, autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request") 516 } 517 if req == nil { 518 return 519 } 520 resp, err := client.ListByResourceGroupSender(req) 521 if err != nil { 522 result.Response = autorest.Response{Response: resp} 523 return result, autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "listByResourceGroupNextResults", resp, "Failure sending next results request") 524 } 525 result, err = client.ListByResourceGroupResponder(resp) 526 if err != nil { 527 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request") 528 } 529 return 530} 531 532// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required. 533func (client ServersClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result ServerListResultIterator, err error) { 534 if tracing.IsEnabled() { 535 ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.ListByResourceGroup") 536 defer func() { 537 sc := -1 538 if result.Response().Response.Response != nil { 539 sc = result.page.Response().Response.Response.StatusCode 540 } 541 tracing.EndSpan(ctx, sc, err) 542 }() 543 } 544 result.page, err = client.ListByResourceGroup(ctx, resourceGroupName) 545 return 546} 547 548// Restart restarts a server. 549// Parameters: 550// resourceGroupName - the name of the resource group. The name is case insensitive. 551// serverName - the name of the server. 552func (client ServersClient) Restart(ctx context.Context, resourceGroupName string, serverName string) (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}, 569 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 570 return result, validation.NewError("postgresqlflexibleservers.ServersClient", "Restart", err.Error()) 571 } 572 573 req, err := client.RestartPreparer(ctx, resourceGroupName, serverName) 574 if err != nil { 575 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Restart", nil, "Failure preparing request") 576 return 577 } 578 579 result, err = client.RestartSender(req) 580 if err != nil { 581 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Restart", nil, "Failure sending request") 582 return 583 } 584 585 return 586} 587 588// RestartPreparer prepares the Restart request. 589func (client ServersClient) RestartPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) { 590 pathParameters := map[string]interface{}{ 591 "resourceGroupName": autorest.Encode("path", resourceGroupName), 592 "serverName": autorest.Encode("path", serverName), 593 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 594 } 595 596 const APIVersion = "2020-02-14-preview" 597 queryParameters := map[string]interface{}{ 598 "api-version": APIVersion, 599 } 600 601 preparer := autorest.CreatePreparer( 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 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 607} 608 609// RestartSender sends the Restart request. The method will close the 610// http.Response Body if it receives an error. 611func (client ServersClient) RestartSender(req *http.Request) (future ServersRestartFuture, err error) { 612 var resp *http.Response 613 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 614 if err != nil { 615 return 616 } 617 var azf azure.Future 618 azf, err = azure.NewFutureFromResponse(resp) 619 future.FutureAPI = &azf 620 future.Result = future.result 621 return 622} 623 624// RestartResponder handles the response to the Restart request. The method always 625// closes the http.Response Body. 626func (client ServersClient) RestartResponder(resp *http.Response) (result autorest.Response, err error) { 627 err = autorest.Respond( 628 resp, 629 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 630 autorest.ByClosing()) 631 result.Response = resp 632 return 633} 634 635// Start starts a server. 636// Parameters: 637// resourceGroupName - the name of the resource group. The name is case insensitive. 638// serverName - the name of the server. 639func (client ServersClient) Start(ctx context.Context, resourceGroupName string, serverName string) (result ServersStartFuture, err error) { 640 if tracing.IsEnabled() { 641 ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Start") 642 defer func() { 643 sc := -1 644 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 645 sc = result.FutureAPI.Response().StatusCode 646 } 647 tracing.EndSpan(ctx, sc, err) 648 }() 649 } 650 if err := validation.Validate([]validation.Validation{ 651 {TargetValue: client.SubscriptionID, 652 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 653 {TargetValue: resourceGroupName, 654 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 655 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 656 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 657 return result, validation.NewError("postgresqlflexibleservers.ServersClient", "Start", err.Error()) 658 } 659 660 req, err := client.StartPreparer(ctx, resourceGroupName, serverName) 661 if err != nil { 662 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Start", nil, "Failure preparing request") 663 return 664 } 665 666 result, err = client.StartSender(req) 667 if err != nil { 668 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Start", nil, "Failure sending request") 669 return 670 } 671 672 return 673} 674 675// StartPreparer prepares the Start request. 676func (client ServersClient) StartPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) { 677 pathParameters := map[string]interface{}{ 678 "resourceGroupName": autorest.Encode("path", resourceGroupName), 679 "serverName": autorest.Encode("path", serverName), 680 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 681 } 682 683 const APIVersion = "2020-02-14-preview" 684 queryParameters := map[string]interface{}{ 685 "api-version": APIVersion, 686 } 687 688 preparer := autorest.CreatePreparer( 689 autorest.AsPost(), 690 autorest.WithBaseURL(client.BaseURI), 691 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/flexibleServers/{serverName}/start", pathParameters), 692 autorest.WithQueryParameters(queryParameters)) 693 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 694} 695 696// StartSender sends the Start request. The method will close the 697// http.Response Body if it receives an error. 698func (client ServersClient) StartSender(req *http.Request) (future ServersStartFuture, err error) { 699 var resp *http.Response 700 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 701 if err != nil { 702 return 703 } 704 var azf azure.Future 705 azf, err = azure.NewFutureFromResponse(resp) 706 future.FutureAPI = &azf 707 future.Result = future.result 708 return 709} 710 711// StartResponder handles the response to the Start request. The method always 712// closes the http.Response Body. 713func (client ServersClient) StartResponder(resp *http.Response) (result autorest.Response, err error) { 714 err = autorest.Respond( 715 resp, 716 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 717 autorest.ByClosing()) 718 result.Response = resp 719 return 720} 721 722// Stop stops a server. 723// Parameters: 724// resourceGroupName - the name of the resource group. The name is case insensitive. 725// serverName - the name of the server. 726func (client ServersClient) Stop(ctx context.Context, resourceGroupName string, serverName string) (result ServersStopFuture, err error) { 727 if tracing.IsEnabled() { 728 ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Stop") 729 defer func() { 730 sc := -1 731 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 732 sc = result.FutureAPI.Response().StatusCode 733 } 734 tracing.EndSpan(ctx, sc, err) 735 }() 736 } 737 if err := validation.Validate([]validation.Validation{ 738 {TargetValue: client.SubscriptionID, 739 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 740 {TargetValue: resourceGroupName, 741 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 742 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 743 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 744 return result, validation.NewError("postgresqlflexibleservers.ServersClient", "Stop", err.Error()) 745 } 746 747 req, err := client.StopPreparer(ctx, resourceGroupName, serverName) 748 if err != nil { 749 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Stop", nil, "Failure preparing request") 750 return 751 } 752 753 result, err = client.StopSender(req) 754 if err != nil { 755 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Stop", nil, "Failure sending request") 756 return 757 } 758 759 return 760} 761 762// StopPreparer prepares the Stop request. 763func (client ServersClient) StopPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) { 764 pathParameters := map[string]interface{}{ 765 "resourceGroupName": autorest.Encode("path", resourceGroupName), 766 "serverName": autorest.Encode("path", serverName), 767 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 768 } 769 770 const APIVersion = "2020-02-14-preview" 771 queryParameters := map[string]interface{}{ 772 "api-version": APIVersion, 773 } 774 775 preparer := autorest.CreatePreparer( 776 autorest.AsPost(), 777 autorest.WithBaseURL(client.BaseURI), 778 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/flexibleServers/{serverName}/stop", pathParameters), 779 autorest.WithQueryParameters(queryParameters)) 780 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 781} 782 783// StopSender sends the Stop request. The method will close the 784// http.Response Body if it receives an error. 785func (client ServersClient) StopSender(req *http.Request) (future ServersStopFuture, err error) { 786 var resp *http.Response 787 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 788 if err != nil { 789 return 790 } 791 var azf azure.Future 792 azf, err = azure.NewFutureFromResponse(resp) 793 future.FutureAPI = &azf 794 future.Result = future.result 795 return 796} 797 798// StopResponder handles the response to the Stop request. The method always 799// closes the http.Response Body. 800func (client ServersClient) StopResponder(resp *http.Response) (result autorest.Response, err error) { 801 err = autorest.Respond( 802 resp, 803 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 804 autorest.ByClosing()) 805 result.Response = resp 806 return 807} 808 809// Update updates an existing server. The request body can contain one to many of the properties present in the normal 810// server definition. 811// Parameters: 812// resourceGroupName - the name of the resource group. The name is case insensitive. 813// serverName - the name of the server. 814// parameters - the required parameters for updating a server. 815func (client ServersClient) Update(ctx context.Context, resourceGroupName string, serverName string, parameters ServerForUpdate) (result ServersUpdateFuture, err error) { 816 if tracing.IsEnabled() { 817 ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Update") 818 defer func() { 819 sc := -1 820 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 821 sc = result.FutureAPI.Response().StatusCode 822 } 823 tracing.EndSpan(ctx, sc, err) 824 }() 825 } 826 if err := validation.Validate([]validation.Validation{ 827 {TargetValue: client.SubscriptionID, 828 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 829 {TargetValue: resourceGroupName, 830 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 831 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 832 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 833 return result, validation.NewError("postgresqlflexibleservers.ServersClient", "Update", err.Error()) 834 } 835 836 req, err := client.UpdatePreparer(ctx, resourceGroupName, serverName, parameters) 837 if err != nil { 838 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Update", nil, "Failure preparing request") 839 return 840 } 841 842 result, err = client.UpdateSender(req) 843 if err != nil { 844 err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Update", nil, "Failure sending request") 845 return 846 } 847 848 return 849} 850 851// UpdatePreparer prepares the Update request. 852func (client ServersClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, parameters ServerForUpdate) (*http.Request, error) { 853 pathParameters := map[string]interface{}{ 854 "resourceGroupName": autorest.Encode("path", resourceGroupName), 855 "serverName": autorest.Encode("path", serverName), 856 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 857 } 858 859 const APIVersion = "2020-02-14-preview" 860 queryParameters := map[string]interface{}{ 861 "api-version": APIVersion, 862 } 863 864 preparer := autorest.CreatePreparer( 865 autorest.AsContentType("application/json; charset=utf-8"), 866 autorest.AsPatch(), 867 autorest.WithBaseURL(client.BaseURI), 868 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/flexibleServers/{serverName}", pathParameters), 869 autorest.WithJSON(parameters), 870 autorest.WithQueryParameters(queryParameters)) 871 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 872} 873 874// UpdateSender sends the Update request. The method will close the 875// http.Response Body if it receives an error. 876func (client ServersClient) UpdateSender(req *http.Request) (future ServersUpdateFuture, err error) { 877 var resp *http.Response 878 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 879 if err != nil { 880 return 881 } 882 var azf azure.Future 883 azf, err = azure.NewFutureFromResponse(resp) 884 future.FutureAPI = &azf 885 future.Result = future.result 886 return 887} 888 889// UpdateResponder handles the response to the Update request. The method always 890// closes the http.Response Body. 891func (client ServersClient) UpdateResponder(resp *http.Response) (result Server, err error) { 892 err = autorest.Respond( 893 resp, 894 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), 895 autorest.ByUnmarshallingJSON(&result), 896 autorest.ByClosing()) 897 result.Response = autorest.Response{Response: resp} 898 return 899} 900