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