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