1package mysql
2
3// Copyright (c) Microsoft and contributors.  All rights reserved.
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13//
14// See the License for the specific language governing permissions and
15// limitations under the License.
16//
17// Code generated by Microsoft (R) AutoRest Code Generator.
18// Changes may cause incorrect behavior and will be lost if the code is regenerated.
19
20import (
21	"context"
22	"github.com/Azure/go-autorest/autorest"
23	"github.com/Azure/go-autorest/autorest/azure"
24	"github.com/Azure/go-autorest/autorest/validation"
25	"github.com/Azure/go-autorest/tracing"
26	"net/http"
27)
28
29// ServersClient is the the Microsoft Azure management API provides create, read, update, and delete functionality for
30// Azure MySQL resources including servers, databases, firewall rules, VNET rules, log files and configurations with
31// new business model.
32type ServersClient struct {
33	BaseClient
34}
35
36// NewServersClient creates an instance of the ServersClient client.
37func NewServersClient(subscriptionID string) ServersClient {
38	return NewServersClientWithBaseURI(DefaultBaseURI, subscriptionID)
39}
40
41// NewServersClientWithBaseURI creates an instance of the ServersClient client using a custom endpoint.  Use this when
42// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
43func NewServersClientWithBaseURI(baseURI string, subscriptionID string) ServersClient {
44	return ServersClient{NewWithBaseURI(baseURI, subscriptionID)}
45}
46
47// Create creates a new server or updates an existing server. The update action will overwrite the existing server.
48// Parameters:
49// resourceGroupName - the name of the resource group. The name is case insensitive.
50// serverName - the name of the server.
51// parameters - the required parameters for creating or updating a server.
52func (client ServersClient) Create(ctx context.Context, resourceGroupName string, serverName string, parameters ServerForCreate) (result ServersCreateFuture, err error) {
53	if tracing.IsEnabled() {
54		ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Create")
55		defer func() {
56			sc := -1
57			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
58				sc = result.FutureAPI.Response().StatusCode
59			}
60			tracing.EndSpan(ctx, sc, err)
61		}()
62	}
63	if err := validation.Validate([]validation.Validation{
64		{TargetValue: client.SubscriptionID,
65			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
66		{TargetValue: resourceGroupName,
67			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
68				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
69				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}},
70		{TargetValue: parameters,
71			Constraints: []validation.Constraint{{Target: "parameters.Sku", Name: validation.Null, Rule: false,
72				Chain: []validation.Constraint{{Target: "parameters.Sku.Name", Name: validation.Null, Rule: true, Chain: nil},
73					{Target: "parameters.Sku.Capacity", Name: validation.Null, Rule: false,
74						Chain: []validation.Constraint{{Target: "parameters.Sku.Capacity", Name: validation.InclusiveMinimum, Rule: int64(0), Chain: nil}}},
75				}},
76				{Target: "parameters.Location", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil {
77		return result, validation.NewError("mysql.ServersClient", "Create", err.Error())
78	}
79
80	req, err := client.CreatePreparer(ctx, resourceGroupName, serverName, parameters)
81	if err != nil {
82		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "Create", nil, "Failure preparing request")
83		return
84	}
85
86	result, err = client.CreateSender(req)
87	if err != nil {
88		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "Create", nil, "Failure sending request")
89		return
90	}
91
92	return
93}
94
95// CreatePreparer prepares the Create request.
96func (client ServersClient) CreatePreparer(ctx context.Context, resourceGroupName string, serverName string, parameters ServerForCreate) (*http.Request, error) {
97	pathParameters := map[string]interface{}{
98		"resourceGroupName": autorest.Encode("path", resourceGroupName),
99		"serverName":        autorest.Encode("path", serverName),
100		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
101	}
102
103	const APIVersion = "2017-12-01"
104	queryParameters := map[string]interface{}{
105		"api-version": APIVersion,
106	}
107
108	preparer := autorest.CreatePreparer(
109		autorest.AsContentType("application/json; charset=utf-8"),
110		autorest.AsPut(),
111		autorest.WithBaseURL(client.BaseURI),
112		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForMySQL/servers/{serverName}", pathParameters),
113		autorest.WithJSON(parameters),
114		autorest.WithQueryParameters(queryParameters))
115	return preparer.Prepare((&http.Request{}).WithContext(ctx))
116}
117
118// CreateSender sends the Create request. The method will close the
119// http.Response Body if it receives an error.
120func (client ServersClient) CreateSender(req *http.Request) (future ServersCreateFuture, err error) {
121	var resp *http.Response
122	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
123	if err != nil {
124		return
125	}
126	var azf azure.Future
127	azf, err = azure.NewFutureFromResponse(resp)
128	future.FutureAPI = &azf
129	future.Result = func(client ServersClient) (s Server, err error) {
130		var done bool
131		done, err = future.DoneWithContext(context.Background(), client)
132		if err != nil {
133			err = autorest.NewErrorWithError(err, "mysql.ServersCreateFuture", "Result", future.Response(), "Polling failure")
134			return
135		}
136		if !done {
137			err = azure.NewAsyncOpIncompleteError("mysql.ServersCreateFuture")
138			return
139		}
140		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
141		s.Response.Response, err = future.GetResult(sender)
142		if s.Response.Response == nil && err == nil {
143			err = autorest.NewErrorWithError(err, "mysql.ServersCreateFuture", "Result", nil, "received nil response and error")
144		}
145		if err == nil && s.Response.Response.StatusCode != http.StatusNoContent {
146			s, err = client.CreateResponder(s.Response.Response)
147			if err != nil {
148				err = autorest.NewErrorWithError(err, "mysql.ServersCreateFuture", "Result", s.Response.Response, "Failure responding to request")
149			}
150		}
151		return
152	}
153	return
154}
155
156// CreateResponder handles the response to the Create request. The method always
157// closes the http.Response Body.
158func (client ServersClient) CreateResponder(resp *http.Response) (result Server, err error) {
159	err = autorest.Respond(
160		resp,
161		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated, http.StatusAccepted),
162		autorest.ByUnmarshallingJSON(&result),
163		autorest.ByClosing())
164	result.Response = autorest.Response{Response: resp}
165	return
166}
167
168// Delete deletes a server.
169// Parameters:
170// resourceGroupName - the name of the resource group. The name is case insensitive.
171// serverName - the name of the server.
172func (client ServersClient) Delete(ctx context.Context, resourceGroupName string, serverName string) (result ServersDeleteFuture, err error) {
173	if tracing.IsEnabled() {
174		ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Delete")
175		defer func() {
176			sc := -1
177			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
178				sc = result.FutureAPI.Response().StatusCode
179			}
180			tracing.EndSpan(ctx, sc, err)
181		}()
182	}
183	if err := validation.Validate([]validation.Validation{
184		{TargetValue: client.SubscriptionID,
185			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
186		{TargetValue: resourceGroupName,
187			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
188				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
189				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
190		return result, validation.NewError("mysql.ServersClient", "Delete", err.Error())
191	}
192
193	req, err := client.DeletePreparer(ctx, resourceGroupName, serverName)
194	if err != nil {
195		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "Delete", nil, "Failure preparing request")
196		return
197	}
198
199	result, err = client.DeleteSender(req)
200	if err != nil {
201		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "Delete", nil, "Failure sending request")
202		return
203	}
204
205	return
206}
207
208// DeletePreparer prepares the Delete request.
209func (client ServersClient) DeletePreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) {
210	pathParameters := map[string]interface{}{
211		"resourceGroupName": autorest.Encode("path", resourceGroupName),
212		"serverName":        autorest.Encode("path", serverName),
213		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
214	}
215
216	const APIVersion = "2017-12-01"
217	queryParameters := map[string]interface{}{
218		"api-version": APIVersion,
219	}
220
221	preparer := autorest.CreatePreparer(
222		autorest.AsDelete(),
223		autorest.WithBaseURL(client.BaseURI),
224		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForMySQL/servers/{serverName}", pathParameters),
225		autorest.WithQueryParameters(queryParameters))
226	return preparer.Prepare((&http.Request{}).WithContext(ctx))
227}
228
229// DeleteSender sends the Delete request. The method will close the
230// http.Response Body if it receives an error.
231func (client ServersClient) DeleteSender(req *http.Request) (future ServersDeleteFuture, err error) {
232	var resp *http.Response
233	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
234	if err != nil {
235		return
236	}
237	var azf azure.Future
238	azf, err = azure.NewFutureFromResponse(resp)
239	future.FutureAPI = &azf
240	future.Result = func(client ServersClient) (ar autorest.Response, err error) {
241		var done bool
242		done, err = future.DoneWithContext(context.Background(), client)
243		if err != nil {
244			err = autorest.NewErrorWithError(err, "mysql.ServersDeleteFuture", "Result", future.Response(), "Polling failure")
245			return
246		}
247		if !done {
248			err = azure.NewAsyncOpIncompleteError("mysql.ServersDeleteFuture")
249			return
250		}
251		ar.Response = future.Response()
252		return
253	}
254	return
255}
256
257// DeleteResponder handles the response to the Delete request. The method always
258// closes the http.Response Body.
259func (client ServersClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
260	err = autorest.Respond(
261		resp,
262		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
263		autorest.ByClosing())
264	result.Response = resp
265	return
266}
267
268// Get gets information about a server.
269// Parameters:
270// resourceGroupName - the name of the resource group. The name is case insensitive.
271// serverName - the name of the server.
272func (client ServersClient) Get(ctx context.Context, resourceGroupName string, serverName string) (result Server, err error) {
273	if tracing.IsEnabled() {
274		ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Get")
275		defer func() {
276			sc := -1
277			if result.Response.Response != nil {
278				sc = result.Response.Response.StatusCode
279			}
280			tracing.EndSpan(ctx, sc, err)
281		}()
282	}
283	if err := validation.Validate([]validation.Validation{
284		{TargetValue: client.SubscriptionID,
285			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
286		{TargetValue: resourceGroupName,
287			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
288				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
289				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
290		return result, validation.NewError("mysql.ServersClient", "Get", err.Error())
291	}
292
293	req, err := client.GetPreparer(ctx, resourceGroupName, serverName)
294	if err != nil {
295		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "Get", nil, "Failure preparing request")
296		return
297	}
298
299	resp, err := client.GetSender(req)
300	if err != nil {
301		result.Response = autorest.Response{Response: resp}
302		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "Get", resp, "Failure sending request")
303		return
304	}
305
306	result, err = client.GetResponder(resp)
307	if err != nil {
308		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "Get", resp, "Failure responding to request")
309		return
310	}
311
312	return
313}
314
315// GetPreparer prepares the Get request.
316func (client ServersClient) GetPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) {
317	pathParameters := map[string]interface{}{
318		"resourceGroupName": autorest.Encode("path", resourceGroupName),
319		"serverName":        autorest.Encode("path", serverName),
320		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
321	}
322
323	const APIVersion = "2017-12-01"
324	queryParameters := map[string]interface{}{
325		"api-version": APIVersion,
326	}
327
328	preparer := autorest.CreatePreparer(
329		autorest.AsGet(),
330		autorest.WithBaseURL(client.BaseURI),
331		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForMySQL/servers/{serverName}", pathParameters),
332		autorest.WithQueryParameters(queryParameters))
333	return preparer.Prepare((&http.Request{}).WithContext(ctx))
334}
335
336// GetSender sends the Get request. The method will close the
337// http.Response Body if it receives an error.
338func (client ServersClient) GetSender(req *http.Request) (*http.Response, error) {
339	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
340}
341
342// GetResponder handles the response to the Get request. The method always
343// closes the http.Response Body.
344func (client ServersClient) GetResponder(resp *http.Response) (result Server, err error) {
345	err = autorest.Respond(
346		resp,
347		azure.WithErrorUnlessStatusCode(http.StatusOK),
348		autorest.ByUnmarshallingJSON(&result),
349		autorest.ByClosing())
350	result.Response = autorest.Response{Response: resp}
351	return
352}
353
354// List list all the servers in a given subscription.
355func (client ServersClient) List(ctx context.Context) (result ServerListResult, err error) {
356	if tracing.IsEnabled() {
357		ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.List")
358		defer func() {
359			sc := -1
360			if result.Response.Response != nil {
361				sc = result.Response.Response.StatusCode
362			}
363			tracing.EndSpan(ctx, sc, err)
364		}()
365	}
366	if err := validation.Validate([]validation.Validation{
367		{TargetValue: client.SubscriptionID,
368			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}}}); err != nil {
369		return result, validation.NewError("mysql.ServersClient", "List", err.Error())
370	}
371
372	req, err := client.ListPreparer(ctx)
373	if err != nil {
374		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "List", nil, "Failure preparing request")
375		return
376	}
377
378	resp, err := client.ListSender(req)
379	if err != nil {
380		result.Response = autorest.Response{Response: resp}
381		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "List", resp, "Failure sending request")
382		return
383	}
384
385	result, err = client.ListResponder(resp)
386	if err != nil {
387		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "List", resp, "Failure responding to request")
388		return
389	}
390
391	return
392}
393
394// ListPreparer prepares the List request.
395func (client ServersClient) ListPreparer(ctx context.Context) (*http.Request, error) {
396	pathParameters := map[string]interface{}{
397		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
398	}
399
400	const APIVersion = "2017-12-01"
401	queryParameters := map[string]interface{}{
402		"api-version": APIVersion,
403	}
404
405	preparer := autorest.CreatePreparer(
406		autorest.AsGet(),
407		autorest.WithBaseURL(client.BaseURI),
408		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.DBForMySQL/servers", pathParameters),
409		autorest.WithQueryParameters(queryParameters))
410	return preparer.Prepare((&http.Request{}).WithContext(ctx))
411}
412
413// ListSender sends the List request. The method will close the
414// http.Response Body if it receives an error.
415func (client ServersClient) ListSender(req *http.Request) (*http.Response, error) {
416	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
417}
418
419// ListResponder handles the response to the List request. The method always
420// closes the http.Response Body.
421func (client ServersClient) ListResponder(resp *http.Response) (result ServerListResult, err error) {
422	err = autorest.Respond(
423		resp,
424		azure.WithErrorUnlessStatusCode(http.StatusOK),
425		autorest.ByUnmarshallingJSON(&result),
426		autorest.ByClosing())
427	result.Response = autorest.Response{Response: resp}
428	return
429}
430
431// ListByResourceGroup list all the servers in a given resource group.
432// Parameters:
433// resourceGroupName - the name of the resource group. The name is case insensitive.
434func (client ServersClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result ServerListResult, err error) {
435	if tracing.IsEnabled() {
436		ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.ListByResourceGroup")
437		defer func() {
438			sc := -1
439			if result.Response.Response != nil {
440				sc = result.Response.Response.StatusCode
441			}
442			tracing.EndSpan(ctx, sc, err)
443		}()
444	}
445	if err := validation.Validate([]validation.Validation{
446		{TargetValue: client.SubscriptionID,
447			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
448		{TargetValue: resourceGroupName,
449			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
450				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
451				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
452		return result, validation.NewError("mysql.ServersClient", "ListByResourceGroup", err.Error())
453	}
454
455	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
456	if err != nil {
457		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "ListByResourceGroup", nil, "Failure preparing request")
458		return
459	}
460
461	resp, err := client.ListByResourceGroupSender(req)
462	if err != nil {
463		result.Response = autorest.Response{Response: resp}
464		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "ListByResourceGroup", resp, "Failure sending request")
465		return
466	}
467
468	result, err = client.ListByResourceGroupResponder(resp)
469	if err != nil {
470		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "ListByResourceGroup", resp, "Failure responding to request")
471		return
472	}
473
474	return
475}
476
477// ListByResourceGroupPreparer prepares the ListByResourceGroup request.
478func (client ServersClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
479	pathParameters := map[string]interface{}{
480		"resourceGroupName": autorest.Encode("path", resourceGroupName),
481		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
482	}
483
484	const APIVersion = "2017-12-01"
485	queryParameters := map[string]interface{}{
486		"api-version": APIVersion,
487	}
488
489	preparer := autorest.CreatePreparer(
490		autorest.AsGet(),
491		autorest.WithBaseURL(client.BaseURI),
492		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForMySQL/servers", pathParameters),
493		autorest.WithQueryParameters(queryParameters))
494	return preparer.Prepare((&http.Request{}).WithContext(ctx))
495}
496
497// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
498// http.Response Body if it receives an error.
499func (client ServersClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
500	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
501}
502
503// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
504// closes the http.Response Body.
505func (client ServersClient) ListByResourceGroupResponder(resp *http.Response) (result ServerListResult, err error) {
506	err = autorest.Respond(
507		resp,
508		azure.WithErrorUnlessStatusCode(http.StatusOK),
509		autorest.ByUnmarshallingJSON(&result),
510		autorest.ByClosing())
511	result.Response = autorest.Response{Response: resp}
512	return
513}
514
515// Restart restarts a server.
516// Parameters:
517// resourceGroupName - the name of the resource group. The name is case insensitive.
518// serverName - the name of the server.
519func (client ServersClient) Restart(ctx context.Context, resourceGroupName string, serverName string) (result ServersRestartFuture, err error) {
520	if tracing.IsEnabled() {
521		ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Restart")
522		defer func() {
523			sc := -1
524			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
525				sc = result.FutureAPI.Response().StatusCode
526			}
527			tracing.EndSpan(ctx, sc, err)
528		}()
529	}
530	if err := validation.Validate([]validation.Validation{
531		{TargetValue: client.SubscriptionID,
532			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
533		{TargetValue: resourceGroupName,
534			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
535				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
536				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
537		return result, validation.NewError("mysql.ServersClient", "Restart", err.Error())
538	}
539
540	req, err := client.RestartPreparer(ctx, resourceGroupName, serverName)
541	if err != nil {
542		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "Restart", nil, "Failure preparing request")
543		return
544	}
545
546	result, err = client.RestartSender(req)
547	if err != nil {
548		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "Restart", nil, "Failure sending request")
549		return
550	}
551
552	return
553}
554
555// RestartPreparer prepares the Restart request.
556func (client ServersClient) RestartPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) {
557	pathParameters := map[string]interface{}{
558		"resourceGroupName": autorest.Encode("path", resourceGroupName),
559		"serverName":        autorest.Encode("path", serverName),
560		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
561	}
562
563	const APIVersion = "2017-12-01"
564	queryParameters := map[string]interface{}{
565		"api-version": APIVersion,
566	}
567
568	preparer := autorest.CreatePreparer(
569		autorest.AsPost(),
570		autorest.WithBaseURL(client.BaseURI),
571		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForMySQL/servers/{serverName}/restart", pathParameters),
572		autorest.WithQueryParameters(queryParameters))
573	return preparer.Prepare((&http.Request{}).WithContext(ctx))
574}
575
576// RestartSender sends the Restart request. The method will close the
577// http.Response Body if it receives an error.
578func (client ServersClient) RestartSender(req *http.Request) (future ServersRestartFuture, err error) {
579	var resp *http.Response
580	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
581	if err != nil {
582		return
583	}
584	var azf azure.Future
585	azf, err = azure.NewFutureFromResponse(resp)
586	future.FutureAPI = &azf
587	future.Result = func(client ServersClient) (ar autorest.Response, err error) {
588		var done bool
589		done, err = future.DoneWithContext(context.Background(), client)
590		if err != nil {
591			err = autorest.NewErrorWithError(err, "mysql.ServersRestartFuture", "Result", future.Response(), "Polling failure")
592			return
593		}
594		if !done {
595			err = azure.NewAsyncOpIncompleteError("mysql.ServersRestartFuture")
596			return
597		}
598		ar.Response = future.Response()
599		return
600	}
601	return
602}
603
604// RestartResponder handles the response to the Restart request. The method always
605// closes the http.Response Body.
606func (client ServersClient) RestartResponder(resp *http.Response) (result autorest.Response, err error) {
607	err = autorest.Respond(
608		resp,
609		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
610		autorest.ByClosing())
611	result.Response = resp
612	return
613}
614
615// Start starts a stopped server.
616// Parameters:
617// resourceGroupName - the name of the resource group. The name is case insensitive.
618// serverName - the name of the server.
619func (client ServersClient) Start(ctx context.Context, resourceGroupName string, serverName string) (result ServersStartFuture, err error) {
620	if tracing.IsEnabled() {
621		ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Start")
622		defer func() {
623			sc := -1
624			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
625				sc = result.FutureAPI.Response().StatusCode
626			}
627			tracing.EndSpan(ctx, sc, err)
628		}()
629	}
630	if err := validation.Validate([]validation.Validation{
631		{TargetValue: client.SubscriptionID,
632			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
633		{TargetValue: resourceGroupName,
634			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
635				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
636				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
637		return result, validation.NewError("mysql.ServersClient", "Start", err.Error())
638	}
639
640	req, err := client.StartPreparer(ctx, resourceGroupName, serverName)
641	if err != nil {
642		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "Start", nil, "Failure preparing request")
643		return
644	}
645
646	result, err = client.StartSender(req)
647	if err != nil {
648		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "Start", nil, "Failure sending request")
649		return
650	}
651
652	return
653}
654
655// StartPreparer prepares the Start request.
656func (client ServersClient) StartPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) {
657	pathParameters := map[string]interface{}{
658		"resourceGroupName": autorest.Encode("path", resourceGroupName),
659		"serverName":        autorest.Encode("path", serverName),
660		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
661	}
662
663	const APIVersion = "2020-01-01"
664	queryParameters := map[string]interface{}{
665		"api-version": APIVersion,
666	}
667
668	preparer := autorest.CreatePreparer(
669		autorest.AsPost(),
670		autorest.WithBaseURL(client.BaseURI),
671		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/servers/{serverName}/start", pathParameters),
672		autorest.WithQueryParameters(queryParameters))
673	return preparer.Prepare((&http.Request{}).WithContext(ctx))
674}
675
676// StartSender sends the Start request. The method will close the
677// http.Response Body if it receives an error.
678func (client ServersClient) StartSender(req *http.Request) (future ServersStartFuture, err error) {
679	var resp *http.Response
680	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
681	if err != nil {
682		return
683	}
684	var azf azure.Future
685	azf, err = azure.NewFutureFromResponse(resp)
686	future.FutureAPI = &azf
687	future.Result = func(client ServersClient) (ar autorest.Response, err error) {
688		var done bool
689		done, err = future.DoneWithContext(context.Background(), client)
690		if err != nil {
691			err = autorest.NewErrorWithError(err, "mysql.ServersStartFuture", "Result", future.Response(), "Polling failure")
692			return
693		}
694		if !done {
695			err = azure.NewAsyncOpIncompleteError("mysql.ServersStartFuture")
696			return
697		}
698		ar.Response = future.Response()
699		return
700	}
701	return
702}
703
704// StartResponder handles the response to the Start request. The method always
705// closes the http.Response Body.
706func (client ServersClient) StartResponder(resp *http.Response) (result autorest.Response, err error) {
707	err = autorest.Respond(
708		resp,
709		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
710		autorest.ByClosing())
711	result.Response = resp
712	return
713}
714
715// Stop stops a running server.
716// Parameters:
717// resourceGroupName - the name of the resource group. The name is case insensitive.
718// serverName - the name of the server.
719func (client ServersClient) Stop(ctx context.Context, resourceGroupName string, serverName string) (result ServersStopFuture, err error) {
720	if tracing.IsEnabled() {
721		ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Stop")
722		defer func() {
723			sc := -1
724			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
725				sc = result.FutureAPI.Response().StatusCode
726			}
727			tracing.EndSpan(ctx, sc, err)
728		}()
729	}
730	if err := validation.Validate([]validation.Validation{
731		{TargetValue: client.SubscriptionID,
732			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
733		{TargetValue: resourceGroupName,
734			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
735				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
736				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
737		return result, validation.NewError("mysql.ServersClient", "Stop", err.Error())
738	}
739
740	req, err := client.StopPreparer(ctx, resourceGroupName, serverName)
741	if err != nil {
742		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "Stop", nil, "Failure preparing request")
743		return
744	}
745
746	result, err = client.StopSender(req)
747	if err != nil {
748		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "Stop", nil, "Failure sending request")
749		return
750	}
751
752	return
753}
754
755// StopPreparer prepares the Stop request.
756func (client ServersClient) StopPreparer(ctx context.Context, resourceGroupName string, serverName string) (*http.Request, error) {
757	pathParameters := map[string]interface{}{
758		"resourceGroupName": autorest.Encode("path", resourceGroupName),
759		"serverName":        autorest.Encode("path", serverName),
760		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
761	}
762
763	const APIVersion = "2020-01-01"
764	queryParameters := map[string]interface{}{
765		"api-version": APIVersion,
766	}
767
768	preparer := autorest.CreatePreparer(
769		autorest.AsPost(),
770		autorest.WithBaseURL(client.BaseURI),
771		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/servers/{serverName}/stop", pathParameters),
772		autorest.WithQueryParameters(queryParameters))
773	return preparer.Prepare((&http.Request{}).WithContext(ctx))
774}
775
776// StopSender sends the Stop request. The method will close the
777// http.Response Body if it receives an error.
778func (client ServersClient) StopSender(req *http.Request) (future ServersStopFuture, err error) {
779	var resp *http.Response
780	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
781	if err != nil {
782		return
783	}
784	var azf azure.Future
785	azf, err = azure.NewFutureFromResponse(resp)
786	future.FutureAPI = &azf
787	future.Result = func(client ServersClient) (ar autorest.Response, err error) {
788		var done bool
789		done, err = future.DoneWithContext(context.Background(), client)
790		if err != nil {
791			err = autorest.NewErrorWithError(err, "mysql.ServersStopFuture", "Result", future.Response(), "Polling failure")
792			return
793		}
794		if !done {
795			err = azure.NewAsyncOpIncompleteError("mysql.ServersStopFuture")
796			return
797		}
798		ar.Response = future.Response()
799		return
800	}
801	return
802}
803
804// StopResponder handles the response to the Stop request. The method always
805// closes the http.Response Body.
806func (client ServersClient) StopResponder(resp *http.Response) (result autorest.Response, err error) {
807	err = autorest.Respond(
808		resp,
809		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
810		autorest.ByClosing())
811	result.Response = resp
812	return
813}
814
815// Update updates an existing server. The request body can contain one to many of the properties present in the normal
816// server definition.
817// Parameters:
818// resourceGroupName - the name of the resource group. The name is case insensitive.
819// serverName - the name of the server.
820// parameters - the required parameters for updating a server.
821func (client ServersClient) Update(ctx context.Context, resourceGroupName string, serverName string, parameters ServerUpdateParameters) (result ServersUpdateFuture, err error) {
822	if tracing.IsEnabled() {
823		ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Update")
824		defer func() {
825			sc := -1
826			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
827				sc = result.FutureAPI.Response().StatusCode
828			}
829			tracing.EndSpan(ctx, sc, err)
830		}()
831	}
832	if err := validation.Validate([]validation.Validation{
833		{TargetValue: client.SubscriptionID,
834			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
835		{TargetValue: resourceGroupName,
836			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
837				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
838				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
839		return result, validation.NewError("mysql.ServersClient", "Update", err.Error())
840	}
841
842	req, err := client.UpdatePreparer(ctx, resourceGroupName, serverName, parameters)
843	if err != nil {
844		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "Update", nil, "Failure preparing request")
845		return
846	}
847
848	result, err = client.UpdateSender(req)
849	if err != nil {
850		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "Update", nil, "Failure sending request")
851		return
852	}
853
854	return
855}
856
857// UpdatePreparer prepares the Update request.
858func (client ServersClient) UpdatePreparer(ctx context.Context, resourceGroupName string, serverName string, parameters ServerUpdateParameters) (*http.Request, error) {
859	pathParameters := map[string]interface{}{
860		"resourceGroupName": autorest.Encode("path", resourceGroupName),
861		"serverName":        autorest.Encode("path", serverName),
862		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
863	}
864
865	const APIVersion = "2017-12-01"
866	queryParameters := map[string]interface{}{
867		"api-version": APIVersion,
868	}
869
870	preparer := autorest.CreatePreparer(
871		autorest.AsContentType("application/json; charset=utf-8"),
872		autorest.AsPatch(),
873		autorest.WithBaseURL(client.BaseURI),
874		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBForMySQL/servers/{serverName}", pathParameters),
875		autorest.WithJSON(parameters),
876		autorest.WithQueryParameters(queryParameters))
877	return preparer.Prepare((&http.Request{}).WithContext(ctx))
878}
879
880// UpdateSender sends the Update request. The method will close the
881// http.Response Body if it receives an error.
882func (client ServersClient) UpdateSender(req *http.Request) (future ServersUpdateFuture, err error) {
883	var resp *http.Response
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 = func(client ServersClient) (s Server, err error) {
892		var done bool
893		done, err = future.DoneWithContext(context.Background(), client)
894		if err != nil {
895			err = autorest.NewErrorWithError(err, "mysql.ServersUpdateFuture", "Result", future.Response(), "Polling failure")
896			return
897		}
898		if !done {
899			err = azure.NewAsyncOpIncompleteError("mysql.ServersUpdateFuture")
900			return
901		}
902		sender := autorest.DecorateSender(client, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
903		s.Response.Response, err = future.GetResult(sender)
904		if s.Response.Response == nil && err == nil {
905			err = autorest.NewErrorWithError(err, "mysql.ServersUpdateFuture", "Result", nil, "received nil response and error")
906		}
907		if err == nil && s.Response.Response.StatusCode != http.StatusNoContent {
908			s, err = client.UpdateResponder(s.Response.Response)
909			if err != nil {
910				err = autorest.NewErrorWithError(err, "mysql.ServersUpdateFuture", "Result", s.Response.Response, "Failure responding to request")
911			}
912		}
913		return
914	}
915	return
916}
917
918// UpdateResponder handles the response to the Update request. The method always
919// closes the http.Response Body.
920func (client ServersClient) UpdateResponder(resp *http.Response) (result Server, err error) {
921	err = autorest.Respond(
922		resp,
923		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
924		autorest.ByUnmarshallingJSON(&result),
925		autorest.ByClosing())
926	result.Response = autorest.Response{Response: resp}
927	return
928}
929
930// Upgrade upgrade server version.
931// Parameters:
932// resourceGroupName - the name of the resource group. The name is case insensitive.
933// serverName - the name of the server.
934// parameters - the required parameters for updating a server.
935func (client ServersClient) Upgrade(ctx context.Context, resourceGroupName string, serverName string, parameters ServerUpgradeParameters) (result ServersUpgradeFuture, err error) {
936	if tracing.IsEnabled() {
937		ctx = tracing.StartSpan(ctx, fqdn+"/ServersClient.Upgrade")
938		defer func() {
939			sc := -1
940			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
941				sc = result.FutureAPI.Response().StatusCode
942			}
943			tracing.EndSpan(ctx, sc, err)
944		}()
945	}
946	if err := validation.Validate([]validation.Validation{
947		{TargetValue: client.SubscriptionID,
948			Constraints: []validation.Constraint{{Target: "client.SubscriptionID", Name: validation.MinLength, Rule: 1, Chain: nil}}},
949		{TargetValue: resourceGroupName,
950			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MaxLength, Rule: 90, Chain: nil},
951				{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil},
952				{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._\(\)]+$`, Chain: nil}}}}); err != nil {
953		return result, validation.NewError("mysql.ServersClient", "Upgrade", err.Error())
954	}
955
956	req, err := client.UpgradePreparer(ctx, resourceGroupName, serverName, parameters)
957	if err != nil {
958		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "Upgrade", nil, "Failure preparing request")
959		return
960	}
961
962	result, err = client.UpgradeSender(req)
963	if err != nil {
964		err = autorest.NewErrorWithError(err, "mysql.ServersClient", "Upgrade", nil, "Failure sending request")
965		return
966	}
967
968	return
969}
970
971// UpgradePreparer prepares the Upgrade request.
972func (client ServersClient) UpgradePreparer(ctx context.Context, resourceGroupName string, serverName string, parameters ServerUpgradeParameters) (*http.Request, error) {
973	pathParameters := map[string]interface{}{
974		"resourceGroupName": autorest.Encode("path", resourceGroupName),
975		"serverName":        autorest.Encode("path", serverName),
976		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
977	}
978
979	const APIVersion = "2020-01-01"
980	queryParameters := map[string]interface{}{
981		"api-version": APIVersion,
982	}
983
984	preparer := autorest.CreatePreparer(
985		autorest.AsContentType("application/json; charset=utf-8"),
986		autorest.AsPost(),
987		autorest.WithBaseURL(client.BaseURI),
988		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DBforMySQL/servers/{serverName}/upgrade", pathParameters),
989		autorest.WithJSON(parameters),
990		autorest.WithQueryParameters(queryParameters))
991	return preparer.Prepare((&http.Request{}).WithContext(ctx))
992}
993
994// UpgradeSender sends the Upgrade request. The method will close the
995// http.Response Body if it receives an error.
996func (client ServersClient) UpgradeSender(req *http.Request) (future ServersUpgradeFuture, err error) {
997	var resp *http.Response
998	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
999	if err != nil {
1000		return
1001	}
1002	var azf azure.Future
1003	azf, err = azure.NewFutureFromResponse(resp)
1004	future.FutureAPI = &azf
1005	future.Result = func(client ServersClient) (ar autorest.Response, err error) {
1006		var done bool
1007		done, err = future.DoneWithContext(context.Background(), client)
1008		if err != nil {
1009			err = autorest.NewErrorWithError(err, "mysql.ServersUpgradeFuture", "Result", future.Response(), "Polling failure")
1010			return
1011		}
1012		if !done {
1013			err = azure.NewAsyncOpIncompleteError("mysql.ServersUpgradeFuture")
1014			return
1015		}
1016		ar.Response = future.Response()
1017		return
1018	}
1019	return
1020}
1021
1022// UpgradeResponder handles the response to the Upgrade request. The method always
1023// closes the http.Response Body.
1024func (client ServersClient) UpgradeResponder(resp *http.Response) (result autorest.Response, err error) {
1025	err = autorest.Respond(
1026		resp,
1027		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
1028		autorest.ByClosing())
1029	result.Response = resp
1030	return
1031}
1032