1package 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 9import ( 10 "context" 11 "github.com/Azure/go-autorest/autorest" 12 "github.com/Azure/go-autorest/autorest/azure" 13 "github.com/Azure/go-autorest/autorest/validation" 14 "github.com/Azure/go-autorest/tracing" 15 "net/http" 16) 17 18// ReplicasClient 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. 21type ReplicasClient struct { 22 BaseClient 23} 24 25// NewReplicasClient creates an instance of the ReplicasClient client. 26func NewReplicasClient(subscriptionID string) ReplicasClient { 27 return NewReplicasClientWithBaseURI(DefaultBaseURI, subscriptionID) 28} 29 30// NewReplicasClientWithBaseURI creates an instance of the ReplicasClient client using a custom endpoint. Use this 31// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 32func NewReplicasClientWithBaseURI(baseURI string, subscriptionID string) ReplicasClient { 33 return ReplicasClient{NewWithBaseURI(baseURI, subscriptionID)} 34} 35 36// ListByServer list all the replicas for a given server. 37// Parameters: 38// resourceGroupName - the name of the resource group. The name is case insensitive. 39// serverName - the name of the server. 40func (client ReplicasClient) ListByServer(ctx context.Context, resourceGroupName string, serverName string) (result ServerListResultPage, err error) { 41 if tracing.IsEnabled() { 42 ctx = tracing.StartSpan(ctx, fqdn+"/ReplicasClient.ListByServer") 43 defer func() { 44 sc := -1 45 if result.slr.Response.Response != nil { 46 sc = result.slr.Response.Response.StatusCode 47 } 48 tracing.EndSpan(ctx, sc, err) 49 }() 50 } 51 if err := validation.Validate([]validation.Validation{ 52 {TargetValue: client.SubscriptionID, 53 Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}, 54 {TargetValue: resourceGroupName, 55 Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil}, 56 {Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}, 57 {Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil { 58 return result, validation.NewError("mysqlflexibleservers.ReplicasClient", "ListByServer", err.Error()) 59 } 60 61 result.fn = client.listByServerNextResults 62 req, err := client.ListByServerPreparer(ctx, resourceGroupName, serverName) 63 if err != nil { 64 err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ReplicasClient", "ListByServer", nil, "Failure preparing request") 65 return 66 } 67 68 resp, err := client.ListByServerSender(req) 69 if err != nil { 70 result.slr.Response = autorest.Response{Response: resp} 71 err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ReplicasClient", "ListByServer", resp, "Failure sending request") 72 return 73 } 74 75 result.slr, err = client.ListByServerResponder(resp) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ReplicasClient", "ListByServer", resp, "Failure responding to request") 78 return 79 } 80 if result.slr.hasNextLink() && result.slr.IsEmpty() { 81 err = result.NextWithContext(ctx) 82 return 83 } 84 85 return 86} 87 88// ListByServerPreparer prepares the ListByServer request. 89func (client ReplicasClient) ListByServerPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) { 90 pathParameters := map[string]interface{}{ 91 "resourceGroupName": autorest.Encode("path", resourceGroupName), 92 "serverName": autorest.Encode("path", serverName), 93 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 94 } 95 96 const APIVersion = "2020-07-01-preview" 97 queryParameters := map[string]interface{}{ 98 "api-version": APIVersion, 99 } 100 101 preparer := autorest.CreatePreparer( 102 autorest.AsGet(), 103 autorest.WithBaseURL(client.BaseURI), 104 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForMySql/flexibleServers/{serverName}/replicas", pathParameters), 105 autorest.WithQueryParameters(queryParameters)) 106 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 107} 108 109// ListByServerSender sends the ListByServer request. The method will close the 110// http.Response Body if it receives an error. 111func (client ReplicasClient) ListByServerSender(req *http.Request) (*http.Response, error) { 112 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 113} 114 115// ListByServerResponder handles the response to the ListByServer request. The method always 116// closes the http.Response Body. 117func (client ReplicasClient) ListByServerResponder(resp *http.Response) (result ServerListResult, err error) { 118 err = autorest.Respond( 119 resp, 120 azure.WithErrorUnlessStatusCode(http.StatusOK), 121 autorest.ByUnmarshallingJSON(&result), 122 autorest.ByClosing()) 123 result.Response = autorest.Response{Response: resp} 124 return 125} 126 127// listByServerNextResults retrieves the next set of results, if any. 128func (client ReplicasClient) listByServerNextResults(ctx context.Context, lastResults ServerListResult) (result ServerListResult, err error) { 129 req, err := lastResults.serverListResultPreparer(ctx) 130 if err != nil { 131 return result, autorest.NewErrorWithError(err, "mysqlflexibleservers.ReplicasClient", "listByServerNextResults", nil, "Failure preparing next results request") 132 } 133 if req == nil { 134 return 135 } 136 resp, err := client.ListByServerSender(req) 137 if err != nil { 138 result.Response = autorest.Response{Response: resp} 139 return result, autorest.NewErrorWithError(err, "mysqlflexibleservers.ReplicasClient", "listByServerNextResults", resp, "Failure sending next results request") 140 } 141 result, err = client.ListByServerResponder(resp) 142 if err != nil { 143 err = autorest.NewErrorWithError(err, "mysqlflexibleservers.ReplicasClient", "listByServerNextResults", resp, "Failure responding to next results request") 144 } 145 return 146} 147 148// ListByServerComplete enumerates all values, automatically crossing page boundaries as required. 149func (client ReplicasClient) ListByServerComplete(ctx context.Context, resourceGroupName string, serverName string) (result ServerListResultIterator, err error) { 150 if tracing.IsEnabled() { 151 ctx = tracing.StartSpan(ctx, fqdn+"/ReplicasClient.ListByServer") 152 defer func() { 153 sc := -1 154 if result.Response().Response.Response != nil { 155 sc = result.page.Response().Response.Response.StatusCode 156 } 157 tracing.EndSpan(ctx, sc, err) 158 }() 159 } 160 result.page, err = client.ListByServer(ctx, resourceGroupName, serverName) 161 return 162} 163