1package sqlvirtualmachine
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/tracing"
14	"net/http"
15)
16
17// OperationsClient is the the SQL virtual machine management API provides a RESTful set of web APIs that interact with
18// Azure Compute, Network & Storage services to manage your SQL Server virtual machine. The API enables users to
19// create, delete and retrieve a SQL virtual machine, SQL virtual machine group or availability group listener.
20type OperationsClient struct {
21	BaseClient
22}
23
24// NewOperationsClient creates an instance of the OperationsClient client.
25func NewOperationsClient(subscriptionID string) OperationsClient {
26	return NewOperationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
27}
28
29// NewOperationsClientWithBaseURI creates an instance of the OperationsClient client using a custom endpoint.  Use this
30// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
31func NewOperationsClientWithBaseURI(baseURI string, subscriptionID string) OperationsClient {
32	return OperationsClient{NewWithBaseURI(baseURI, subscriptionID)}
33}
34
35// List lists all of the available SQL Rest API operations.
36func (client OperationsClient) List(ctx context.Context) (result OperationListResultPage, err error) {
37	if tracing.IsEnabled() {
38		ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List")
39		defer func() {
40			sc := -1
41			if result.olr.Response.Response != nil {
42				sc = result.olr.Response.Response.StatusCode
43			}
44			tracing.EndSpan(ctx, sc, err)
45		}()
46	}
47	result.fn = client.listNextResults
48	req, err := client.ListPreparer(ctx)
49	if err != nil {
50		err = autorest.NewErrorWithError(err, "sqlvirtualmachine.OperationsClient", "List", nil, "Failure preparing request")
51		return
52	}
53
54	resp, err := client.ListSender(req)
55	if err != nil {
56		result.olr.Response = autorest.Response{Response: resp}
57		err = autorest.NewErrorWithError(err, "sqlvirtualmachine.OperationsClient", "List", resp, "Failure sending request")
58		return
59	}
60
61	result.olr, err = client.ListResponder(resp)
62	if err != nil {
63		err = autorest.NewErrorWithError(err, "sqlvirtualmachine.OperationsClient", "List", resp, "Failure responding to request")
64		return
65	}
66	if result.olr.hasNextLink() && result.olr.IsEmpty() {
67		err = result.NextWithContext(ctx)
68		return
69	}
70
71	return
72}
73
74// ListPreparer prepares the List request.
75func (client OperationsClient) ListPreparer(ctx context.Context) (*http.Request, error) {
76	const APIVersion = "2017-03-01-preview"
77	queryParameters := map[string]interface{}{
78		"api-version": APIVersion,
79	}
80
81	preparer := autorest.CreatePreparer(
82		autorest.AsGet(),
83		autorest.WithBaseURL(client.BaseURI),
84		autorest.WithPath("/providers/Microsoft.SqlVirtualMachine/operations"),
85		autorest.WithQueryParameters(queryParameters))
86	return preparer.Prepare((&http.Request{}).WithContext(ctx))
87}
88
89// ListSender sends the List request. The method will close the
90// http.Response Body if it receives an error.
91func (client OperationsClient) ListSender(req *http.Request) (*http.Response, error) {
92	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
93}
94
95// ListResponder handles the response to the List request. The method always
96// closes the http.Response Body.
97func (client OperationsClient) ListResponder(resp *http.Response) (result OperationListResult, err error) {
98	err = autorest.Respond(
99		resp,
100		azure.WithErrorUnlessStatusCode(http.StatusOK),
101		autorest.ByUnmarshallingJSON(&result),
102		autorest.ByClosing())
103	result.Response = autorest.Response{Response: resp}
104	return
105}
106
107// listNextResults retrieves the next set of results, if any.
108func (client OperationsClient) listNextResults(ctx context.Context, lastResults OperationListResult) (result OperationListResult, err error) {
109	req, err := lastResults.operationListResultPreparer(ctx)
110	if err != nil {
111		return result, autorest.NewErrorWithError(err, "sqlvirtualmachine.OperationsClient", "listNextResults", nil, "Failure preparing next results request")
112	}
113	if req == nil {
114		return
115	}
116	resp, err := client.ListSender(req)
117	if err != nil {
118		result.Response = autorest.Response{Response: resp}
119		return result, autorest.NewErrorWithError(err, "sqlvirtualmachine.OperationsClient", "listNextResults", resp, "Failure sending next results request")
120	}
121	result, err = client.ListResponder(resp)
122	if err != nil {
123		err = autorest.NewErrorWithError(err, "sqlvirtualmachine.OperationsClient", "listNextResults", resp, "Failure responding to next results request")
124	}
125	return
126}
127
128// ListComplete enumerates all values, automatically crossing page boundaries as required.
129func (client OperationsClient) ListComplete(ctx context.Context) (result OperationListResultIterator, err error) {
130	if tracing.IsEnabled() {
131		ctx = tracing.StartSpan(ctx, fqdn+"/OperationsClient.List")
132		defer func() {
133			sc := -1
134			if result.Response().Response.Response != nil {
135				sc = result.page.Response().Response.Response.StatusCode
136			}
137			tracing.EndSpan(ctx, sc, err)
138		}()
139	}
140	result.page, err = client.List(ctx)
141	return
142}
143