diff --git a/services/mysql/mgmt/2020-01-01/mysql/models.go b/services/mysql/mgmt/2020-01-01/mysql/models.go index ba8d2aa1451a..84824cf701f5 100644 --- a/services/mysql/mgmt/2020-01-01/mysql/models.go +++ b/services/mysql/mgmt/2020-01-01/mysql/models.go @@ -3640,6 +3640,28 @@ func (future *ServersUpdateFuture) Result(client ServersClient) (s Server, err e return } +// ServersUpgradeFuture an abstraction for monitoring and retrieving the results of a long-running operation. +type ServersUpgradeFuture struct { + azure.Future +} + +// Result returns the result of the asynchronous operation. +// If the operation has not completed it will return an error. +func (future *ServersUpgradeFuture) Result(client ServersClient) (ar autorest.Response, err error) { + var done bool + done, err = future.DoneWithContext(context.Background(), client) + if err != nil { + err = autorest.NewErrorWithError(err, "mysql.ServersUpgradeFuture", "Result", future.Response(), "Polling failure") + return + } + if !done { + err = azure.NewAsyncOpIncompleteError("mysql.ServersUpgradeFuture") + return + } + ar.Response = future.Response() + return +} + // ServerUpdateParameters parameters allowed to update for a server. type ServerUpdateParameters struct { // Identity - The Azure Active Directory identity of the server. @@ -3739,6 +3761,51 @@ type ServerUpdateParametersProperties struct { ReplicationRole *string `json:"replicationRole,omitempty"` } +// ServerUpgradeParameters ... +type ServerUpgradeParameters struct { + // ServerUpgradeParametersProperties - The properties that can be updated for a server. + *ServerUpgradeParametersProperties `json:"properties,omitempty"` +} + +// MarshalJSON is the custom marshaler for ServerUpgradeParameters. +func (sup ServerUpgradeParameters) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if sup.ServerUpgradeParametersProperties != nil { + objectMap["properties"] = sup.ServerUpgradeParametersProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for ServerUpgradeParameters struct. +func (sup *ServerUpgradeParameters) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "properties": + if v != nil { + var serverUpgradeParametersProperties ServerUpgradeParametersProperties + err = json.Unmarshal(*v, &serverUpgradeParametersProperties) + if err != nil { + return err + } + sup.ServerUpgradeParametersProperties = &serverUpgradeParametersProperties + } + } + } + + return nil +} + +// ServerUpgradeParametersProperties the properties that can be updated for a server. +type ServerUpgradeParametersProperties struct { + // TargetServerVersion - Represents an server storage profile. + TargetServerVersion *string `json:"targetServerVersion,omitempty"` +} + // Sku billing information related properties of a server. type Sku struct { // Name - The name of the sku, typically, tier + family + cores, e.g. B_Gen4_1, GP_Gen5_8. diff --git a/services/mysql/mgmt/2020-01-01/mysql/mysqlapi/interfaces.go b/services/mysql/mgmt/2020-01-01/mysql/mysqlapi/interfaces.go index 21b6ea2a26e2..8c368509fb6b 100644 --- a/services/mysql/mgmt/2020-01-01/mysql/mysqlapi/interfaces.go +++ b/services/mysql/mgmt/2020-01-01/mysql/mysqlapi/interfaces.go @@ -40,6 +40,7 @@ type ServersClientAPI interface { Start(ctx context.Context, resourceGroupName string, serverName string) (result mysql.ServersStartFuture, err error) Stop(ctx context.Context, resourceGroupName string, serverName string) (result mysql.ServersStopFuture, err error) Update(ctx context.Context, resourceGroupName string, serverName string, parameters mysql.ServerUpdateParameters) (result mysql.ServersUpdateFuture, err error) + Upgrade(ctx context.Context, resourceGroupName string, serverName string, parameters mysql.ServerUpgradeParameters) (result mysql.ServersUpgradeFuture, err error) } var _ ServersClientAPI = (*mysql.ServersClient)(nil) diff --git a/services/mysql/mgmt/2020-01-01/mysql/servers.go b/services/mysql/mgmt/2020-01-01/mysql/servers.go index b0ba8c9fb93c..cbc368883b0e 100644 --- a/services/mysql/mgmt/2020-01-01/mysql/servers.go +++ b/services/mysql/mgmt/2020-01-01/mysql/servers.go @@ -807,3 +807,90 @@ func (client ServersClient) UpdateResponder(resp *http.Response) (result Server, result.Response = autorest.Response{Response: resp} return } + +// Upgrade upgrade server version. +// Parameters: +// resourceGroupName - the name of the resource group. The name is case insensitive. +// serverName - the name of the server. +// parameters - the required parameters for updating a server. +func (client ServersClient) Upgrade(ctx context.Context, resourceGroupName string, serverName string, parameters ServerUpgradeParameters) (result ServersUpgradeFuture, err error) { + if tracing.IsEnabled() { + ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Upgrade") + defer func() { + sc := -1 + if result.Response() != nil { + sc = result.Response().StatusCode + } + tracing.EndSpan(ctx, sc, err) + }() + } + if err := validation.Validate([]validation.Validation{ + {TargetValue: client.SubscriptionID, + Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, + {TargetValue: resourceGroupName, + Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, + {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, + {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { + return result, validation.NewError("mysql.ServersClient", "Upgrade", err.Error()) + } + + req, err := client.UpgradePreparer(ctx, resourceGroupName, serverName, parameters) + if err != nil { + err = autorest.NewErrorWithError(err, "mysql.ServersClient", "Upgrade", nil, "Failure preparing request") + return + } + + result, err = client.UpgradeSender(req) + if err != nil { + err = autorest.NewErrorWithError(err, "mysql.ServersClient", "Upgrade", result.Response(), "Failure sending request") + return + } + + return +} + +// UpgradePreparer prepares the Upgrade request. +func (client ServersClient) UpgradePreparer(ctx context.Context, resourceGroupName string, serverName string, parameters ServerUpgradeParameters) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "resourceGroupName": autorest.Encode("path", resourceGroupName), + "serverName": autorest.Encode("path", serverName), + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2020-01-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/servers/{serverName}/upgrade", pathParameters), + autorest.WithJSON(parameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// UpgradeSender sends the Upgrade request. The method will close the +// http.Response Body if it receives an error. +func (client ServersClient) UpgradeSender(req *http.Request) (future ServersUpgradeFuture, err error) { + var resp *http.Response + resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) + if err != nil { + return + } + future.Future, err = azure.NewFutureFromResponse(resp) + return +} + +// UpgradeResponder handles the response to the Upgrade request. The method always +// closes the http.Response Body. +func (client ServersClient) UpgradeResponder(resp *http.Response) (result autorest.Response, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted), + autorest.ByClosing()) + result.Response = resp + return +}