1 package dtl
2
3
4
5
6
7
8
9 import (
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
18 type CostInsightClient struct {
19 BaseClient
20 }
21
22
23 func NewCostInsightClient(subscriptionID string) CostInsightClient {
24 return NewCostInsightClientWithBaseURI(DefaultBaseURI, subscriptionID)
25 }
26
27
28
29 func NewCostInsightClientWithBaseURI(baseURI string, subscriptionID string) CostInsightClient {
30 return CostInsightClient{NewWithBaseURI(baseURI, subscriptionID)}
31 }
32
33
34
35
36
37
38 func (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
72 func (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
94
95 func (client CostInsightClient) GetResourceSender(req *http.Request) (*http.Response, error) {
96 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
97 }
98
99
100
101 func (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
112
113
114
115
116 func (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
155 func (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
185
186 func (client CostInsightClient) ListSender(req *http.Request) (*http.Response, error) {
187 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
188 }
189
190
191
192 func (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
203 func (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
224 func (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
240
241
242
243
244 func (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", result.Response(), "Failure sending request")
264 return
265 }
266
267 return
268 }
269
270
271 func (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
293
294 func (client CostInsightClient) RefreshDataSender(req *http.Request) (future CostInsightRefreshDataFuture, err error) {
295 var resp *http.Response
296 future.FutureAPI = &azure.Future{}
297 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
298 if err != nil {
299 return
300 }
301 var azf azure.Future
302 azf, err = azure.NewFutureFromResponse(resp)
303 future.FutureAPI = &azf
304 future.Result = future.result
305 return
306 }
307
308
309
310 func (client CostInsightClient) RefreshDataResponder(resp *http.Response) (result autorest.Response, err error) {
311 err = autorest.Respond(
312 resp,
313 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
314 autorest.ByClosing())
315 result.Response = resp
316 return
317 }
318
View as plain text