1package containerservice
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/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// AgentPoolsClient is the the Container Service Client.
19type AgentPoolsClient struct {
20	BaseClient
21}
22
23// NewAgentPoolsClient creates an instance of the AgentPoolsClient client.
24func NewAgentPoolsClient(subscriptionID string) AgentPoolsClient {
25	return NewAgentPoolsClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewAgentPoolsClientWithBaseURI creates an instance of the AgentPoolsClient client using a custom endpoint.  Use this
29// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewAgentPoolsClientWithBaseURI(baseURI string, subscriptionID string) AgentPoolsClient {
31	return AgentPoolsClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// CreateOrUpdate creates or updates an agent pool in the specified managed cluster.
35// Parameters:
36// resourceGroupName - the name of the resource group.
37// resourceName - the name of the managed cluster resource.
38// agentPoolName - the name of the agent pool.
39// parameters - parameters supplied to the Create or Update an agent pool operation.
40func (client AgentPoolsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, resourceName string, agentPoolName string, parameters AgentPool) (result AgentPoolsCreateOrUpdateFuture, err error) {
41	if tracing.IsEnabled() {
42		ctx = tracing.StartSpan(ctx, fqdn+"/AgentPoolsClient.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: resourceGroupName,
53			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
54		{TargetValue: resourceName,
55			Constraints: []validation.Constraint{{Target: "resourceName", Name: validation.MaxLength, Rule: 63, Chain: nil},
56				{Target: "resourceName", Name: validation.MinLength, Rule: 1, Chain: nil},
57				{Target: "resourceName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]$|^[a-zA-Z0-9][-_a-zA-Z0-9]{0,61}[a-zA-Z0-9]$`, Chain: nil}}},
58		{TargetValue: parameters,
59			Constraints: []validation.Constraint{{Target: "parameters.ManagedClusterAgentPoolProfileProperties", Name: validation.Null, Rule: false,
60				Chain: []validation.Constraint{{Target: "parameters.ManagedClusterAgentPoolProfileProperties.Count", Name: validation.Null, Rule: true,
61					Chain: []validation.Constraint{{Target: "parameters.ManagedClusterAgentPoolProfileProperties.Count", Name: validation.InclusiveMaximum, Rule: int64(100), Chain: nil},
62						{Target: "parameters.ManagedClusterAgentPoolProfileProperties.Count", Name: validation.InclusiveMinimum, Rule: int64(1), Chain: nil},
63					}},
64				}}}}}); err != nil {
65		return result, validation.NewError("containerservice.AgentPoolsClient", "CreateOrUpdate", err.Error())
66	}
67
68	req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, resourceName, agentPoolName, parameters)
69	if err != nil {
70		err = autorest.NewErrorWithError(err, "containerservice.AgentPoolsClient", "CreateOrUpdate", nil, "Failure preparing request")
71		return
72	}
73
74	result, err = client.CreateOrUpdateSender(req)
75	if err != nil {
76		err = autorest.NewErrorWithError(err, "containerservice.AgentPoolsClient", "CreateOrUpdate", nil, "Failure sending request")
77		return
78	}
79
80	return
81}
82
83// CreateOrUpdatePreparer prepares the CreateOrUpdate request.
84func (client AgentPoolsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, resourceName string, agentPoolName string, parameters AgentPool) (*http.Request, error) {
85	pathParameters := map[string]interface{}{
86		"agentPoolName":     autorest.Encode("path", agentPoolName),
87		"resourceGroupName": autorest.Encode("path", resourceGroupName),
88		"resourceName":      autorest.Encode("path", resourceName),
89		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
90	}
91
92	const APIVersion = "2019-04-01"
93	queryParameters := map[string]interface{}{
94		"api-version": APIVersion,
95	}
96
97	preparer := autorest.CreatePreparer(
98		autorest.AsContentType("application/json; charset=utf-8"),
99		autorest.AsPut(),
100		autorest.WithBaseURL(client.BaseURI),
101		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/agentPools/{agentPoolName}", pathParameters),
102		autorest.WithJSON(parameters),
103		autorest.WithQueryParameters(queryParameters))
104	return preparer.Prepare((&http.Request{}).WithContext(ctx))
105}
106
107// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the
108// http.Response Body if it receives an error.
109func (client AgentPoolsClient) CreateOrUpdateSender(req *http.Request) (future AgentPoolsCreateOrUpdateFuture, err error) {
110	var resp *http.Response
111	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
112	if err != nil {
113		return
114	}
115	var azf azure.Future
116	azf, err = azure.NewFutureFromResponse(resp)
117	future.FutureAPI = &azf
118	future.Result = future.result
119	return
120}
121
122// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always
123// closes the http.Response Body.
124func (client AgentPoolsClient) CreateOrUpdateResponder(resp *http.Response) (result AgentPool, err error) {
125	err = autorest.Respond(
126		resp,
127		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated),
128		autorest.ByUnmarshallingJSON(&result),
129		autorest.ByClosing())
130	result.Response = autorest.Response{Response: resp}
131	return
132}
133
134// Delete deletes the agent pool in the specified managed cluster.
135// Parameters:
136// resourceGroupName - the name of the resource group.
137// resourceName - the name of the managed cluster resource.
138// agentPoolName - the name of the agent pool.
139func (client AgentPoolsClient) Delete(ctx context.Context, resourceGroupName string, resourceName string, agentPoolName string) (result AgentPoolsDeleteFuture, err error) {
140	if tracing.IsEnabled() {
141		ctx = tracing.StartSpan(ctx, fqdn+"/AgentPoolsClient.Delete")
142		defer func() {
143			sc := -1
144			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
145				sc = result.FutureAPI.Response().StatusCode
146			}
147			tracing.EndSpan(ctx, sc, err)
148		}()
149	}
150	if err := validation.Validate([]validation.Validation{
151		{TargetValue: resourceGroupName,
152			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
153		{TargetValue: resourceName,
154			Constraints: []validation.Constraint{{Target: "resourceName", Name: validation.MaxLength, Rule: 63, Chain: nil},
155				{Target: "resourceName", Name: validation.MinLength, Rule: 1, Chain: nil},
156				{Target: "resourceName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]$|^[a-zA-Z0-9][-_a-zA-Z0-9]{0,61}[a-zA-Z0-9]$`, Chain: nil}}}}); err != nil {
157		return result, validation.NewError("containerservice.AgentPoolsClient", "Delete", err.Error())
158	}
159
160	req, err := client.DeletePreparer(ctx, resourceGroupName, resourceName, agentPoolName)
161	if err != nil {
162		err = autorest.NewErrorWithError(err, "containerservice.AgentPoolsClient", "Delete", nil, "Failure preparing request")
163		return
164	}
165
166	result, err = client.DeleteSender(req)
167	if err != nil {
168		err = autorest.NewErrorWithError(err, "containerservice.AgentPoolsClient", "Delete", nil, "Failure sending request")
169		return
170	}
171
172	return
173}
174
175// DeletePreparer prepares the Delete request.
176func (client AgentPoolsClient) DeletePreparer(ctx context.Context, resourceGroupName string, resourceName string, agentPoolName string) (*http.Request, error) {
177	pathParameters := map[string]interface{}{
178		"agentPoolName":     autorest.Encode("path", agentPoolName),
179		"resourceGroupName": autorest.Encode("path", resourceGroupName),
180		"resourceName":      autorest.Encode("path", resourceName),
181		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
182	}
183
184	const APIVersion = "2019-04-01"
185	queryParameters := map[string]interface{}{
186		"api-version": APIVersion,
187	}
188
189	preparer := autorest.CreatePreparer(
190		autorest.AsDelete(),
191		autorest.WithBaseURL(client.BaseURI),
192		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/agentPools/{agentPoolName}", pathParameters),
193		autorest.WithQueryParameters(queryParameters))
194	return preparer.Prepare((&http.Request{}).WithContext(ctx))
195}
196
197// DeleteSender sends the Delete request. The method will close the
198// http.Response Body if it receives an error.
199func (client AgentPoolsClient) DeleteSender(req *http.Request) (future AgentPoolsDeleteFuture, err error) {
200	var resp *http.Response
201	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
202	if err != nil {
203		return
204	}
205	var azf azure.Future
206	azf, err = azure.NewFutureFromResponse(resp)
207	future.FutureAPI = &azf
208	future.Result = future.result
209	return
210}
211
212// DeleteResponder handles the response to the Delete request. The method always
213// closes the http.Response Body.
214func (client AgentPoolsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
215	err = autorest.Respond(
216		resp,
217		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent),
218		autorest.ByClosing())
219	result.Response = resp
220	return
221}
222
223// Get gets the details of the agent pool by managed cluster and resource group.
224// Parameters:
225// resourceGroupName - the name of the resource group.
226// resourceName - the name of the managed cluster resource.
227// agentPoolName - the name of the agent pool.
228func (client AgentPoolsClient) Get(ctx context.Context, resourceGroupName string, resourceName string, agentPoolName string) (result AgentPool, err error) {
229	if tracing.IsEnabled() {
230		ctx = tracing.StartSpan(ctx, fqdn+"/AgentPoolsClient.Get")
231		defer func() {
232			sc := -1
233			if result.Response.Response != nil {
234				sc = result.Response.Response.StatusCode
235			}
236			tracing.EndSpan(ctx, sc, err)
237		}()
238	}
239	if err := validation.Validate([]validation.Validation{
240		{TargetValue: resourceGroupName,
241			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
242		{TargetValue: resourceName,
243			Constraints: []validation.Constraint{{Target: "resourceName", Name: validation.MaxLength, Rule: 63, Chain: nil},
244				{Target: "resourceName", Name: validation.MinLength, Rule: 1, Chain: nil},
245				{Target: "resourceName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]$|^[a-zA-Z0-9][-_a-zA-Z0-9]{0,61}[a-zA-Z0-9]$`, Chain: nil}}}}); err != nil {
246		return result, validation.NewError("containerservice.AgentPoolsClient", "Get", err.Error())
247	}
248
249	req, err := client.GetPreparer(ctx, resourceGroupName, resourceName, agentPoolName)
250	if err != nil {
251		err = autorest.NewErrorWithError(err, "containerservice.AgentPoolsClient", "Get", nil, "Failure preparing request")
252		return
253	}
254
255	resp, err := client.GetSender(req)
256	if err != nil {
257		result.Response = autorest.Response{Response: resp}
258		err = autorest.NewErrorWithError(err, "containerservice.AgentPoolsClient", "Get", resp, "Failure sending request")
259		return
260	}
261
262	result, err = client.GetResponder(resp)
263	if err != nil {
264		err = autorest.NewErrorWithError(err, "containerservice.AgentPoolsClient", "Get", resp, "Failure responding to request")
265		return
266	}
267
268	return
269}
270
271// GetPreparer prepares the Get request.
272func (client AgentPoolsClient) GetPreparer(ctx context.Context, resourceGroupName string, resourceName string, agentPoolName string) (*http.Request, error) {
273	pathParameters := map[string]interface{}{
274		"agentPoolName":     autorest.Encode("path", agentPoolName),
275		"resourceGroupName": autorest.Encode("path", resourceGroupName),
276		"resourceName":      autorest.Encode("path", resourceName),
277		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
278	}
279
280	const APIVersion = "2019-04-01"
281	queryParameters := map[string]interface{}{
282		"api-version": APIVersion,
283	}
284
285	preparer := autorest.CreatePreparer(
286		autorest.AsGet(),
287		autorest.WithBaseURL(client.BaseURI),
288		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/agentPools/{agentPoolName}", pathParameters),
289		autorest.WithQueryParameters(queryParameters))
290	return preparer.Prepare((&http.Request{}).WithContext(ctx))
291}
292
293// GetSender sends the Get request. The method will close the
294// http.Response Body if it receives an error.
295func (client AgentPoolsClient) GetSender(req *http.Request) (*http.Response, error) {
296	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
297}
298
299// GetResponder handles the response to the Get request. The method always
300// closes the http.Response Body.
301func (client AgentPoolsClient) GetResponder(resp *http.Response) (result AgentPool, err error) {
302	err = autorest.Respond(
303		resp,
304		azure.WithErrorUnlessStatusCode(http.StatusOK),
305		autorest.ByUnmarshallingJSON(&result),
306		autorest.ByClosing())
307	result.Response = autorest.Response{Response: resp}
308	return
309}
310
311// List gets a list of agent pools in the specified managed cluster. The operation returns properties of each agent
312// pool.
313// Parameters:
314// resourceGroupName - the name of the resource group.
315// resourceName - the name of the managed cluster resource.
316func (client AgentPoolsClient) List(ctx context.Context, resourceGroupName string, resourceName string) (result AgentPoolListResultPage, err error) {
317	if tracing.IsEnabled() {
318		ctx = tracing.StartSpan(ctx, fqdn+"/AgentPoolsClient.List")
319		defer func() {
320			sc := -1
321			if result.aplr.Response.Response != nil {
322				sc = result.aplr.Response.Response.StatusCode
323			}
324			tracing.EndSpan(ctx, sc, err)
325		}()
326	}
327	if err := validation.Validate([]validation.Validation{
328		{TargetValue: resourceGroupName,
329			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.MinLength, Rule: 1, Chain: nil}}},
330		{TargetValue: resourceName,
331			Constraints: []validation.Constraint{{Target: "resourceName", Name: validation.MaxLength, Rule: 63, Chain: nil},
332				{Target: "resourceName", Name: validation.MinLength, Rule: 1, Chain: nil},
333				{Target: "resourceName", Name: validation.Pattern, Rule: `^[a-zA-Z0-9]$|^[a-zA-Z0-9][-_a-zA-Z0-9]{0,61}[a-zA-Z0-9]$`, Chain: nil}}}}); err != nil {
334		return result, validation.NewError("containerservice.AgentPoolsClient", "List", err.Error())
335	}
336
337	result.fn = client.listNextResults
338	req, err := client.ListPreparer(ctx, resourceGroupName, resourceName)
339	if err != nil {
340		err = autorest.NewErrorWithError(err, "containerservice.AgentPoolsClient", "List", nil, "Failure preparing request")
341		return
342	}
343
344	resp, err := client.ListSender(req)
345	if err != nil {
346		result.aplr.Response = autorest.Response{Response: resp}
347		err = autorest.NewErrorWithError(err, "containerservice.AgentPoolsClient", "List", resp, "Failure sending request")
348		return
349	}
350
351	result.aplr, err = client.ListResponder(resp)
352	if err != nil {
353		err = autorest.NewErrorWithError(err, "containerservice.AgentPoolsClient", "List", resp, "Failure responding to request")
354		return
355	}
356	if result.aplr.hasNextLink() && result.aplr.IsEmpty() {
357		err = result.NextWithContext(ctx)
358		return
359	}
360
361	return
362}
363
364// ListPreparer prepares the List request.
365func (client AgentPoolsClient) ListPreparer(ctx context.Context, resourceGroupName string, resourceName string) (*http.Request, error) {
366	pathParameters := map[string]interface{}{
367		"resourceGroupName": autorest.Encode("path", resourceGroupName),
368		"resourceName":      autorest.Encode("path", resourceName),
369		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
370	}
371
372	const APIVersion = "2019-04-01"
373	queryParameters := map[string]interface{}{
374		"api-version": APIVersion,
375	}
376
377	preparer := autorest.CreatePreparer(
378		autorest.AsGet(),
379		autorest.WithBaseURL(client.BaseURI),
380		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/managedClusters/{resourceName}/agentPools", pathParameters),
381		autorest.WithQueryParameters(queryParameters))
382	return preparer.Prepare((&http.Request{}).WithContext(ctx))
383}
384
385// ListSender sends the List request. The method will close the
386// http.Response Body if it receives an error.
387func (client AgentPoolsClient) ListSender(req *http.Request) (*http.Response, error) {
388	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
389}
390
391// ListResponder handles the response to the List request. The method always
392// closes the http.Response Body.
393func (client AgentPoolsClient) ListResponder(resp *http.Response) (result AgentPoolListResult, err error) {
394	err = autorest.Respond(
395		resp,
396		azure.WithErrorUnlessStatusCode(http.StatusOK),
397		autorest.ByUnmarshallingJSON(&result),
398		autorest.ByClosing())
399	result.Response = autorest.Response{Response: resp}
400	return
401}
402
403// listNextResults retrieves the next set of results, if any.
404func (client AgentPoolsClient) listNextResults(ctx context.Context, lastResults AgentPoolListResult) (result AgentPoolListResult, err error) {
405	req, err := lastResults.agentPoolListResultPreparer(ctx)
406	if err != nil {
407		return result, autorest.NewErrorWithError(err, "containerservice.AgentPoolsClient", "listNextResults", nil, "Failure preparing next results request")
408	}
409	if req == nil {
410		return
411	}
412	resp, err := client.ListSender(req)
413	if err != nil {
414		result.Response = autorest.Response{Response: resp}
415		return result, autorest.NewErrorWithError(err, "containerservice.AgentPoolsClient", "listNextResults", resp, "Failure sending next results request")
416	}
417	result, err = client.ListResponder(resp)
418	if err != nil {
419		err = autorest.NewErrorWithError(err, "containerservice.AgentPoolsClient", "listNextResults", resp, "Failure responding to next results request")
420	}
421	return
422}
423
424// ListComplete enumerates all values, automatically crossing page boundaries as required.
425func (client AgentPoolsClient) ListComplete(ctx context.Context, resourceGroupName string, resourceName string) (result AgentPoolListResultIterator, err error) {
426	if tracing.IsEnabled() {
427		ctx = tracing.StartSpan(ctx, fqdn+"/AgentPoolsClient.List")
428		defer func() {
429			sc := -1
430			if result.Response().Response.Response != nil {
431				sc = result.page.Response().Response.Response.StatusCode
432			}
433			tracing.EndSpan(ctx, sc, err)
434		}()
435	}
436	result.page, err = client.List(ctx, resourceGroupName, resourceName)
437	return
438}
439