1package dtl
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// CostInsightClient is the azure DevTest Labs REST API version 2015-05-21-preview.
18type CostInsightClient struct {
19	BaseClient
20}
21
22// NewCostInsightClient creates an instance of the CostInsightClient client.
23func NewCostInsightClient(subscriptionID string) CostInsightClient {
24	return NewCostInsightClientWithBaseURI(DefaultBaseURI, subscriptionID)
25}
26
27// NewCostInsightClientWithBaseURI creates an instance of the CostInsightClient client using a custom endpoint.  Use
28// this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
29func NewCostInsightClientWithBaseURI(baseURI string, subscriptionID string) CostInsightClient {
30	return CostInsightClient{NewWithBaseURI(baseURI, subscriptionID)}
31}
32
33// GetResource get cost insight.
34// Parameters:
35// resourceGroupName - the name of the resource group.
36// labName - the name of the lab.
37// name - the name of the cost insight.
38func (client CostInsightClient) GetResource(ctx context.Context, resourceGroupName string, labName string, name string) (result CostInsight, err error) {
39	if tracing.IsEnabled() {
40		ctx = tracing.StartSpan(ctx, fqdn+"/CostInsightClient.GetResource")
41		defer func() {
42			sc := -1
43			if result.Response.Response != nil {
44				sc = result.Response.Response.StatusCode
45			}
46			tracing.EndSpan(ctx, sc, err)
47		}()
48	}
49	req, err := client.GetResourcePreparer(ctx, resourceGroupName, labName, name)
50	if err != nil {
51		err = autorest.NewErrorWithError(err, "dtl.CostInsightClient", "GetResource", nil, "Failure preparing request")
52		return
53	}
54
55	resp, err := client.GetResourceSender(req)
56	if err != nil {
57		result.Response = autorest.Response{Response: resp}
58		err = autorest.NewErrorWithError(err, "dtl.CostInsightClient", "GetResource", resp, "Failure sending request")
59		return
60	}
61
62	result, err = client.GetResourceResponder(resp)
63	if err != nil {
64		err = autorest.NewErrorWithError(err, "dtl.CostInsightClient", "GetResource", resp, "Failure responding to request")
65		return
66	}
67
68	return
69}
70
71// GetResourcePreparer prepares the GetResource request.
72func (client CostInsightClient) GetResourcePreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
73	pathParameters := map[string]interface{}{
74		"labName":           autorest.Encode("path", labName),
75		"name":              autorest.Encode("path", name),
76		"resourceGroupName": autorest.Encode("path", resourceGroupName),
77		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
78	}
79
80	const APIVersion = "2015-05-21-preview"
81	queryParameters := map[string]interface{}{
82		"api-version": APIVersion,
83	}
84
85	preparer := autorest.CreatePreparer(
86		autorest.AsGet(),
87		autorest.WithBaseURL(client.BaseURI),
88		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/costinsights/{name}", pathParameters),
89		autorest.WithQueryParameters(queryParameters))
90	return preparer.Prepare((&http.Request{}).WithContext(ctx))
91}
92
93// GetResourceSender sends the GetResource request. The method will close the
94// http.Response Body if it receives an error.
95func (client CostInsightClient) GetResourceSender(req *http.Request) (*http.Response, error) {
96	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
97}
98
99// GetResourceResponder handles the response to the GetResource request. The method always
100// closes the http.Response Body.
101func (client CostInsightClient) GetResourceResponder(resp *http.Response) (result CostInsight, err error) {
102	err = autorest.Respond(
103		resp,
104		azure.WithErrorUnlessStatusCode(http.StatusOK),
105		autorest.ByUnmarshallingJSON(&result),
106		autorest.ByClosing())
107	result.Response = autorest.Response{Response: resp}
108	return
109}
110
111// List list cost insights.
112// Parameters:
113// resourceGroupName - the name of the resource group.
114// labName - the name of the lab.
115// filter - the filter to apply on the operation.
116func (client CostInsightClient) List(ctx context.Context, resourceGroupName string, labName string, filter string, top *int32, orderBy string) (result ResponseWithContinuationCostInsightPage, err error) {
117	if tracing.IsEnabled() {
118		ctx = tracing.StartSpan(ctx, fqdn+"/CostInsightClient.List")
119		defer func() {
120			sc := -1
121			if result.rwcci.Response.Response != nil {
122				sc = result.rwcci.Response.Response.StatusCode
123			}
124			tracing.EndSpan(ctx, sc, err)
125		}()
126	}
127	result.fn = client.listNextResults
128	req, err := client.ListPreparer(ctx, resourceGroupName, labName, filter, top, orderBy)
129	if err != nil {
130		err = autorest.NewErrorWithError(err, "dtl.CostInsightClient", "List", nil, "Failure preparing request")
131		return
132	}
133
134	resp, err := client.ListSender(req)
135	if err != nil {
136		result.rwcci.Response = autorest.Response{Response: resp}
137		err = autorest.NewErrorWithError(err, "dtl.CostInsightClient", "List", resp, "Failure sending request")
138		return
139	}
140
141	result.rwcci, err = client.ListResponder(resp)
142	if err != nil {
143		err = autorest.NewErrorWithError(err, "dtl.CostInsightClient", "List", resp, "Failure responding to request")
144		return
145	}
146	if result.rwcci.hasNextLink() && result.rwcci.IsEmpty() {
147		err = result.NextWithContext(ctx)
148		return
149	}
150
151	return
152}
153
154// ListPreparer prepares the List request.
155func (client CostInsightClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, filter string, top *int32, orderBy string) (*http.Request, error) {
156	pathParameters := map[string]interface{}{
157		"labName":           autorest.Encode("path", labName),
158		"resourceGroupName": autorest.Encode("path", resourceGroupName),
159		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
160	}
161
162	const APIVersion = "2015-05-21-preview"
163	queryParameters := map[string]interface{}{
164		"api-version": APIVersion,
165	}
166	if len(filter) > 0 {
167		queryParameters["$filter"] = autorest.Encode("query", filter)
168	}
169	if top != nil {
170		queryParameters["$top"] = autorest.Encode("query", *top)
171	}
172	if len(orderBy) > 0 {
173		queryParameters["$orderBy"] = autorest.Encode("query", orderBy)
174	}
175
176	preparer := autorest.CreatePreparer(
177		autorest.AsGet(),
178		autorest.WithBaseURL(client.BaseURI),
179		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/costinsights", pathParameters),
180		autorest.WithQueryParameters(queryParameters))
181	return preparer.Prepare((&http.Request{}).WithContext(ctx))
182}
183
184// ListSender sends the List request. The method will close the
185// http.Response Body if it receives an error.
186func (client CostInsightClient) ListSender(req *http.Request) (*http.Response, error) {
187	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
188}
189
190// ListResponder handles the response to the List request. The method always
191// closes the http.Response Body.
192func (client CostInsightClient) ListResponder(resp *http.Response) (result ResponseWithContinuationCostInsight, err error) {
193	err = autorest.Respond(
194		resp,
195		azure.WithErrorUnlessStatusCode(http.StatusOK),
196		autorest.ByUnmarshallingJSON(&result),
197		autorest.ByClosing())
198	result.Response = autorest.Response{Response: resp}
199	return
200}
201
202// listNextResults retrieves the next set of results, if any.
203func (client CostInsightClient) listNextResults(ctx context.Context, lastResults ResponseWithContinuationCostInsight) (result ResponseWithContinuationCostInsight, err error) {
204	req, err := lastResults.responseWithContinuationCostInsightPreparer(ctx)
205	if err != nil {
206		return result, autorest.NewErrorWithError(err, "dtl.CostInsightClient", "listNextResults", nil, "Failure preparing next results request")
207	}
208	if req == nil {
209		return
210	}
211	resp, err := client.ListSender(req)
212	if err != nil {
213		result.Response = autorest.Response{Response: resp}
214		return result, autorest.NewErrorWithError(err, "dtl.CostInsightClient", "listNextResults", resp, "Failure sending next results request")
215	}
216	result, err = client.ListResponder(resp)
217	if err != nil {
218		err = autorest.NewErrorWithError(err, "dtl.CostInsightClient", "listNextResults", resp, "Failure responding to next results request")
219	}
220	return
221}
222
223// ListComplete enumerates all values, automatically crossing page boundaries as required.
224func (client CostInsightClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, filter string, top *int32, orderBy string) (result ResponseWithContinuationCostInsightIterator, err error) {
225	if tracing.IsEnabled() {
226		ctx = tracing.StartSpan(ctx, fqdn+"/CostInsightClient.List")
227		defer func() {
228			sc := -1
229			if result.Response().Response.Response != nil {
230				sc = result.page.Response().Response.Response.StatusCode
231			}
232			tracing.EndSpan(ctx, sc, err)
233		}()
234	}
235	result.page, err = client.List(ctx, resourceGroupName, labName, filter, top, orderBy)
236	return
237}
238
239// RefreshData refresh Lab's Cost Insight Data. This operation can take a while to complete.
240// Parameters:
241// resourceGroupName - the name of the resource group.
242// labName - the name of the lab.
243// name - the name of the cost insight.
244func (client CostInsightClient) RefreshData(ctx context.Context, resourceGroupName string, labName string, name string) (result CostInsightRefreshDataFuture, err error) {
245	if tracing.IsEnabled() {
246		ctx = tracing.StartSpan(ctx, fqdn+"/CostInsightClient.RefreshData")
247		defer func() {
248			sc := -1
249			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
250				sc = result.FutureAPI.Response().StatusCode
251			}
252			tracing.EndSpan(ctx, sc, err)
253		}()
254	}
255	req, err := client.RefreshDataPreparer(ctx, resourceGroupName, labName, name)
256	if err != nil {
257		err = autorest.NewErrorWithError(err, "dtl.CostInsightClient", "RefreshData", nil, "Failure preparing request")
258		return
259	}
260
261	result, err = client.RefreshDataSender(req)
262	if err != nil {
263		err = autorest.NewErrorWithError(err, "dtl.CostInsightClient", "RefreshData", nil, "Failure sending request")
264		return
265	}
266
267	return
268}
269
270// RefreshDataPreparer prepares the RefreshData request.
271func (client CostInsightClient) RefreshDataPreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
272	pathParameters := map[string]interface{}{
273		"labName":           autorest.Encode("path", labName),
274		"name":              autorest.Encode("path", name),
275		"resourceGroupName": autorest.Encode("path", resourceGroupName),
276		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
277	}
278
279	const APIVersion = "2015-05-21-preview"
280	queryParameters := map[string]interface{}{
281		"api-version": APIVersion,
282	}
283
284	preparer := autorest.CreatePreparer(
285		autorest.AsPost(),
286		autorest.WithBaseURL(client.BaseURI),
287		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/costinsights/{name}/refreshData", pathParameters),
288		autorest.WithQueryParameters(queryParameters))
289	return preparer.Prepare((&http.Request{}).WithContext(ctx))
290}
291
292// RefreshDataSender sends the RefreshData request. The method will close the
293// http.Response Body if it receives an error.
294func (client CostInsightClient) RefreshDataSender(req *http.Request) (future CostInsightRefreshDataFuture, err error) {
295	var resp *http.Response
296	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
297	if err != nil {
298		return
299	}
300	var azf azure.Future
301	azf, err = azure.NewFutureFromResponse(resp)
302	future.FutureAPI = &azf
303	future.Result = future.result
304	return
305}
306
307// RefreshDataResponder handles the response to the RefreshData request. The method always
308// closes the http.Response Body.
309func (client CostInsightClient) RefreshDataResponder(resp *http.Response) (result autorest.Response, err error) {
310	err = autorest.Respond(
311		resp,
312		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
313		autorest.ByClosing())
314	result.Response = resp
315	return
316}
317