1package batch
2
3// Copyright (c) Microsoft Corporation. All rights reserved.
4// Licensed under the MIT License. See License.txt in the project root for license information.
5//
6// Code generated by Microsoft (R) AutoRest Code Generator.
7// Changes may cause incorrect behavior and will be lost if the code is regenerated.
8
9import (
10	"context"
11	"github.com/Azure/go-autorest/autorest"
12	"github.com/Azure/go-autorest/autorest/azure"
13	"github.com/Azure/go-autorest/autorest/date"
14	"github.com/Azure/go-autorest/autorest/validation"
15	"github.com/Azure/go-autorest/tracing"
16	"github.com/gofrs/uuid"
17	"net/http"
18)
19
20// AccountClient is the a client for issuing REST requests to the Azure Batch service.
21type AccountClient struct {
22	BaseClient
23}
24
25// NewAccountClient creates an instance of the AccountClient client.
26func NewAccountClient() AccountClient {
27	return NewAccountClientWithBaseURI(DefaultBaseURI)
28}
29
30// NewAccountClientWithBaseURI creates an instance of the AccountClient client using a custom endpoint.  Use this when
31// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
32func NewAccountClientWithBaseURI(baseURI string) AccountClient {
33	return AccountClient{NewWithBaseURI(baseURI)}
34}
35
36// ListNodeAgentSkus sends the list node agent skus request.
37// Parameters:
38// filter - an OData $filter clause.
39// maxResults - the maximum number of items to return in the response. A maximum of 1000 results will be
40// returned.
41// timeout - the maximum time that the server can spend processing the request, in seconds. The default is 30
42// seconds.
43// clientRequestID - the caller-generated request identity, in the form of a GUID with no decoration such as
44// curly braces, e.g. 9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
45// returnClientRequestID - whether the server should return the client-request-id in the response.
46// ocpDate - the time the request was issued. Client libraries typically set this to the current system clock
47// time; set it explicitly if you are calling the REST API directly.
48func (client AccountClient) ListNodeAgentSkus(ctx context.Context, filter string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result AccountListNodeAgentSkusResultPage, err error) {
49	if tracing.IsEnabled() {
50		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.ListNodeAgentSkus")
51		defer func() {
52			sc := -1
53			if result.alnasr.Response.Response != nil {
54				sc = result.alnasr.Response.Response.StatusCode
55			}
56			tracing.EndSpan(ctx, sc, err)
57		}()
58	}
59	if err := validation.Validate([]validation.Validation{
60		{TargetValue: maxResults,
61			Constraints: []validation.Constraint{{Target: "maxResults", Name: validation.Null, Rule: false,
62				Chain: []validation.Constraint{{Target: "maxResults", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil},
63					{Target: "maxResults", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
64				}}}}}); err != nil {
65		return result, validation.NewError("batch.AccountClient", "ListNodeAgentSkus", err.Error())
66	}
67
68	result.fn = client.listNodeAgentSkusNextResults
69	req, err := client.ListNodeAgentSkusPreparer(ctx, filter, maxResults, timeout, clientRequestID, returnClientRequestID, ocpDate)
70	if err != nil {
71		err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListNodeAgentSkus", nil, "Failure preparing request")
72		return
73	}
74
75	resp, err := client.ListNodeAgentSkusSender(req)
76	if err != nil {
77		result.alnasr.Response = autorest.Response{Response: resp}
78		err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListNodeAgentSkus", resp, "Failure sending request")
79		return
80	}
81
82	result.alnasr, err = client.ListNodeAgentSkusResponder(resp)
83	if err != nil {
84		err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListNodeAgentSkus", resp, "Failure responding to request")
85		return
86	}
87	if result.alnasr.hasNextLink() && result.alnasr.IsEmpty() {
88		err = result.NextWithContext(ctx)
89		return
90	}
91
92	return
93}
94
95// ListNodeAgentSkusPreparer prepares the ListNodeAgentSkus request.
96func (client AccountClient) ListNodeAgentSkusPreparer(ctx context.Context, filter string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (*http.Request, error) {
97	const APIVersion = "2017-05-01.5.0"
98	queryParameters := map[string]interface{}{
99		"api-version": APIVersion,
100	}
101	if len(filter) > 0 {
102		queryParameters["$filter"] = autorest.Encode("query", filter)
103	}
104	if maxResults != nil {
105		queryParameters["maxresults"] = autorest.Encode("query", *maxResults)
106	} else {
107		queryParameters["maxresults"] = autorest.Encode("query", 1000)
108	}
109	if timeout != nil {
110		queryParameters["timeout"] = autorest.Encode("query", *timeout)
111	} else {
112		queryParameters["timeout"] = autorest.Encode("query", 30)
113	}
114
115	preparer := autorest.CreatePreparer(
116		autorest.AsGet(),
117		autorest.WithBaseURL(client.BaseURI),
118		autorest.WithPath("/nodeagentskus"),
119		autorest.WithQueryParameters(queryParameters))
120	if clientRequestID != nil {
121		preparer = autorest.DecoratePreparer(preparer,
122			autorest.WithHeader("client-request-id", autorest.String(clientRequestID)))
123	}
124	if returnClientRequestID != nil {
125		preparer = autorest.DecoratePreparer(preparer,
126			autorest.WithHeader("return-client-request-id", autorest.String(returnClientRequestID)))
127	} else {
128		preparer = autorest.DecoratePreparer(preparer,
129			autorest.WithHeader("return-client-request-id", autorest.String(false)))
130	}
131	if ocpDate != nil {
132		preparer = autorest.DecoratePreparer(preparer,
133			autorest.WithHeader("ocp-date", autorest.String(ocpDate)))
134	}
135	return preparer.Prepare((&http.Request{}).WithContext(ctx))
136}
137
138// ListNodeAgentSkusSender sends the ListNodeAgentSkus request. The method will close the
139// http.Response Body if it receives an error.
140func (client AccountClient) ListNodeAgentSkusSender(req *http.Request) (*http.Response, error) {
141	return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...))
142}
143
144// ListNodeAgentSkusResponder handles the response to the ListNodeAgentSkus request. The method always
145// closes the http.Response Body.
146func (client AccountClient) ListNodeAgentSkusResponder(resp *http.Response) (result AccountListNodeAgentSkusResult, err error) {
147	err = autorest.Respond(
148		resp,
149		azure.WithErrorUnlessStatusCode(http.StatusOK),
150		autorest.ByUnmarshallingJSON(&result),
151		autorest.ByClosing())
152	result.Response = autorest.Response{Response: resp}
153	return
154}
155
156// listNodeAgentSkusNextResults retrieves the next set of results, if any.
157func (client AccountClient) listNodeAgentSkusNextResults(ctx context.Context, lastResults AccountListNodeAgentSkusResult) (result AccountListNodeAgentSkusResult, err error) {
158	req, err := lastResults.accountListNodeAgentSkusResultPreparer(ctx)
159	if err != nil {
160		return result, autorest.NewErrorWithError(err, "batch.AccountClient", "listNodeAgentSkusNextResults", nil, "Failure preparing next results request")
161	}
162	if req == nil {
163		return
164	}
165	resp, err := client.ListNodeAgentSkusSender(req)
166	if err != nil {
167		result.Response = autorest.Response{Response: resp}
168		return result, autorest.NewErrorWithError(err, "batch.AccountClient", "listNodeAgentSkusNextResults", resp, "Failure sending next results request")
169	}
170	result, err = client.ListNodeAgentSkusResponder(resp)
171	if err != nil {
172		err = autorest.NewErrorWithError(err, "batch.AccountClient", "listNodeAgentSkusNextResults", resp, "Failure responding to next results request")
173	}
174	return
175}
176
177// ListNodeAgentSkusComplete enumerates all values, automatically crossing page boundaries as required.
178func (client AccountClient) ListNodeAgentSkusComplete(ctx context.Context, filter string, maxResults *int32, timeout *int32, clientRequestID *uuid.UUID, returnClientRequestID *bool, ocpDate *date.TimeRFC1123) (result AccountListNodeAgentSkusResultIterator, err error) {
179	if tracing.IsEnabled() {
180		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.ListNodeAgentSkus")
181		defer func() {
182			sc := -1
183			if result.Response().Response.Response != nil {
184				sc = result.page.Response().Response.Response.StatusCode
185			}
186			tracing.EndSpan(ctx, sc, err)
187		}()
188	}
189	result.page, err = client.ListNodeAgentSkus(ctx, filter, maxResults, timeout, clientRequestID, returnClientRequestID, ocpDate)
190	return
191}
192