...

Source file src/github.com/Azure/azure-sdk-for-go/services/preview/mysql/mgmt/2020-07-01-preview/mysqlflexibleservers/servers.go

Documentation: github.com/Azure/azure-sdk-for-go/services/preview/mysql/mgmt/2020-07-01-preview/mysqlflexibleservers

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

View as plain text