1package hdinsight
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/tracing"
25	"net/http"
26)
27
28// LocationsClient is the hDInsight Management Client
29type LocationsClient struct {
30	BaseClient
31}
32
33// NewLocationsClient creates an instance of the LocationsClient client.
34func NewLocationsClient(subscriptionID string) LocationsClient {
35	return NewLocationsClientWithBaseURI(DefaultBaseURI, subscriptionID)
36}
37
38// NewLocationsClientWithBaseURI creates an instance of the LocationsClient client using a custom endpoint.  Use this
39// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
40func NewLocationsClientWithBaseURI(baseURI string, subscriptionID string) LocationsClient {
41	return LocationsClient{NewWithBaseURI(baseURI, subscriptionID)}
42}
43
44// GetCapabilities gets the capabilities for the specified location.
45// Parameters:
46// location - the Azure location (region) for which to make the request.
47func (client LocationsClient) GetCapabilities(ctx context.Context, location string) (result CapabilitiesResult, err error) {
48	if tracing.IsEnabled() {
49		ctx = tracing.StartSpan(ctx, fqdn+"/LocationsClient.GetCapabilities")
50		defer func() {
51			sc := -1
52			if result.Response.Response != nil {
53				sc = result.Response.Response.StatusCode
54			}
55			tracing.EndSpan(ctx, sc, err)
56		}()
57	}
58	req, err := client.GetCapabilitiesPreparer(ctx, location)
59	if err != nil {
60		err = autorest.NewErrorWithError(err, "hdinsight.LocationsClient", "GetCapabilities", nil, "Failure preparing request")
61		return
62	}
63
64	resp, err := client.GetCapabilitiesSender(req)
65	if err != nil {
66		result.Response = autorest.Response{Response: resp}
67		err = autorest.NewErrorWithError(err, "hdinsight.LocationsClient", "GetCapabilities", resp, "Failure sending request")
68		return
69	}
70
71	result, err = client.GetCapabilitiesResponder(resp)
72	if err != nil {
73		err = autorest.NewErrorWithError(err, "hdinsight.LocationsClient", "GetCapabilities", resp, "Failure responding to request")
74		return
75	}
76
77	return
78}
79
80// GetCapabilitiesPreparer prepares the GetCapabilities request.
81func (client LocationsClient) GetCapabilitiesPreparer(ctx context.Context, location string) (*http.Request, error) {
82	pathParameters := map[string]interface{}{
83		"location":       autorest.Encode("path", location),
84		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
85	}
86
87	const APIVersion = "2015-03-01-preview"
88	queryParameters := map[string]interface{}{
89		"api-version": APIVersion,
90	}
91
92	preparer := autorest.CreatePreparer(
93		autorest.AsGet(),
94		autorest.WithBaseURL(client.BaseURI),
95		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.HDInsight/locations/{location}/capabilities", pathParameters),
96		autorest.WithQueryParameters(queryParameters))
97	return preparer.Prepare((&http.Request{}).WithContext(ctx))
98}
99
100// GetCapabilitiesSender sends the GetCapabilities request. The method will close the
101// http.Response Body if it receives an error.
102func (client LocationsClient) GetCapabilitiesSender(req *http.Request) (*http.Response, error) {
103	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
104}
105
106// GetCapabilitiesResponder handles the response to the GetCapabilities request. The method always
107// closes the http.Response Body.
108func (client LocationsClient) GetCapabilitiesResponder(resp *http.Response) (result CapabilitiesResult, err error) {
109	err = autorest.Respond(
110		resp,
111		azure.WithErrorUnlessStatusCode(http.StatusOK),
112		autorest.ByUnmarshallingJSON(&result),
113		autorest.ByClosing())
114	result.Response = autorest.Response{Response: resp}
115	return
116}
117
118// ListBillingSpecs lists the billingSpecs for the specified subscription and location.
119// Parameters:
120// location - the Azure location (region) for which to make the request.
121func (client LocationsClient) ListBillingSpecs(ctx context.Context, location string) (result BillingResponseListResult, err error) {
122	if tracing.IsEnabled() {
123		ctx = tracing.StartSpan(ctx, fqdn+"/LocationsClient.ListBillingSpecs")
124		defer func() {
125			sc := -1
126			if result.Response.Response != nil {
127				sc = result.Response.Response.StatusCode
128			}
129			tracing.EndSpan(ctx, sc, err)
130		}()
131	}
132	req, err := client.ListBillingSpecsPreparer(ctx, location)
133	if err != nil {
134		err = autorest.NewErrorWithError(err, "hdinsight.LocationsClient", "ListBillingSpecs", nil, "Failure preparing request")
135		return
136	}
137
138	resp, err := client.ListBillingSpecsSender(req)
139	if err != nil {
140		result.Response = autorest.Response{Response: resp}
141		err = autorest.NewErrorWithError(err, "hdinsight.LocationsClient", "ListBillingSpecs", resp, "Failure sending request")
142		return
143	}
144
145	result, err = client.ListBillingSpecsResponder(resp)
146	if err != nil {
147		err = autorest.NewErrorWithError(err, "hdinsight.LocationsClient", "ListBillingSpecs", resp, "Failure responding to request")
148		return
149	}
150
151	return
152}
153
154// ListBillingSpecsPreparer prepares the ListBillingSpecs request.
155func (client LocationsClient) ListBillingSpecsPreparer(ctx context.Context, location string) (*http.Request, error) {
156	pathParameters := map[string]interface{}{
157		"location":       autorest.Encode("path", location),
158		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
159	}
160
161	const APIVersion = "2015-03-01-preview"
162	queryParameters := map[string]interface{}{
163		"api-version": APIVersion,
164	}
165
166	preparer := autorest.CreatePreparer(
167		autorest.AsGet(),
168		autorest.WithBaseURL(client.BaseURI),
169		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.HDInsight/locations/{location}/billingSpecs", pathParameters),
170		autorest.WithQueryParameters(queryParameters))
171	return preparer.Prepare((&http.Request{}).WithContext(ctx))
172}
173
174// ListBillingSpecsSender sends the ListBillingSpecs request. The method will close the
175// http.Response Body if it receives an error.
176func (client LocationsClient) ListBillingSpecsSender(req *http.Request) (*http.Response, error) {
177	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
178}
179
180// ListBillingSpecsResponder handles the response to the ListBillingSpecs request. The method always
181// closes the http.Response Body.
182func (client LocationsClient) ListBillingSpecsResponder(resp *http.Response) (result BillingResponseListResult, err error) {
183	err = autorest.Respond(
184		resp,
185		azure.WithErrorUnlessStatusCode(http.StatusOK),
186		autorest.ByUnmarshallingJSON(&result),
187		autorest.ByClosing())
188	result.Response = autorest.Response{Response: resp}
189	return
190}
191
192// ListUsages lists the usages for the specified location.
193// Parameters:
194// location - the Azure location (region) for which to make the request.
195func (client LocationsClient) ListUsages(ctx context.Context, location string) (result UsagesListResult, err error) {
196	if tracing.IsEnabled() {
197		ctx = tracing.StartSpan(ctx, fqdn+"/LocationsClient.ListUsages")
198		defer func() {
199			sc := -1
200			if result.Response.Response != nil {
201				sc = result.Response.Response.StatusCode
202			}
203			tracing.EndSpan(ctx, sc, err)
204		}()
205	}
206	req, err := client.ListUsagesPreparer(ctx, location)
207	if err != nil {
208		err = autorest.NewErrorWithError(err, "hdinsight.LocationsClient", "ListUsages", nil, "Failure preparing request")
209		return
210	}
211
212	resp, err := client.ListUsagesSender(req)
213	if err != nil {
214		result.Response = autorest.Response{Response: resp}
215		err = autorest.NewErrorWithError(err, "hdinsight.LocationsClient", "ListUsages", resp, "Failure sending request")
216		return
217	}
218
219	result, err = client.ListUsagesResponder(resp)
220	if err != nil {
221		err = autorest.NewErrorWithError(err, "hdinsight.LocationsClient", "ListUsages", resp, "Failure responding to request")
222		return
223	}
224
225	return
226}
227
228// ListUsagesPreparer prepares the ListUsages request.
229func (client LocationsClient) ListUsagesPreparer(ctx context.Context, location string) (*http.Request, error) {
230	pathParameters := map[string]interface{}{
231		"location":       autorest.Encode("path", location),
232		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
233	}
234
235	const APIVersion = "2015-03-01-preview"
236	queryParameters := map[string]interface{}{
237		"api-version": APIVersion,
238	}
239
240	preparer := autorest.CreatePreparer(
241		autorest.AsGet(),
242		autorest.WithBaseURL(client.BaseURI),
243		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.HDInsight/locations/{location}/usages", pathParameters),
244		autorest.WithQueryParameters(queryParameters))
245	return preparer.Prepare((&http.Request{}).WithContext(ctx))
246}
247
248// ListUsagesSender sends the ListUsages request. The method will close the
249// http.Response Body if it receives an error.
250func (client LocationsClient) ListUsagesSender(req *http.Request) (*http.Response, error) {
251	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
252}
253
254// ListUsagesResponder handles the response to the ListUsages request. The method always
255// closes the http.Response Body.
256func (client LocationsClient) ListUsagesResponder(resp *http.Response) (result UsagesListResult, err error) {
257	err = autorest.Respond(
258		resp,
259		azure.WithErrorUnlessStatusCode(http.StatusOK),
260		autorest.ByUnmarshallingJSON(&result),
261		autorest.ByClosing())
262	result.Response = autorest.Response{Response: resp}
263	return
264}
265