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/autorest/validation"
14 "github.com/Azure/go-autorest/tracing"
15 "net/http"
16 )
17
18
19 type FormulasClient struct {
20 BaseClient
21 }
22
23
24 func NewFormulasClient(subscriptionID string) FormulasClient {
25 return NewFormulasClientWithBaseURI(DefaultBaseURI, subscriptionID)
26 }
27
28
29
30 func NewFormulasClientWithBaseURI(baseURI string, subscriptionID string) FormulasClient {
31 return FormulasClient{NewWithBaseURI(baseURI, subscriptionID)}
32 }
33
34
35
36
37
38
39
40 func (client FormulasClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, labName string, name string, formula Formula) (result FormulasCreateOrUpdateFuture, err error) {
41 if tracing.IsEnabled() {
42 ctx = tracing.StartSpan(ctx, fqdn+"/FormulasClient.CreateOrUpdate")
43 defer func() {
44 sc := -1
45 if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
46 sc = result.FutureAPI.Response().StatusCode
47 }
48 tracing.EndSpan(ctx, sc, err)
49 }()
50 }
51 if err := validation.Validate([]validation.Validation{
52 {TargetValue: formula,
53 Constraints: []validation.Constraint{{Target: "formula.FormulaProperties", Name: validation.Null, Rule: true,
54 Chain: []validation.Constraint{{Target: "formula.FormulaProperties.FormulaContent", Name: validation.Null, Rule: false,
55 Chain: []validation.Constraint{{Target: "formula.FormulaProperties.FormulaContent.LabVirtualMachineCreationParameterProperties", Name: validation.Null, Rule: false,
56 Chain: []validation.Constraint{{Target: "formula.FormulaProperties.FormulaContent.LabVirtualMachineCreationParameterProperties.ApplicableSchedule", Name: validation.Null, Rule: false,
57 Chain: []validation.Constraint{{Target: "formula.FormulaProperties.FormulaContent.LabVirtualMachineCreationParameterProperties.ApplicableSchedule.ApplicableScheduleProperties", Name: validation.Null, Rule: true,
58 Chain: []validation.Constraint{{Target: "formula.FormulaProperties.FormulaContent.LabVirtualMachineCreationParameterProperties.ApplicableSchedule.ApplicableScheduleProperties.LabVmsShutdown", Name: validation.Null, Rule: false,
59 Chain: []validation.Constraint{{Target: "formula.FormulaProperties.FormulaContent.LabVirtualMachineCreationParameterProperties.ApplicableSchedule.ApplicableScheduleProperties.LabVmsShutdown.ScheduleProperties", Name: validation.Null, Rule: true, Chain: nil}}},
60 {Target: "formula.FormulaProperties.FormulaContent.LabVirtualMachineCreationParameterProperties.ApplicableSchedule.ApplicableScheduleProperties.LabVmsStartup", Name: validation.Null, Rule: false,
61 Chain: []validation.Constraint{{Target: "formula.FormulaProperties.FormulaContent.LabVirtualMachineCreationParameterProperties.ApplicableSchedule.ApplicableScheduleProperties.LabVmsStartup.ScheduleProperties", Name: validation.Null, Rule: true, Chain: nil}}},
62 }},
63 }},
64 }},
65 }},
66 }}}}}); err != nil {
67 return result, validation.NewError("dtl.FormulasClient", "CreateOrUpdate", err.Error())
68 }
69
70 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, labName, name, formula)
71 if err != nil {
72 err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "CreateOrUpdate", nil, "Failure preparing request")
73 return
74 }
75
76 result, err = client.CreateOrUpdateSender(req)
77 if err != nil {
78 err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "CreateOrUpdate", result.Response(), "Failure sending request")
79 return
80 }
81
82 return
83 }
84
85
86 func (client FormulasClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, labName string, name string, formula Formula) (*http.Request, error) {
87 pathParameters := map[string]interface{}{
88 "labName": autorest.Encode("path", labName),
89 "name": autorest.Encode("path", name),
90 "resourceGroupName": autorest.Encode("path", resourceGroupName),
91 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
92 }
93
94 const APIVersion = "2016-05-15"
95 queryParameters := map[string]interface{}{
96 "api-version": APIVersion,
97 }
98
99 preparer := autorest.CreatePreparer(
100 autorest.AsContentType("application/json; charset=utf-8"),
101 autorest.AsPut(),
102 autorest.WithBaseURL(client.BaseURI),
103 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}", pathParameters),
104 autorest.WithJSON(formula),
105 autorest.WithQueryParameters(queryParameters))
106 return preparer.Prepare((&http.Request{}).WithContext(ctx))
107 }
108
109
110
111 func (client FormulasClient) CreateOrUpdateSender(req *http.Request) (future FormulasCreateOrUpdateFuture, err error) {
112 var resp *http.Response
113 future.FutureAPI = &azure.Future{}
114 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
115 if err != nil {
116 return
117 }
118 var azf azure.Future
119 azf, err = azure.NewFutureFromResponse(resp)
120 future.FutureAPI = &azf
121 future.Result = future.result
122 return
123 }
124
125
126
127 func (client FormulasClient) CreateOrUpdateResponder(resp *http.Response) (result Formula, err error) {
128 err = autorest.Respond(
129 resp,
130 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
131 autorest.ByUnmarshallingJSON(&result),
132 autorest.ByClosing())
133 result.Response = autorest.Response{Response: resp}
134 return
135 }
136
137
138
139
140
141
142 func (client FormulasClient) Delete(ctx context.Context, resourceGroupName string, labName string, name string) (result autorest.Response, err error) {
143 if tracing.IsEnabled() {
144 ctx = tracing.StartSpan(ctx, fqdn+"/FormulasClient.Delete")
145 defer func() {
146 sc := -1
147 if result.Response != nil {
148 sc = result.Response.StatusCode
149 }
150 tracing.EndSpan(ctx, sc, err)
151 }()
152 }
153 req, err := client.DeletePreparer(ctx, resourceGroupName, labName, name)
154 if err != nil {
155 err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Delete", nil, "Failure preparing request")
156 return
157 }
158
159 resp, err := client.DeleteSender(req)
160 if err != nil {
161 result.Response = resp
162 err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Delete", resp, "Failure sending request")
163 return
164 }
165
166 result, err = client.DeleteResponder(resp)
167 if err != nil {
168 err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Delete", resp, "Failure responding to request")
169 return
170 }
171
172 return
173 }
174
175
176 func (client FormulasClient) DeletePreparer(ctx context.Context, resourceGroupName string, labName string, name string) (*http.Request, error) {
177 pathParameters := map[string]interface{}{
178 "labName": autorest.Encode("path", labName),
179 "name": autorest.Encode("path", name),
180 "resourceGroupName": autorest.Encode("path", resourceGroupName),
181 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
182 }
183
184 const APIVersion = "2016-05-15"
185 queryParameters := map[string]interface{}{
186 "api-version": APIVersion,
187 }
188
189 preparer := autorest.CreatePreparer(
190 autorest.AsDelete(),
191 autorest.WithBaseURL(client.BaseURI),
192 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}", pathParameters),
193 autorest.WithQueryParameters(queryParameters))
194 return preparer.Prepare((&http.Request{}).WithContext(ctx))
195 }
196
197
198
199 func (client FormulasClient) DeleteSender(req *http.Request) (*http.Response, error) {
200 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
201 }
202
203
204
205 func (client FormulasClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
206 err = autorest.Respond(
207 resp,
208 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
209 autorest.ByClosing())
210 result.Response = resp
211 return
212 }
213
214
215
216
217
218
219
220 func (client FormulasClient) Get(ctx context.Context, resourceGroupName string, labName string, name string, expand string) (result Formula, err error) {
221 if tracing.IsEnabled() {
222 ctx = tracing.StartSpan(ctx, fqdn+"/FormulasClient.Get")
223 defer func() {
224 sc := -1
225 if result.Response.Response != nil {
226 sc = result.Response.Response.StatusCode
227 }
228 tracing.EndSpan(ctx, sc, err)
229 }()
230 }
231 req, err := client.GetPreparer(ctx, resourceGroupName, labName, name, expand)
232 if err != nil {
233 err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Get", nil, "Failure preparing request")
234 return
235 }
236
237 resp, err := client.GetSender(req)
238 if err != nil {
239 result.Response = autorest.Response{Response: resp}
240 err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Get", resp, "Failure sending request")
241 return
242 }
243
244 result, err = client.GetResponder(resp)
245 if err != nil {
246 err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "Get", resp, "Failure responding to request")
247 return
248 }
249
250 return
251 }
252
253
254 func (client FormulasClient) GetPreparer(ctx context.Context, resourceGroupName string, labName string, name string, expand string) (*http.Request, error) {
255 pathParameters := map[string]interface{}{
256 "labName": autorest.Encode("path", labName),
257 "name": autorest.Encode("path", name),
258 "resourceGroupName": autorest.Encode("path", resourceGroupName),
259 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
260 }
261
262 const APIVersion = "2016-05-15"
263 queryParameters := map[string]interface{}{
264 "api-version": APIVersion,
265 }
266 if len(expand) > 0 {
267 queryParameters["$expand"] = autorest.Encode("query", expand)
268 }
269
270 preparer := autorest.CreatePreparer(
271 autorest.AsGet(),
272 autorest.WithBaseURL(client.BaseURI),
273 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas/{name}", pathParameters),
274 autorest.WithQueryParameters(queryParameters))
275 return preparer.Prepare((&http.Request{}).WithContext(ctx))
276 }
277
278
279
280 func (client FormulasClient) GetSender(req *http.Request) (*http.Response, error) {
281 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
282 }
283
284
285
286 func (client FormulasClient) GetResponder(resp *http.Response) (result Formula, err error) {
287 err = autorest.Respond(
288 resp,
289 azure.WithErrorUnlessStatusCode(http.StatusOK),
290 autorest.ByUnmarshallingJSON(&result),
291 autorest.ByClosing())
292 result.Response = autorest.Response{Response: resp}
293 return
294 }
295
296
297
298
299
300
301
302
303
304 func (client FormulasClient) List(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationFormulaPage, err error) {
305 if tracing.IsEnabled() {
306 ctx = tracing.StartSpan(ctx, fqdn+"/FormulasClient.List")
307 defer func() {
308 sc := -1
309 if result.rwcf.Response.Response != nil {
310 sc = result.rwcf.Response.Response.StatusCode
311 }
312 tracing.EndSpan(ctx, sc, err)
313 }()
314 }
315 result.fn = client.listNextResults
316 req, err := client.ListPreparer(ctx, resourceGroupName, labName, expand, filter, top, orderby)
317 if err != nil {
318 err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "List", nil, "Failure preparing request")
319 return
320 }
321
322 resp, err := client.ListSender(req)
323 if err != nil {
324 result.rwcf.Response = autorest.Response{Response: resp}
325 err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "List", resp, "Failure sending request")
326 return
327 }
328
329 result.rwcf, err = client.ListResponder(resp)
330 if err != nil {
331 err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "List", resp, "Failure responding to request")
332 return
333 }
334 if result.rwcf.hasNextLink() && result.rwcf.IsEmpty() {
335 err = result.NextWithContext(ctx)
336 return
337 }
338
339 return
340 }
341
342
343 func (client FormulasClient) ListPreparer(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (*http.Request, error) {
344 pathParameters := map[string]interface{}{
345 "labName": autorest.Encode("path", labName),
346 "resourceGroupName": autorest.Encode("path", resourceGroupName),
347 "subscriptionId": autorest.Encode("path", client.SubscriptionID),
348 }
349
350 const APIVersion = "2016-05-15"
351 queryParameters := map[string]interface{}{
352 "api-version": APIVersion,
353 }
354 if len(expand) > 0 {
355 queryParameters["$expand"] = autorest.Encode("query", expand)
356 }
357 if len(filter) > 0 {
358 queryParameters["$filter"] = autorest.Encode("query", filter)
359 }
360 if top != nil {
361 queryParameters["$top"] = autorest.Encode("query", *top)
362 }
363 if len(orderby) > 0 {
364 queryParameters["$orderby"] = autorest.Encode("query", orderby)
365 }
366
367 preparer := autorest.CreatePreparer(
368 autorest.AsGet(),
369 autorest.WithBaseURL(client.BaseURI),
370 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/formulas", pathParameters),
371 autorest.WithQueryParameters(queryParameters))
372 return preparer.Prepare((&http.Request{}).WithContext(ctx))
373 }
374
375
376
377 func (client FormulasClient) ListSender(req *http.Request) (*http.Response, error) {
378 return client.Send(req, azure.DoRetryWithRegistration(client.Client))
379 }
380
381
382
383 func (client FormulasClient) ListResponder(resp *http.Response) (result ResponseWithContinuationFormula, err error) {
384 err = autorest.Respond(
385 resp,
386 azure.WithErrorUnlessStatusCode(http.StatusOK),
387 autorest.ByUnmarshallingJSON(&result),
388 autorest.ByClosing())
389 result.Response = autorest.Response{Response: resp}
390 return
391 }
392
393
394 func (client FormulasClient) listNextResults(ctx context.Context, lastResults ResponseWithContinuationFormula) (result ResponseWithContinuationFormula, err error) {
395 req, err := lastResults.responseWithContinuationFormulaPreparer(ctx)
396 if err != nil {
397 return result, autorest.NewErrorWithError(err, "dtl.FormulasClient", "listNextResults", nil, "Failure preparing next results request")
398 }
399 if req == nil {
400 return
401 }
402 resp, err := client.ListSender(req)
403 if err != nil {
404 result.Response = autorest.Response{Response: resp}
405 return result, autorest.NewErrorWithError(err, "dtl.FormulasClient", "listNextResults", resp, "Failure sending next results request")
406 }
407 result, err = client.ListResponder(resp)
408 if err != nil {
409 err = autorest.NewErrorWithError(err, "dtl.FormulasClient", "listNextResults", resp, "Failure responding to next results request")
410 }
411 return
412 }
413
414
415 func (client FormulasClient) ListComplete(ctx context.Context, resourceGroupName string, labName string, expand string, filter string, top *int32, orderby string) (result ResponseWithContinuationFormulaIterator, err error) {
416 if tracing.IsEnabled() {
417 ctx = tracing.StartSpan(ctx, fqdn+"/FormulasClient.List")
418 defer func() {
419 sc := -1
420 if result.Response().Response.Response != nil {
421 sc = result.page.Response().Response.Response.StatusCode
422 }
423 tracing.EndSpan(ctx, sc, err)
424 }()
425 }
426 result.page, err = client.List(ctx, resourceGroupName, labName, expand, filter, top, orderby)
427 return
428 }
429
View as plain text