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