...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/postgresql/mgmt/2020-11-05-preview/postgresqlflexibleservers/servers.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/postgresql/mgmt/2020-11-05-preview/postgresqlflexibleservers

     1  package 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  
     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  // 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.
    21  type ServersClient struct {
    22  	BaseClient
    23  }
    24  
    25  // NewServersClient creates an instance of the ServersClient client.
    26  func 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).
    32  func 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.
    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  				{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", result.Response(), "Failure sending request")
    74  		return
    75  	}
    76  
    77  	return
    78  }
    79  
    80  // CreatePreparer prepares the Create request.
    81  func (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.
   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  // CreateResponder handles the response to the Create request. The method always
   120  // closes the http.Response Body.
   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  // Delete deletes a server.
   132  // Parameters:
   133  // resourceGroupName - the name of the resource group. The name is case insensitive.
   134  // serverName - the name of the server.
   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},
   152  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   153  		return result, validation.NewError("postgresqlflexibleservers.ServersClient", "Delete", err.Error())
   154  	}
   155  
   156  	req, err := client.DeletePreparer(ctx, resourceGroupName, serverName)
   157  	if err != nil {
   158  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Delete", nil, "Failure preparing request")
   159  		return
   160  	}
   161  
   162  	result, err = client.DeleteSender(req)
   163  	if err != nil {
   164  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Delete", result.Response(), "Failure sending request")
   165  		return
   166  	}
   167  
   168  	return
   169  }
   170  
   171  // DeletePreparer prepares the Delete request.
   172  func (client ServersClient) DeletePreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) {
   173  	pathParameters := map[string]interface{}{
   174  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   175  		"serverName":        autorest.Encode("path", serverName),
   176  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   177  	}
   178  
   179  	const APIVersion = "2020-02-14-preview"
   180  	queryParameters := map[string]interface{}{
   181  		"api-version": APIVersion,
   182  	}
   183  
   184  	preparer := autorest.CreatePreparer(
   185  		autorest.AsDelete(),
   186  		autorest.WithBaseURL(client.BaseURI),
   187  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/flexibleServers/{serverName}", pathParameters),
   188  		autorest.WithQueryParameters(queryParameters))
   189  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   190  }
   191  
   192  // DeleteSender sends the Delete request. The method will close the
   193  // http.Response Body if it receives an error.
   194  func (client ServersClient) DeleteSender(req *http.Request) (future ServersDeleteFuture, err error) {
   195  	var resp *http.Response
   196  	future.FutureAPI = &azure.Future{}
   197  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   198  	if err != nil {
   199  		return
   200  	}
   201  	var azf azure.Future
   202  	azf, err = azure.NewFutureFromResponse(resp)
   203  	future.FutureAPI = &azf
   204  	future.Result = future.result
   205  	return
   206  }
   207  
   208  // DeleteResponder handles the response to the Delete request. The method always
   209  // closes the http.Response Body.
   210  func (client ServersClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
   211  	err = autorest.Respond(
   212  		resp,
   213  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
   214  		autorest.ByClosing())
   215  	result.Response = resp
   216  	return
   217  }
   218  
   219  // Get gets information about a server.
   220  // Parameters:
   221  // resourceGroupName - the name of the resource group. The name is case insensitive.
   222  // serverName - the name of the server.
   223  func (client ServersClient) Get(ctx context.Context, resourceGroupName string, serverName string) (result Server, err error) {
   224  	if tracing.IsEnabled() {
   225  		ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Get")
   226  		defer func() {
   227  			sc := -1
   228  			if result.Response.Response != nil {
   229  				sc = result.Response.Response.StatusCode
   230  			}
   231  			tracing.EndSpan(ctx, sc, err)
   232  		}()
   233  	}
   234  	if err := validation.Validate([]validation.Validation{
   235  		{TargetValue: client.SubscriptionID,
   236  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   237  		{TargetValue: resourceGroupName,
   238  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   239  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   240  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   241  		return result, validation.NewError("postgresqlflexibleservers.ServersClient", "Get", err.Error())
   242  	}
   243  
   244  	req, err := client.GetPreparer(ctx, resourceGroupName, serverName)
   245  	if err != nil {
   246  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Get", nil, "Failure preparing request")
   247  		return
   248  	}
   249  
   250  	resp, err := client.GetSender(req)
   251  	if err != nil {
   252  		result.Response = autorest.Response{Response: resp}
   253  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Get", resp, "Failure sending request")
   254  		return
   255  	}
   256  
   257  	result, err = client.GetResponder(resp)
   258  	if err != nil {
   259  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Get", resp, "Failure responding to request")
   260  		return
   261  	}
   262  
   263  	return
   264  }
   265  
   266  // GetPreparer prepares the Get request.
   267  func (client ServersClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) {
   268  	pathParameters := map[string]interface{}{
   269  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   270  		"serverName":        autorest.Encode("path", serverName),
   271  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   272  	}
   273  
   274  	const APIVersion = "2020-02-14-preview"
   275  	queryParameters := map[string]interface{}{
   276  		"api-version": APIVersion,
   277  	}
   278  
   279  	preparer := autorest.CreatePreparer(
   280  		autorest.AsGet(),
   281  		autorest.WithBaseURL(client.BaseURI),
   282  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/flexibleServers/{serverName}", pathParameters),
   283  		autorest.WithQueryParameters(queryParameters))
   284  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   285  }
   286  
   287  // GetSender sends the Get request. The method will close the
   288  // http.Response Body if it receives an error.
   289  func (client ServersClient) GetSender(req *http.Request) (*http.Response, error) {
   290  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   291  }
   292  
   293  // GetResponder handles the response to the Get request. The method always
   294  // closes the http.Response Body.
   295  func (client ServersClient) GetResponder(resp *http.Response) (result Server, err error) {
   296  	err = autorest.Respond(
   297  		resp,
   298  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   299  		autorest.ByUnmarshallingJSON(&result),
   300  		autorest.ByClosing())
   301  	result.Response = autorest.Response{Response: resp}
   302  	return
   303  }
   304  
   305  // List list all the servers in a given subscription.
   306  func (client ServersClient) List(ctx context.Context) (result ServerListResultPage, err error) {
   307  	if tracing.IsEnabled() {
   308  		ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.List")
   309  		defer func() {
   310  			sc := -1
   311  			if result.slr.Response.Response != nil {
   312  				sc = result.slr.Response.Response.StatusCode
   313  			}
   314  			tracing.EndSpan(ctx, sc, err)
   315  		}()
   316  	}
   317  	if err := validation.Validate([]validation.Validation{
   318  		{TargetValue: client.SubscriptionID,
   319  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
   320  		return result, validation.NewError("postgresqlflexibleservers.ServersClient", "List", err.Error())
   321  	}
   322  
   323  	result.fn = client.listNextResults
   324  	req, err := client.ListPreparer(ctx)
   325  	if err != nil {
   326  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "List", nil, "Failure preparing request")
   327  		return
   328  	}
   329  
   330  	resp, err := client.ListSender(req)
   331  	if err != nil {
   332  		result.slr.Response = autorest.Response{Response: resp}
   333  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "List", resp, "Failure sending request")
   334  		return
   335  	}
   336  
   337  	result.slr, err = client.ListResponder(resp)
   338  	if err != nil {
   339  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "List", resp, "Failure responding to request")
   340  		return
   341  	}
   342  	if result.slr.hasNextLink() && result.slr.IsEmpty() {
   343  		err = result.NextWithContext(ctx)
   344  		return
   345  	}
   346  
   347  	return
   348  }
   349  
   350  // ListPreparer prepares the List request.
   351  func (client ServersClient) ListPreparer(ctx context.Context) (*http.Request, error) {
   352  	pathParameters := map[string]interface{}{
   353  		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
   354  	}
   355  
   356  	const APIVersion = "2020-02-14-preview"
   357  	queryParameters := map[string]interface{}{
   358  		"api-version": APIVersion,
   359  	}
   360  
   361  	preparer := autorest.CreatePreparer(
   362  		autorest.AsGet(),
   363  		autorest.WithBaseURL(client.BaseURI),
   364  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DBForPostgreSql/flexibleServers", pathParameters),
   365  		autorest.WithQueryParameters(queryParameters))
   366  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   367  }
   368  
   369  // ListSender sends the List request. The method will close the
   370  // http.Response Body if it receives an error.
   371  func (client ServersClient) ListSender(req *http.Request) (*http.Response, error) {
   372  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   373  }
   374  
   375  // ListResponder handles the response to the List request. The method always
   376  // closes the http.Response Body.
   377  func (client ServersClient) ListResponder(resp *http.Response) (result ServerListResult, err error) {
   378  	err = autorest.Respond(
   379  		resp,
   380  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   381  		autorest.ByUnmarshallingJSON(&result),
   382  		autorest.ByClosing())
   383  	result.Response = autorest.Response{Response: resp}
   384  	return
   385  }
   386  
   387  // listNextResults retrieves the next set of results, if any.
   388  func (client ServersClient) listNextResults(ctx context.Context, lastResults ServerListResult) (result ServerListResult, err error) {
   389  	req, err := lastResults.serverListResultPreparer(ctx)
   390  	if err != nil {
   391  		return result, autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "listNextResults", nil, "Failure preparing next results request")
   392  	}
   393  	if req == nil {
   394  		return
   395  	}
   396  	resp, err := client.ListSender(req)
   397  	if err != nil {
   398  		result.Response = autorest.Response{Response: resp}
   399  		return result, autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "listNextResults", resp, "Failure sending next results request")
   400  	}
   401  	result, err = client.ListResponder(resp)
   402  	if err != nil {
   403  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "listNextResults", resp, "Failure responding to next results request")
   404  	}
   405  	return
   406  }
   407  
   408  // ListComplete enumerates all values, automatically crossing page boundaries as required.
   409  func (client ServersClient) ListComplete(ctx context.Context) (result ServerListResultIterator, err error) {
   410  	if tracing.IsEnabled() {
   411  		ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.List")
   412  		defer func() {
   413  			sc := -1
   414  			if result.Response().Response.Response != nil {
   415  				sc = result.page.Response().Response.Response.StatusCode
   416  			}
   417  			tracing.EndSpan(ctx, sc, err)
   418  		}()
   419  	}
   420  	result.page, err = client.List(ctx)
   421  	return
   422  }
   423  
   424  // ListByResourceGroup list all the servers in a given resource group.
   425  // Parameters:
   426  // resourceGroupName - the name of the resource group. The name is case insensitive.
   427  func (client ServersClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result ServerListResultPage, err error) {
   428  	if tracing.IsEnabled() {
   429  		ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.ListByResourceGroup")
   430  		defer func() {
   431  			sc := -1
   432  			if result.slr.Response.Response != nil {
   433  				sc = result.slr.Response.Response.StatusCode
   434  			}
   435  			tracing.EndSpan(ctx, sc, err)
   436  		}()
   437  	}
   438  	if err := validation.Validate([]validation.Validation{
   439  		{TargetValue: client.SubscriptionID,
   440  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   441  		{TargetValue: resourceGroupName,
   442  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   443  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   444  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   445  		return result, validation.NewError("postgresqlflexibleservers.ServersClient", "ListByResourceGroup", err.Error())
   446  	}
   447  
   448  	result.fn = client.listByResourceGroupNextResults
   449  	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
   450  	if err != nil {
   451  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "ListByResourceGroup", nil, "Failure preparing request")
   452  		return
   453  	}
   454  
   455  	resp, err := client.ListByResourceGroupSender(req)
   456  	if err != nil {
   457  		result.slr.Response = autorest.Response{Response: resp}
   458  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "ListByResourceGroup", resp, "Failure sending request")
   459  		return
   460  	}
   461  
   462  	result.slr, err = client.ListByResourceGroupResponder(resp)
   463  	if err != nil {
   464  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "ListByResourceGroup", resp, "Failure responding to request")
   465  		return
   466  	}
   467  	if result.slr.hasNextLink() && result.slr.IsEmpty() {
   468  		err = result.NextWithContext(ctx)
   469  		return
   470  	}
   471  
   472  	return
   473  }
   474  
   475  // ListByResourceGroupPreparer prepares the ListByResourceGroup request.
   476  func (client ServersClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
   477  	pathParameters := map[string]interface{}{
   478  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   479  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   480  	}
   481  
   482  	const APIVersion = "2020-02-14-preview"
   483  	queryParameters := map[string]interface{}{
   484  		"api-version": APIVersion,
   485  	}
   486  
   487  	preparer := autorest.CreatePreparer(
   488  		autorest.AsGet(),
   489  		autorest.WithBaseURL(client.BaseURI),
   490  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/flexibleServers", pathParameters),
   491  		autorest.WithQueryParameters(queryParameters))
   492  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   493  }
   494  
   495  // ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
   496  // http.Response Body if it receives an error.
   497  func (client ServersClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
   498  	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
   499  }
   500  
   501  // ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
   502  // closes the http.Response Body.
   503  func (client ServersClient) ListByResourceGroupResponder(resp *http.Response) (result ServerListResult, err error) {
   504  	err = autorest.Respond(
   505  		resp,
   506  		azure.WithErrorUnlessStatusCode(http.StatusOK),
   507  		autorest.ByUnmarshallingJSON(&result),
   508  		autorest.ByClosing())
   509  	result.Response = autorest.Response{Response: resp}
   510  	return
   511  }
   512  
   513  // listByResourceGroupNextResults retrieves the next set of results, if any.
   514  func (client ServersClient) listByResourceGroupNextResults(ctx context.Context, lastResults ServerListResult) (result ServerListResult, err error) {
   515  	req, err := lastResults.serverListResultPreparer(ctx)
   516  	if err != nil {
   517  		return result, autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request")
   518  	}
   519  	if req == nil {
   520  		return
   521  	}
   522  	resp, err := client.ListByResourceGroupSender(req)
   523  	if err != nil {
   524  		result.Response = autorest.Response{Response: resp}
   525  		return result, autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "listByResourceGroupNextResults", resp, "Failure sending next results request")
   526  	}
   527  	result, err = client.ListByResourceGroupResponder(resp)
   528  	if err != nil {
   529  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request")
   530  	}
   531  	return
   532  }
   533  
   534  // ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required.
   535  func (client ServersClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result ServerListResultIterator, err error) {
   536  	if tracing.IsEnabled() {
   537  		ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.ListByResourceGroup")
   538  		defer func() {
   539  			sc := -1
   540  			if result.Response().Response.Response != nil {
   541  				sc = result.page.Response().Response.Response.StatusCode
   542  			}
   543  			tracing.EndSpan(ctx, sc, err)
   544  		}()
   545  	}
   546  	result.page, err = client.ListByResourceGroup(ctx, resourceGroupName)
   547  	return
   548  }
   549  
   550  // Restart restarts a server.
   551  // Parameters:
   552  // resourceGroupName - the name of the resource group. The name is case insensitive.
   553  // serverName - the name of the server.
   554  func (client ServersClient) Restart(ctx context.Context, resourceGroupName string, serverName string) (result ServersRestartFuture, err error) {
   555  	if tracing.IsEnabled() {
   556  		ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Restart")
   557  		defer func() {
   558  			sc := -1
   559  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   560  				sc = result.FutureAPI.Response().StatusCode
   561  			}
   562  			tracing.EndSpan(ctx, sc, err)
   563  		}()
   564  	}
   565  	if err := validation.Validate([]validation.Validation{
   566  		{TargetValue: client.SubscriptionID,
   567  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   568  		{TargetValue: resourceGroupName,
   569  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   570  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   571  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   572  		return result, validation.NewError("postgresqlflexibleservers.ServersClient", "Restart", err.Error())
   573  	}
   574  
   575  	req, err := client.RestartPreparer(ctx, resourceGroupName, serverName)
   576  	if err != nil {
   577  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Restart", nil, "Failure preparing request")
   578  		return
   579  	}
   580  
   581  	result, err = client.RestartSender(req)
   582  	if err != nil {
   583  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Restart", result.Response(), "Failure sending request")
   584  		return
   585  	}
   586  
   587  	return
   588  }
   589  
   590  // RestartPreparer prepares the Restart request.
   591  func (client ServersClient) RestartPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) {
   592  	pathParameters := map[string]interface{}{
   593  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   594  		"serverName":        autorest.Encode("path", serverName),
   595  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   596  	}
   597  
   598  	const APIVersion = "2020-02-14-preview"
   599  	queryParameters := map[string]interface{}{
   600  		"api-version": APIVersion,
   601  	}
   602  
   603  	preparer := autorest.CreatePreparer(
   604  		autorest.AsPost(),
   605  		autorest.WithBaseURL(client.BaseURI),
   606  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/flexibleServers/{serverName}/restart", pathParameters),
   607  		autorest.WithQueryParameters(queryParameters))
   608  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   609  }
   610  
   611  // RestartSender sends the Restart request. The method will close the
   612  // http.Response Body if it receives an error.
   613  func (client ServersClient) RestartSender(req *http.Request) (future ServersRestartFuture, err error) {
   614  	var resp *http.Response
   615  	future.FutureAPI = &azure.Future{}
   616  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   617  	if err != nil {
   618  		return
   619  	}
   620  	var azf azure.Future
   621  	azf, err = azure.NewFutureFromResponse(resp)
   622  	future.FutureAPI = &azf
   623  	future.Result = future.result
   624  	return
   625  }
   626  
   627  // RestartResponder handles the response to the Restart request. The method always
   628  // closes the http.Response Body.
   629  func (client ServersClient) RestartResponder(resp *http.Response) (result autorest.Response, err error) {
   630  	err = autorest.Respond(
   631  		resp,
   632  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   633  		autorest.ByClosing())
   634  	result.Response = resp
   635  	return
   636  }
   637  
   638  // Start starts a server.
   639  // Parameters:
   640  // resourceGroupName - the name of the resource group. The name is case insensitive.
   641  // serverName - the name of the server.
   642  func (client ServersClient) Start(ctx context.Context, resourceGroupName string, serverName string) (result ServersStartFuture, err error) {
   643  	if tracing.IsEnabled() {
   644  		ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Start")
   645  		defer func() {
   646  			sc := -1
   647  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   648  				sc = result.FutureAPI.Response().StatusCode
   649  			}
   650  			tracing.EndSpan(ctx, sc, err)
   651  		}()
   652  	}
   653  	if err := validation.Validate([]validation.Validation{
   654  		{TargetValue: client.SubscriptionID,
   655  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   656  		{TargetValue: resourceGroupName,
   657  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   658  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   659  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   660  		return result, validation.NewError("postgresqlflexibleservers.ServersClient", "Start", err.Error())
   661  	}
   662  
   663  	req, err := client.StartPreparer(ctx, resourceGroupName, serverName)
   664  	if err != nil {
   665  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Start", nil, "Failure preparing request")
   666  		return
   667  	}
   668  
   669  	result, err = client.StartSender(req)
   670  	if err != nil {
   671  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Start", result.Response(), "Failure sending request")
   672  		return
   673  	}
   674  
   675  	return
   676  }
   677  
   678  // StartPreparer prepares the Start request.
   679  func (client ServersClient) StartPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) {
   680  	pathParameters := map[string]interface{}{
   681  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   682  		"serverName":        autorest.Encode("path", serverName),
   683  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   684  	}
   685  
   686  	const APIVersion = "2020-02-14-preview"
   687  	queryParameters := map[string]interface{}{
   688  		"api-version": APIVersion,
   689  	}
   690  
   691  	preparer := autorest.CreatePreparer(
   692  		autorest.AsPost(),
   693  		autorest.WithBaseURL(client.BaseURI),
   694  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/flexibleServers/{serverName}/start", pathParameters),
   695  		autorest.WithQueryParameters(queryParameters))
   696  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   697  }
   698  
   699  // StartSender sends the Start request. The method will close the
   700  // http.Response Body if it receives an error.
   701  func (client ServersClient) StartSender(req *http.Request) (future ServersStartFuture, err error) {
   702  	var resp *http.Response
   703  	future.FutureAPI = &azure.Future{}
   704  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   705  	if err != nil {
   706  		return
   707  	}
   708  	var azf azure.Future
   709  	azf, err = azure.NewFutureFromResponse(resp)
   710  	future.FutureAPI = &azf
   711  	future.Result = future.result
   712  	return
   713  }
   714  
   715  // StartResponder handles the response to the Start request. The method always
   716  // closes the http.Response Body.
   717  func (client ServersClient) StartResponder(resp *http.Response) (result autorest.Response, err error) {
   718  	err = autorest.Respond(
   719  		resp,
   720  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   721  		autorest.ByClosing())
   722  	result.Response = resp
   723  	return
   724  }
   725  
   726  // Stop stops a server.
   727  // Parameters:
   728  // resourceGroupName - the name of the resource group. The name is case insensitive.
   729  // serverName - the name of the server.
   730  func (client ServersClient) Stop(ctx context.Context, resourceGroupName string, serverName string) (result ServersStopFuture, err error) {
   731  	if tracing.IsEnabled() {
   732  		ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Stop")
   733  		defer func() {
   734  			sc := -1
   735  			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
   736  				sc = result.FutureAPI.Response().StatusCode
   737  			}
   738  			tracing.EndSpan(ctx, sc, err)
   739  		}()
   740  	}
   741  	if err := validation.Validate([]validation.Validation{
   742  		{TargetValue: client.SubscriptionID,
   743  			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
   744  		{TargetValue: resourceGroupName,
   745  			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
   746  				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
   747  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, 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  // StopPreparer prepares the Stop request.
   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 = "2020-02-14-preview"
   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  // StopSender sends the Stop request. The method will close the
   788  // http.Response Body if it receives an error.
   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  // StopResponder handles the response to the Stop request. The method always
   804  // closes the http.Response Body.
   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  // Update updates an existing server. The request body can contain one to many of the properties present in the normal
   815  // server definition.
   816  // Parameters:
   817  // resourceGroupName - the name of the resource group. The name is case insensitive.
   818  // serverName - the name of the server.
   819  // parameters - the required parameters for updating a server.
   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},
   837  				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
   838  		return result, validation.NewError("postgresqlflexibleservers.ServersClient", "Update", err.Error())
   839  	}
   840  
   841  	req, err := client.UpdatePreparer(ctx, resourceGroupName, serverName, parameters)
   842  	if err != nil {
   843  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Update", nil, "Failure preparing request")
   844  		return
   845  	}
   846  
   847  	result, err = client.UpdateSender(req)
   848  	if err != nil {
   849  		err = autorest.NewErrorWithError(err, "postgresqlflexibleservers.ServersClient", "Update", result.Response(), "Failure sending request")
   850  		return
   851  	}
   852  
   853  	return
   854  }
   855  
   856  // UpdatePreparer prepares the Update request.
   857  func (client ServersClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, parameters ServerForUpdate) (*http.Request, error) {
   858  	pathParameters := map[string]interface{}{
   859  		"resourceGroupName": autorest.Encode("path", resourceGroupName),
   860  		"serverName":        autorest.Encode("path", serverName),
   861  		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
   862  	}
   863  
   864  	const APIVersion = "2020-02-14-preview"
   865  	queryParameters := map[string]interface{}{
   866  		"api-version": APIVersion,
   867  	}
   868  
   869  	preparer := autorest.CreatePreparer(
   870  		autorest.AsContentType("application/json; charset=utf-8"),
   871  		autorest.AsPatch(),
   872  		autorest.WithBaseURL(client.BaseURI),
   873  		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForPostgreSql/flexibleServers/{serverName}", pathParameters),
   874  		autorest.WithJSON(parameters),
   875  		autorest.WithQueryParameters(queryParameters))
   876  	return preparer.Prepare((&http.Request{}).WithContext(ctx))
   877  }
   878  
   879  // UpdateSender sends the Update request. The method will close the
   880  // http.Response Body if it receives an error.
   881  func (client ServersClient) UpdateSender(req *http.Request) (future ServersUpdateFuture, err error) {
   882  	var resp *http.Response
   883  	future.FutureAPI = &azure.Future{}
   884  	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
   885  	if err != nil {
   886  		return
   887  	}
   888  	var azf azure.Future
   889  	azf, err = azure.NewFutureFromResponse(resp)
   890  	future.FutureAPI = &azf
   891  	future.Result = future.result
   892  	return
   893  }
   894  
   895  // UpdateResponder handles the response to the Update request. The method always
   896  // closes the http.Response Body.
   897  func (client ServersClient) UpdateResponder(resp *http.Response) (result Server, err error) {
   898  	err = autorest.Respond(
   899  		resp,
   900  		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
   901  		autorest.ByUnmarshallingJSON(&result),
   902  		autorest.ByClosing())
   903  	result.Response = autorest.Response{Response: resp}
   904  	return
   905  }
   906  

View as plain text