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