forked from Azure/azure-sdk-for-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
account.go
351 lines (323 loc) · 15.3 KB
/
account.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
package batch
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
//
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
import (
"context"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure"
"github.com/Azure/go-autorest/autorest/date"
"github.com/Azure/go-autorest/autorest/validation"
"github.com/Azure/go-autorest/tracing"
"github.com/gofrs/uuid"
"net/http"
)
// AccountClient is the a client for issuing REST requests to the Azure Batch service.
type AccountClient struct {
BaseClient
}
// NewAccountClient creates an instance of the AccountClient client.
func NewAccountClient(batchURL string) AccountClient {
return AccountClient{New(batchURL)}
}
// ListPoolNodeCounts gets the number of Compute Nodes in each state, grouped by Pool.
// Parameters:
// filter - an OData $filter clause. For more information on constructing this filter, see
// https://docs.microsoft.com/en-us/rest/api/batchservice/odata-filters-in-batch.
// maxResults - the maximum number of items to return in the response.
// timeout - the maximum time that the server can spend processing the request, in seconds. The default is 30
// seconds.
// clientRequestID - the caller-generated request identity, in the form of a GUID with no decoration such as
// curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
// returnClientRequestID - whether the server should return the client-request-id in the response.
// ocpDate - the time the request was issued. Client libraries typically set this to the current system clock
// time; set it explicitly if you are calling the REST API directly.
func (client AccountClient) ListPoolNodeCounts(ctx context.Context, filter string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result PoolNodeCountsListResultPage, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.ListPoolNodeCounts")
defer func() {
sc := -1
if result.pnclr.Response.Response != nil {
sc = result.pnclr.Response.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
if err := validation.Validate([]validation.Validation{
{TargetValue: maxResults,
Constraints: []validation.Constraint{{Target: "maxResults", Name: validation.Null, Rule: false,
Chain: []validation.Constraint{{Target: "maxResults", Name: validation.InclusiveMaximum, Rule: int64(10), Chain: nil},
{Target: "maxResults", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
}}}}}); err != nil {
return result, validation.NewError("batch.AccountClient", "ListPoolNodeCounts", err.Error())
}
result.fn = client.listPoolNodeCountsNextResults
req, err := client.ListPoolNodeCountsPreparer(ctx, filter, maxResults, timeout, clientRequestID, returnClientRequestID, ocpDate)
if err != nil {
err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListPoolNodeCounts", nil, "Failure preparing request")
return
}
resp, err := client.ListPoolNodeCountsSender(req)
if err != nil {
result.pnclr.Response = autorest.Response{Response: resp}
err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListPoolNodeCounts", resp, "Failure sending request")
return
}
result.pnclr, err = client.ListPoolNodeCountsResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListPoolNodeCounts", resp, "Failure responding to request")
return
}
if result.pnclr.hasNextLink() && result.pnclr.IsEmpty() {
err = result.NextWithContext(ctx)
return
}
return
}
// ListPoolNodeCountsPreparer prepares the ListPoolNodeCounts request.
func (client AccountClient) ListPoolNodeCountsPreparer(ctx context.Context, filter string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (*http.Request, error) {
urlParameters := map[string]interface{}{
"batchUrl": client.BatchURL,
}
const APIVersion = "2019-06-01.9.0"
queryParameters := map[string]interface{}{
"api-version": APIVersion,
}
if len(filter) > 0 {
queryParameters["$filter"] = autorest.Encode("query", filter)
}
if maxResults != nil {
queryParameters["maxresults"] = autorest.Encode("query", *maxResults)
} else {
queryParameters["maxresults"] = autorest.Encode("query", 10)
}
if timeout != nil {
queryParameters["timeout"] = autorest.Encode("query", *timeout)
} else {
queryParameters["timeout"] = autorest.Encode("query", 30)
}
preparer := autorest.CreatePreparer(
autorest.AsGet(),
autorest.WithCustomBaseURL("{batchUrl}", urlParameters),
autorest.WithPath("/nodecounts"),
autorest.WithQueryParameters(queryParameters))
if clientRequestID != nil {
preparer = autorest.DecoratePreparer(preparer,
autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
}
if returnClientRequestID != nil {
preparer = autorest.DecoratePreparer(preparer,
autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
} else {
preparer = autorest.DecoratePreparer(preparer,
autorest.WithHeader("return-client-request-id", autorest.String(false)))
}
if ocpDate != nil {
preparer = autorest.DecoratePreparer(preparer,
autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
}
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// ListPoolNodeCountsSender sends the ListPoolNodeCounts request. The method will close the
// http.Response Body if it receives an error.
func (client AccountClient) ListPoolNodeCountsSender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// ListPoolNodeCountsResponder handles the response to the ListPoolNodeCounts request. The method always
// closes the http.Response Body.
func (client AccountClient) ListPoolNodeCountsResponder(resp *http.Response) (result PoolNodeCountsListResult, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByUnmarshallingJSON(&result),
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
// listPoolNodeCountsNextResults retrieves the next set of results, if any.
func (client AccountClient) listPoolNodeCountsNextResults(ctx context.Context, lastResults PoolNodeCountsListResult) (result PoolNodeCountsListResult, err error) {
req, err := lastResults.poolNodeCountsListResultPreparer(ctx)
if err != nil {
return result, autorest.NewErrorWithError(err, "batch.AccountClient", "listPoolNodeCountsNextResults", nil, "Failure preparing next results request")
}
if req == nil {
return
}
resp, err := client.ListPoolNodeCountsSender(req)
if err != nil {
result.Response = autorest.Response{Response: resp}
return result, autorest.NewErrorWithError(err, "batch.AccountClient", "listPoolNodeCountsNextResults", resp, "Failure sending next results request")
}
result, err = client.ListPoolNodeCountsResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "batch.AccountClient", "listPoolNodeCountsNextResults", resp, "Failure responding to next results request")
}
return
}
// ListPoolNodeCountsComplete enumerates all values, automatically crossing page boundaries as required.
func (client AccountClient) ListPoolNodeCountsComplete(ctx context.Context, filter string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result PoolNodeCountsListResultIterator, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.ListPoolNodeCounts")
defer func() {
sc := -1
if result.Response().Response.Response != nil {
sc = result.page.Response().Response.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
result.page, err = client.ListPoolNodeCounts(ctx, filter, maxResults, timeout, clientRequestID, returnClientRequestID, ocpDate)
return
}
// ListSupportedImages sends the list supported images request.
// Parameters:
// filter - an OData $filter clause. For more information on constructing this filter, see
// https://docs.microsoft.com/en-us/rest/api/batchservice/odata-filters-in-batch#list-support-images.
// maxResults - the maximum number of items to return in the response. A maximum of 1000 results will be
// returned.
// timeout - the maximum time that the server can spend processing the request, in seconds. The default is 30
// seconds.
// clientRequestID - the caller-generated request identity, in the form of a GUID with no decoration such as
// curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
// returnClientRequestID - whether the server should return the client-request-id in the response.
// ocpDate - the time the request was issued. Client libraries typically set this to the current system clock
// time; set it explicitly if you are calling the REST API directly.
func (client AccountClient) ListSupportedImages(ctx context.Context, filter string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result AccountListSupportedImagesResultPage, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.ListSupportedImages")
defer func() {
sc := -1
if result.alsir.Response.Response != nil {
sc = result.alsir.Response.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
if err := validation.Validate([]validation.Validation{
{TargetValue: maxResults,
Constraints: []validation.Constraint{{Target: "maxResults", Name: validation.Null, Rule: false,
Chain: []validation.Constraint{{Target: "maxResults", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
{Target: "maxResults", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
}}}}}); err != nil {
return result, validation.NewError("batch.AccountClient", "ListSupportedImages", err.Error())
}
result.fn = client.listSupportedImagesNextResults
req, err := client.ListSupportedImagesPreparer(ctx, filter, maxResults, timeout, clientRequestID, returnClientRequestID, ocpDate)
if err != nil {
err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListSupportedImages", nil, "Failure preparing request")
return
}
resp, err := client.ListSupportedImagesSender(req)
if err != nil {
result.alsir.Response = autorest.Response{Response: resp}
err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListSupportedImages", resp, "Failure sending request")
return
}
result.alsir, err = client.ListSupportedImagesResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListSupportedImages", resp, "Failure responding to request")
return
}
if result.alsir.hasNextLink() && result.alsir.IsEmpty() {
err = result.NextWithContext(ctx)
return
}
return
}
// ListSupportedImagesPreparer prepares the ListSupportedImages request.
func (client AccountClient) ListSupportedImagesPreparer(ctx context.Context, filter string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (*http.Request, error) {
urlParameters := map[string]interface{}{
"batchUrl": client.BatchURL,
}
const APIVersion = "2019-06-01.9.0"
queryParameters := map[string]interface{}{
"api-version": APIVersion,
}
if len(filter) > 0 {
queryParameters["$filter"] = autorest.Encode("query", filter)
}
if maxResults != nil {
queryParameters["maxresults"] = autorest.Encode("query", *maxResults)
} else {
queryParameters["maxresults"] = autorest.Encode("query", 1000)
}
if timeout != nil {
queryParameters["timeout"] = autorest.Encode("query", *timeout)
} else {
queryParameters["timeout"] = autorest.Encode("query", 30)
}
preparer := autorest.CreatePreparer(
autorest.AsGet(),
autorest.WithCustomBaseURL("{batchUrl}", urlParameters),
autorest.WithPath("/supportedimages"),
autorest.WithQueryParameters(queryParameters))
if clientRequestID != nil {
preparer = autorest.DecoratePreparer(preparer,
autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
}
if returnClientRequestID != nil {
preparer = autorest.DecoratePreparer(preparer,
autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
} else {
preparer = autorest.DecoratePreparer(preparer,
autorest.WithHeader("return-client-request-id", autorest.String(false)))
}
if ocpDate != nil {
preparer = autorest.DecoratePreparer(preparer,
autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
}
return preparer.Prepare((&http.Request{}).WithContext(ctx))
}
// ListSupportedImagesSender sends the ListSupportedImages request. The method will close the
// http.Response Body if it receives an error.
func (client AccountClient) ListSupportedImagesSender(req *http.Request) (*http.Response, error) {
return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
}
// ListSupportedImagesResponder handles the response to the ListSupportedImages request. The method always
// closes the http.Response Body.
func (client AccountClient) ListSupportedImagesResponder(resp *http.Response) (result AccountListSupportedImagesResult, err error) {
err = autorest.Respond(
resp,
azure.WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByUnmarshallingJSON(&result),
autorest.ByClosing())
result.Response = autorest.Response{Response: resp}
return
}
// listSupportedImagesNextResults retrieves the next set of results, if any.
func (client AccountClient) listSupportedImagesNextResults(ctx context.Context, lastResults AccountListSupportedImagesResult) (result AccountListSupportedImagesResult, err error) {
req, err := lastResults.accountListSupportedImagesResultPreparer(ctx)
if err != nil {
return result, autorest.NewErrorWithError(err, "batch.AccountClient", "listSupportedImagesNextResults", nil, "Failure preparing next results request")
}
if req == nil {
return
}
resp, err := client.ListSupportedImagesSender(req)
if err != nil {
result.Response = autorest.Response{Response: resp}
return result, autorest.NewErrorWithError(err, "batch.AccountClient", "listSupportedImagesNextResults", resp, "Failure sending next results request")
}
result, err = client.ListSupportedImagesResponder(resp)
if err != nil {
err = autorest.NewErrorWithError(err, "batch.AccountClient", "listSupportedImagesNextResults", resp, "Failure responding to next results request")
}
return
}
// ListSupportedImagesComplete enumerates all values, automatically crossing page boundaries as required.
func (client AccountClient) ListSupportedImagesComplete(ctx context.Context, filter string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result AccountListSupportedImagesResultIterator, err error) {
if tracing.IsEnabled() {
ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.ListSupportedImages")
defer func() {
sc := -1
if result.Response().Response.Response != nil {
sc = result.page.Response().Response.Response.StatusCode
}
tracing.EndSpan(ctx, sc, err)
}()
}
result.page, err = client.ListSupportedImages(ctx, filter, maxResults, timeout, clientRequestID, returnClientRequestID, ocpDate)
return
}