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/validation"
14	"github.com/Azure/go-autorest/tracing"
15	"net/http"
16)
17
18// AccountClient is the client for the Account methods of the Batch service.
19type AccountClient struct {
20	BaseClient
21}
22
23// NewAccountClient creates an instance of the AccountClient client.
24func NewAccountClient(subscriptionID string) AccountClient {
25	return NewAccountClientWithBaseURI(DefaultBaseURI, subscriptionID)
26}
27
28// NewAccountClientWithBaseURI creates an instance of the AccountClient client using a custom endpoint.  Use this when
29// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
30func NewAccountClientWithBaseURI(baseURI string, subscriptionID string) AccountClient {
31	return AccountClient{NewWithBaseURI(baseURI, subscriptionID)}
32}
33
34// Create creates a new Batch account with the specified parameters. Existing accounts cannot be updated with this API
35// and should instead be updated with the Update Batch Account API.
36// Parameters:
37// resourceGroupName - the name of the resource group that contains the new Batch account.
38// accountName - a name for the Batch account which must be unique within the region. Batch account names must
39// be between 3 and 24 characters in length and must use only numbers and lowercase letters. This name is used
40// as part of the DNS name that is used to access the Batch service in the region in which the account is
41// created. For example: http://accountname.region.batch.azure.com/.
42// parameters - additional parameters for account creation.
43func (client AccountClient) Create(ctx context.Context, resourceGroupName string, accountName string, parameters AccountCreateParameters) (result AccountCreateFuture, err error) {
44	if tracing.IsEnabled() {
45		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.Create")
46		defer func() {
47			sc := -1
48			if result.FutureAPI != nil && result.FutureAPI.Response() != nil {
49				sc = result.FutureAPI.Response().StatusCode
50			}
51			tracing.EndSpan(ctx, sc, err)
52		}()
53	}
54	if err := validation.Validate([]validation.Validation{
55		{TargetValue: resourceGroupName,
56			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}},
57		{TargetValue: accountName,
58			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
59				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
60				{Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}},
61		{TargetValue: parameters,
62			Constraints: []validation.Constraint{{Target: "parameters.Location", Name: validation.Null, Rule: true, Chain: nil},
63				{Target: "parameters.AccountBaseProperties", Name: validation.Null, Rule: false,
64					Chain: []validation.Constraint{{Target: "parameters.AccountBaseProperties.AutoStorage", Name: validation.Null, Rule: false,
65						Chain: []validation.Constraint{{Target: "parameters.AccountBaseProperties.AutoStorage.StorageAccountID", Name: validation.Null, Rule: true, Chain: nil}}},
66					}}}}}); err != nil {
67		return result, validation.NewError("batch.AccountClient", "Create", err.Error())
68	}
69
70	req, err := client.CreatePreparer(ctx, resourceGroupName, accountName, parameters)
71	if err != nil {
72		err = autorest.NewErrorWithError(err, "batch.AccountClient", "Create", nil, "Failure preparing request")
73		return
74	}
75
76	result, err = client.CreateSender(req)
77	if err != nil {
78		err = autorest.NewErrorWithError(err, "batch.AccountClient", "Create", nil, "Failure sending request")
79		return
80	}
81
82	return
83}
84
85// CreatePreparer prepares the Create request.
86func (client AccountClient) CreatePreparer(ctx context.Context, resourceGroupName string, accountName string, parameters AccountCreateParameters) (*http.Request, error) {
87	pathParameters := map[string]interface{}{
88		"accountName":       autorest.Encode("path", accountName),
89		"resourceGroupName": autorest.Encode("path", resourceGroupName),
90		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
91	}
92
93	const APIVersion = "2015-12-01"
94	queryParameters := map[string]interface{}{
95		"api-version": APIVersion,
96	}
97
98	preparer := autorest.CreatePreparer(
99		autorest.AsContentType("application/json; charset=utf-8"),
100		autorest.AsPut(),
101		autorest.WithBaseURL(client.BaseURI),
102		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}", pathParameters),
103		autorest.WithJSON(parameters),
104		autorest.WithQueryParameters(queryParameters))
105	return preparer.Prepare((&http.Request{}).WithContext(ctx))
106}
107
108// CreateSender sends the Create request. The method will close the
109// http.Response Body if it receives an error.
110func (client AccountClient) CreateSender(req *http.Request) (future AccountCreateFuture, err error) {
111	var resp *http.Response
112	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
113	if err != nil {
114		return
115	}
116	var azf azure.Future
117	azf, err = azure.NewFutureFromResponse(resp)
118	future.FutureAPI = &azf
119	future.Result = future.result
120	return
121}
122
123// CreateResponder handles the response to the Create request. The method always
124// closes the http.Response Body.
125func (client AccountClient) CreateResponder(resp *http.Response) (result Account, err error) {
126	err = autorest.Respond(
127		resp,
128		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
129		autorest.ByUnmarshallingJSON(&result),
130		autorest.ByClosing())
131	result.Response = autorest.Response{Response: resp}
132	return
133}
134
135// Delete deletes the specified Batch account.
136// Parameters:
137// resourceGroupName - the name of the resource group that contains the Batch account to be deleted.
138// accountName - the name of the account to be deleted.
139func (client AccountClient) Delete(ctx context.Context, resourceGroupName string, accountName string) (result AccountDeleteFuture, err error) {
140	if tracing.IsEnabled() {
141		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.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.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}},
153		{TargetValue: accountName,
154			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
155				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
156				{Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
157		return result, validation.NewError("batch.AccountClient", "Delete", err.Error())
158	}
159
160	req, err := client.DeletePreparer(ctx, resourceGroupName, accountName)
161	if err != nil {
162		err = autorest.NewErrorWithError(err, "batch.AccountClient", "Delete", nil, "Failure preparing request")
163		return
164	}
165
166	result, err = client.DeleteSender(req)
167	if err != nil {
168		err = autorest.NewErrorWithError(err, "batch.AccountClient", "Delete", nil, "Failure sending request")
169		return
170	}
171
172	return
173}
174
175// DeletePreparer prepares the Delete request.
176func (client AccountClient) DeletePreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
177	pathParameters := map[string]interface{}{
178		"accountName":       autorest.Encode("path", accountName),
179		"resourceGroupName": autorest.Encode("path", resourceGroupName),
180		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
181	}
182
183	const APIVersion = "2015-12-01"
184	queryParameters := map[string]interface{}{
185		"api-version": APIVersion,
186	}
187
188	preparer := autorest.CreatePreparer(
189		autorest.AsDelete(),
190		autorest.WithBaseURL(client.BaseURI),
191		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}", pathParameters),
192		autorest.WithQueryParameters(queryParameters))
193	return preparer.Prepare((&http.Request{}).WithContext(ctx))
194}
195
196// DeleteSender sends the Delete request. The method will close the
197// http.Response Body if it receives an error.
198func (client AccountClient) DeleteSender(req *http.Request) (future AccountDeleteFuture, err error) {
199	var resp *http.Response
200	resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client))
201	if err != nil {
202		return
203	}
204	var azf azure.Future
205	azf, err = azure.NewFutureFromResponse(resp)
206	future.FutureAPI = &azf
207	future.Result = future.result
208	return
209}
210
211// DeleteResponder handles the response to the Delete request. The method always
212// closes the http.Response Body.
213func (client AccountClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) {
214	err = autorest.Respond(
215		resp,
216		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted),
217		autorest.ByClosing())
218	result.Response = resp
219	return
220}
221
222// Get gets information about the specified Batch account.
223// Parameters:
224// resourceGroupName - the name of the resource group that contains the Batch account.
225// accountName - the name of the account.
226func (client AccountClient) Get(ctx context.Context, resourceGroupName string, accountName string) (result Account, err error) {
227	if tracing.IsEnabled() {
228		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.Get")
229		defer func() {
230			sc := -1
231			if result.Response.Response != nil {
232				sc = result.Response.Response.StatusCode
233			}
234			tracing.EndSpan(ctx, sc, err)
235		}()
236	}
237	if err := validation.Validate([]validation.Validation{
238		{TargetValue: resourceGroupName,
239			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}},
240		{TargetValue: accountName,
241			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
242				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
243				{Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
244		return result, validation.NewError("batch.AccountClient", "Get", err.Error())
245	}
246
247	req, err := client.GetPreparer(ctx, resourceGroupName, accountName)
248	if err != nil {
249		err = autorest.NewErrorWithError(err, "batch.AccountClient", "Get", nil, "Failure preparing request")
250		return
251	}
252
253	resp, err := client.GetSender(req)
254	if err != nil {
255		result.Response = autorest.Response{Response: resp}
256		err = autorest.NewErrorWithError(err, "batch.AccountClient", "Get", resp, "Failure sending request")
257		return
258	}
259
260	result, err = client.GetResponder(resp)
261	if err != nil {
262		err = autorest.NewErrorWithError(err, "batch.AccountClient", "Get", resp, "Failure responding to request")
263		return
264	}
265
266	return
267}
268
269// GetPreparer prepares the Get request.
270func (client AccountClient) GetPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
271	pathParameters := map[string]interface{}{
272		"accountName":       autorest.Encode("path", accountName),
273		"resourceGroupName": autorest.Encode("path", resourceGroupName),
274		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
275	}
276
277	const APIVersion = "2015-12-01"
278	queryParameters := map[string]interface{}{
279		"api-version": APIVersion,
280	}
281
282	preparer := autorest.CreatePreparer(
283		autorest.AsGet(),
284		autorest.WithBaseURL(client.BaseURI),
285		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}", pathParameters),
286		autorest.WithQueryParameters(queryParameters))
287	return preparer.Prepare((&http.Request{}).WithContext(ctx))
288}
289
290// GetSender sends the Get request. The method will close the
291// http.Response Body if it receives an error.
292func (client AccountClient) GetSender(req *http.Request) (*http.Response, error) {
293	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
294}
295
296// GetResponder handles the response to the Get request. The method always
297// closes the http.Response Body.
298func (client AccountClient) GetResponder(resp *http.Response) (result Account, err error) {
299	err = autorest.Respond(
300		resp,
301		azure.WithErrorUnlessStatusCode(http.StatusOK),
302		autorest.ByUnmarshallingJSON(&result),
303		autorest.ByClosing())
304	result.Response = autorest.Response{Response: resp}
305	return
306}
307
308// GetKeys gets the account keys for the specified Batch account.
309// Parameters:
310// resourceGroupName - the name of the resource group that contains the Batch account.
311// accountName - the name of the account.
312func (client AccountClient) GetKeys(ctx context.Context, resourceGroupName string, accountName string) (result AccountKeys, err error) {
313	if tracing.IsEnabled() {
314		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.GetKeys")
315		defer func() {
316			sc := -1
317			if result.Response.Response != nil {
318				sc = result.Response.Response.StatusCode
319			}
320			tracing.EndSpan(ctx, sc, err)
321		}()
322	}
323	if err := validation.Validate([]validation.Validation{
324		{TargetValue: resourceGroupName,
325			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}},
326		{TargetValue: accountName,
327			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
328				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
329				{Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
330		return result, validation.NewError("batch.AccountClient", "GetKeys", err.Error())
331	}
332
333	req, err := client.GetKeysPreparer(ctx, resourceGroupName, accountName)
334	if err != nil {
335		err = autorest.NewErrorWithError(err, "batch.AccountClient", "GetKeys", nil, "Failure preparing request")
336		return
337	}
338
339	resp, err := client.GetKeysSender(req)
340	if err != nil {
341		result.Response = autorest.Response{Response: resp}
342		err = autorest.NewErrorWithError(err, "batch.AccountClient", "GetKeys", resp, "Failure sending request")
343		return
344	}
345
346	result, err = client.GetKeysResponder(resp)
347	if err != nil {
348		err = autorest.NewErrorWithError(err, "batch.AccountClient", "GetKeys", resp, "Failure responding to request")
349		return
350	}
351
352	return
353}
354
355// GetKeysPreparer prepares the GetKeys request.
356func (client AccountClient) GetKeysPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
357	pathParameters := map[string]interface{}{
358		"accountName":       autorest.Encode("path", accountName),
359		"resourceGroupName": autorest.Encode("path", resourceGroupName),
360		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
361	}
362
363	const APIVersion = "2015-12-01"
364	queryParameters := map[string]interface{}{
365		"api-version": APIVersion,
366	}
367
368	preparer := autorest.CreatePreparer(
369		autorest.AsPost(),
370		autorest.WithBaseURL(client.BaseURI),
371		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/listKeys", pathParameters),
372		autorest.WithQueryParameters(queryParameters))
373	return preparer.Prepare((&http.Request{}).WithContext(ctx))
374}
375
376// GetKeysSender sends the GetKeys request. The method will close the
377// http.Response Body if it receives an error.
378func (client AccountClient) GetKeysSender(req *http.Request) (*http.Response, error) {
379	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
380}
381
382// GetKeysResponder handles the response to the GetKeys request. The method always
383// closes the http.Response Body.
384func (client AccountClient) GetKeysResponder(resp *http.Response) (result AccountKeys, err error) {
385	err = autorest.Respond(
386		resp,
387		azure.WithErrorUnlessStatusCode(http.StatusOK),
388		autorest.ByUnmarshallingJSON(&result),
389		autorest.ByClosing())
390	result.Response = autorest.Response{Response: resp}
391	return
392}
393
394// List gets information about the Batch accounts associated with the subscription.
395func (client AccountClient) List(ctx context.Context) (result AccountListResultPage, err error) {
396	if tracing.IsEnabled() {
397		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.List")
398		defer func() {
399			sc := -1
400			if result.alr.Response.Response != nil {
401				sc = result.alr.Response.Response.StatusCode
402			}
403			tracing.EndSpan(ctx, sc, err)
404		}()
405	}
406	result.fn = client.listNextResults
407	req, err := client.ListPreparer(ctx)
408	if err != nil {
409		err = autorest.NewErrorWithError(err, "batch.AccountClient", "List", nil, "Failure preparing request")
410		return
411	}
412
413	resp, err := client.ListSender(req)
414	if err != nil {
415		result.alr.Response = autorest.Response{Response: resp}
416		err = autorest.NewErrorWithError(err, "batch.AccountClient", "List", resp, "Failure sending request")
417		return
418	}
419
420	result.alr, err = client.ListResponder(resp)
421	if err != nil {
422		err = autorest.NewErrorWithError(err, "batch.AccountClient", "List", resp, "Failure responding to request")
423		return
424	}
425	if result.alr.hasNextLink() && result.alr.IsEmpty() {
426		err = result.NextWithContext(ctx)
427		return
428	}
429
430	return
431}
432
433// ListPreparer prepares the List request.
434func (client AccountClient) ListPreparer(ctx context.Context) (*http.Request, error) {
435	pathParameters := map[string]interface{}{
436		"subscriptionId": autorest.Encode("path", client.SubscriptionID),
437	}
438
439	const APIVersion = "2015-12-01"
440	queryParameters := map[string]interface{}{
441		"api-version": APIVersion,
442	}
443
444	preparer := autorest.CreatePreparer(
445		autorest.AsGet(),
446		autorest.WithBaseURL(client.BaseURI),
447		autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Batch/batchAccounts", pathParameters),
448		autorest.WithQueryParameters(queryParameters))
449	return preparer.Prepare((&http.Request{}).WithContext(ctx))
450}
451
452// ListSender sends the List request. The method will close the
453// http.Response Body if it receives an error.
454func (client AccountClient) ListSender(req *http.Request) (*http.Response, error) {
455	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
456}
457
458// ListResponder handles the response to the List request. The method always
459// closes the http.Response Body.
460func (client AccountClient) ListResponder(resp *http.Response) (result AccountListResult, err error) {
461	err = autorest.Respond(
462		resp,
463		azure.WithErrorUnlessStatusCode(http.StatusOK),
464		autorest.ByUnmarshallingJSON(&result),
465		autorest.ByClosing())
466	result.Response = autorest.Response{Response: resp}
467	return
468}
469
470// listNextResults retrieves the next set of results, if any.
471func (client AccountClient) listNextResults(ctx context.Context, lastResults AccountListResult) (result AccountListResult, err error) {
472	req, err := lastResults.accountListResultPreparer(ctx)
473	if err != nil {
474		return result, autorest.NewErrorWithError(err, "batch.AccountClient", "listNextResults", nil, "Failure preparing next results request")
475	}
476	if req == nil {
477		return
478	}
479	resp, err := client.ListSender(req)
480	if err != nil {
481		result.Response = autorest.Response{Response: resp}
482		return result, autorest.NewErrorWithError(err, "batch.AccountClient", "listNextResults", resp, "Failure sending next results request")
483	}
484	result, err = client.ListResponder(resp)
485	if err != nil {
486		err = autorest.NewErrorWithError(err, "batch.AccountClient", "listNextResults", resp, "Failure responding to next results request")
487	}
488	return
489}
490
491// ListComplete enumerates all values, automatically crossing page boundaries as required.
492func (client AccountClient) ListComplete(ctx context.Context) (result AccountListResultIterator, err error) {
493	if tracing.IsEnabled() {
494		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.List")
495		defer func() {
496			sc := -1
497			if result.Response().Response.Response != nil {
498				sc = result.page.Response().Response.Response.StatusCode
499			}
500			tracing.EndSpan(ctx, sc, err)
501		}()
502	}
503	result.page, err = client.List(ctx)
504	return
505}
506
507// ListByResourceGroup gets information about the Batch accounts associated within the specified resource group.
508// Parameters:
509// resourceGroupName - the name of the resource group whose Batch accounts to list.
510func (client AccountClient) ListByResourceGroup(ctx context.Context, resourceGroupName string) (result AccountListResultPage, err error) {
511	if tracing.IsEnabled() {
512		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.ListByResourceGroup")
513		defer func() {
514			sc := -1
515			if result.alr.Response.Response != nil {
516				sc = result.alr.Response.Response.StatusCode
517			}
518			tracing.EndSpan(ctx, sc, err)
519		}()
520	}
521	if err := validation.Validate([]validation.Validation{
522		{TargetValue: resourceGroupName,
523			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
524		return result, validation.NewError("batch.AccountClient", "ListByResourceGroup", err.Error())
525	}
526
527	result.fn = client.listByResourceGroupNextResults
528	req, err := client.ListByResourceGroupPreparer(ctx, resourceGroupName)
529	if err != nil {
530		err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListByResourceGroup", nil, "Failure preparing request")
531		return
532	}
533
534	resp, err := client.ListByResourceGroupSender(req)
535	if err != nil {
536		result.alr.Response = autorest.Response{Response: resp}
537		err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListByResourceGroup", resp, "Failure sending request")
538		return
539	}
540
541	result.alr, err = client.ListByResourceGroupResponder(resp)
542	if err != nil {
543		err = autorest.NewErrorWithError(err, "batch.AccountClient", "ListByResourceGroup", resp, "Failure responding to request")
544		return
545	}
546	if result.alr.hasNextLink() && result.alr.IsEmpty() {
547		err = result.NextWithContext(ctx)
548		return
549	}
550
551	return
552}
553
554// ListByResourceGroupPreparer prepares the ListByResourceGroup request.
555func (client AccountClient) ListByResourceGroupPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) {
556	pathParameters := map[string]interface{}{
557		"resourceGroupName": autorest.Encode("path", resourceGroupName),
558		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
559	}
560
561	const APIVersion = "2015-12-01"
562	queryParameters := map[string]interface{}{
563		"api-version": APIVersion,
564	}
565
566	preparer := autorest.CreatePreparer(
567		autorest.AsGet(),
568		autorest.WithBaseURL(client.BaseURI),
569		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts", pathParameters),
570		autorest.WithQueryParameters(queryParameters))
571	return preparer.Prepare((&http.Request{}).WithContext(ctx))
572}
573
574// ListByResourceGroupSender sends the ListByResourceGroup request. The method will close the
575// http.Response Body if it receives an error.
576func (client AccountClient) ListByResourceGroupSender(req *http.Request) (*http.Response, error) {
577	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
578}
579
580// ListByResourceGroupResponder handles the response to the ListByResourceGroup request. The method always
581// closes the http.Response Body.
582func (client AccountClient) ListByResourceGroupResponder(resp *http.Response) (result AccountListResult, err error) {
583	err = autorest.Respond(
584		resp,
585		azure.WithErrorUnlessStatusCode(http.StatusOK),
586		autorest.ByUnmarshallingJSON(&result),
587		autorest.ByClosing())
588	result.Response = autorest.Response{Response: resp}
589	return
590}
591
592// listByResourceGroupNextResults retrieves the next set of results, if any.
593func (client AccountClient) listByResourceGroupNextResults(ctx context.Context, lastResults AccountListResult) (result AccountListResult, err error) {
594	req, err := lastResults.accountListResultPreparer(ctx)
595	if err != nil {
596		return result, autorest.NewErrorWithError(err, "batch.AccountClient", "listByResourceGroupNextResults", nil, "Failure preparing next results request")
597	}
598	if req == nil {
599		return
600	}
601	resp, err := client.ListByResourceGroupSender(req)
602	if err != nil {
603		result.Response = autorest.Response{Response: resp}
604		return result, autorest.NewErrorWithError(err, "batch.AccountClient", "listByResourceGroupNextResults", resp, "Failure sending next results request")
605	}
606	result, err = client.ListByResourceGroupResponder(resp)
607	if err != nil {
608		err = autorest.NewErrorWithError(err, "batch.AccountClient", "listByResourceGroupNextResults", resp, "Failure responding to next results request")
609	}
610	return
611}
612
613// ListByResourceGroupComplete enumerates all values, automatically crossing page boundaries as required.
614func (client AccountClient) ListByResourceGroupComplete(ctx context.Context, resourceGroupName string) (result AccountListResultIterator, err error) {
615	if tracing.IsEnabled() {
616		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.ListByResourceGroup")
617		defer func() {
618			sc := -1
619			if result.Response().Response.Response != nil {
620				sc = result.page.Response().Response.Response.StatusCode
621			}
622			tracing.EndSpan(ctx, sc, err)
623		}()
624	}
625	result.page, err = client.ListByResourceGroup(ctx, resourceGroupName)
626	return
627}
628
629// RegenerateKey regenerates the specified account key for the Batch account.
630// Parameters:
631// resourceGroupName - the name of the resource group that contains the Batch account.
632// accountName - the name of the account.
633// parameters - the type of key to regenerate.
634func (client AccountClient) RegenerateKey(ctx context.Context, resourceGroupName string, accountName string, parameters AccountRegenerateKeyParameters) (result AccountKeys, err error) {
635	if tracing.IsEnabled() {
636		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.RegenerateKey")
637		defer func() {
638			sc := -1
639			if result.Response.Response != nil {
640				sc = result.Response.Response.StatusCode
641			}
642			tracing.EndSpan(ctx, sc, err)
643		}()
644	}
645	if err := validation.Validate([]validation.Validation{
646		{TargetValue: resourceGroupName,
647			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}},
648		{TargetValue: accountName,
649			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
650				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
651				{Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
652		return result, validation.NewError("batch.AccountClient", "RegenerateKey", err.Error())
653	}
654
655	req, err := client.RegenerateKeyPreparer(ctx, resourceGroupName, accountName, parameters)
656	if err != nil {
657		err = autorest.NewErrorWithError(err, "batch.AccountClient", "RegenerateKey", nil, "Failure preparing request")
658		return
659	}
660
661	resp, err := client.RegenerateKeySender(req)
662	if err != nil {
663		result.Response = autorest.Response{Response: resp}
664		err = autorest.NewErrorWithError(err, "batch.AccountClient", "RegenerateKey", resp, "Failure sending request")
665		return
666	}
667
668	result, err = client.RegenerateKeyResponder(resp)
669	if err != nil {
670		err = autorest.NewErrorWithError(err, "batch.AccountClient", "RegenerateKey", resp, "Failure responding to request")
671		return
672	}
673
674	return
675}
676
677// RegenerateKeyPreparer prepares the RegenerateKey request.
678func (client AccountClient) RegenerateKeyPreparer(ctx context.Context, resourceGroupName string, accountName string, parameters AccountRegenerateKeyParameters) (*http.Request, error) {
679	pathParameters := map[string]interface{}{
680		"accountName":       autorest.Encode("path", accountName),
681		"resourceGroupName": autorest.Encode("path", resourceGroupName),
682		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
683	}
684
685	const APIVersion = "2015-12-01"
686	queryParameters := map[string]interface{}{
687		"api-version": APIVersion,
688	}
689
690	preparer := autorest.CreatePreparer(
691		autorest.AsContentType("application/json; charset=utf-8"),
692		autorest.AsPost(),
693		autorest.WithBaseURL(client.BaseURI),
694		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/regenerateKeys", pathParameters),
695		autorest.WithJSON(parameters),
696		autorest.WithQueryParameters(queryParameters))
697	return preparer.Prepare((&http.Request{}).WithContext(ctx))
698}
699
700// RegenerateKeySender sends the RegenerateKey request. The method will close the
701// http.Response Body if it receives an error.
702func (client AccountClient) RegenerateKeySender(req *http.Request) (*http.Response, error) {
703	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
704}
705
706// RegenerateKeyResponder handles the response to the RegenerateKey request. The method always
707// closes the http.Response Body.
708func (client AccountClient) RegenerateKeyResponder(resp *http.Response) (result AccountKeys, err error) {
709	err = autorest.Respond(
710		resp,
711		azure.WithErrorUnlessStatusCode(http.StatusOK),
712		autorest.ByUnmarshallingJSON(&result),
713		autorest.ByClosing())
714	result.Response = autorest.Response{Response: resp}
715	return
716}
717
718// SynchronizeAutoStorageKeys synchronizes access keys for the auto storage account configured for the specified Batch
719// account.
720// Parameters:
721// resourceGroupName - the name of the resource group that contains the Batch account.
722// accountName - the name of the Batch account.
723func (client AccountClient) SynchronizeAutoStorageKeys(ctx context.Context, resourceGroupName string, accountName string) (result autorest.Response, err error) {
724	if tracing.IsEnabled() {
725		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.SynchronizeAutoStorageKeys")
726		defer func() {
727			sc := -1
728			if result.Response != nil {
729				sc = result.Response.StatusCode
730			}
731			tracing.EndSpan(ctx, sc, err)
732		}()
733	}
734	if err := validation.Validate([]validation.Validation{
735		{TargetValue: resourceGroupName,
736			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}},
737		{TargetValue: accountName,
738			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
739				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
740				{Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
741		return result, validation.NewError("batch.AccountClient", "SynchronizeAutoStorageKeys", err.Error())
742	}
743
744	req, err := client.SynchronizeAutoStorageKeysPreparer(ctx, resourceGroupName, accountName)
745	if err != nil {
746		err = autorest.NewErrorWithError(err, "batch.AccountClient", "SynchronizeAutoStorageKeys", nil, "Failure preparing request")
747		return
748	}
749
750	resp, err := client.SynchronizeAutoStorageKeysSender(req)
751	if err != nil {
752		result.Response = resp
753		err = autorest.NewErrorWithError(err, "batch.AccountClient", "SynchronizeAutoStorageKeys", resp, "Failure sending request")
754		return
755	}
756
757	result, err = client.SynchronizeAutoStorageKeysResponder(resp)
758	if err != nil {
759		err = autorest.NewErrorWithError(err, "batch.AccountClient", "SynchronizeAutoStorageKeys", resp, "Failure responding to request")
760		return
761	}
762
763	return
764}
765
766// SynchronizeAutoStorageKeysPreparer prepares the SynchronizeAutoStorageKeys request.
767func (client AccountClient) SynchronizeAutoStorageKeysPreparer(ctx context.Context, resourceGroupName string, accountName string) (*http.Request, error) {
768	pathParameters := map[string]interface{}{
769		"accountName":       autorest.Encode("path", accountName),
770		"resourceGroupName": autorest.Encode("path", resourceGroupName),
771		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
772	}
773
774	const APIVersion = "2015-12-01"
775	queryParameters := map[string]interface{}{
776		"api-version": APIVersion,
777	}
778
779	preparer := autorest.CreatePreparer(
780		autorest.AsPost(),
781		autorest.WithBaseURL(client.BaseURI),
782		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/syncAutoStorageKeys", pathParameters),
783		autorest.WithQueryParameters(queryParameters))
784	return preparer.Prepare((&http.Request{}).WithContext(ctx))
785}
786
787// SynchronizeAutoStorageKeysSender sends the SynchronizeAutoStorageKeys request. The method will close the
788// http.Response Body if it receives an error.
789func (client AccountClient) SynchronizeAutoStorageKeysSender(req *http.Request) (*http.Response, error) {
790	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
791}
792
793// SynchronizeAutoStorageKeysResponder handles the response to the SynchronizeAutoStorageKeys request. The method always
794// closes the http.Response Body.
795func (client AccountClient) SynchronizeAutoStorageKeysResponder(resp *http.Response) (result autorest.Response, err error) {
796	err = autorest.Respond(
797		resp,
798		azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusNoContent),
799		autorest.ByClosing())
800	result.Response = resp
801	return
802}
803
804// Update updates the properties of an existing Batch account.
805// Parameters:
806// resourceGroupName - the name of the resource group that contains the Batch account.
807// accountName - the name of the account.
808// parameters - additional parameters for account update.
809func (client AccountClient) Update(ctx context.Context, resourceGroupName string, accountName string, parameters AccountUpdateParameters) (result Account, err error) {
810	if tracing.IsEnabled() {
811		ctx = tracing.StartSpan(ctx, fqdn+"/AccountClient.Update")
812		defer func() {
813			sc := -1
814			if result.Response.Response != nil {
815				sc = result.Response.Response.StatusCode
816			}
817			tracing.EndSpan(ctx, sc, err)
818		}()
819	}
820	if err := validation.Validate([]validation.Validation{
821		{TargetValue: resourceGroupName,
822			Constraints: []validation.Constraint{{Target: "resourceGroupName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}},
823		{TargetValue: accountName,
824			Constraints: []validation.Constraint{{Target: "accountName", Name: validation.MaxLength, Rule: 24, Chain: nil},
825				{Target: "accountName", Name: validation.MinLength, Rule: 3, Chain: nil},
826				{Target: "accountName", Name: validation.Pattern, Rule: `^[-\w\._]+$`, Chain: nil}}}}); err != nil {
827		return result, validation.NewError("batch.AccountClient", "Update", err.Error())
828	}
829
830	req, err := client.UpdatePreparer(ctx, resourceGroupName, accountName, parameters)
831	if err != nil {
832		err = autorest.NewErrorWithError(err, "batch.AccountClient", "Update", nil, "Failure preparing request")
833		return
834	}
835
836	resp, err := client.UpdateSender(req)
837	if err != nil {
838		result.Response = autorest.Response{Response: resp}
839		err = autorest.NewErrorWithError(err, "batch.AccountClient", "Update", resp, "Failure sending request")
840		return
841	}
842
843	result, err = client.UpdateResponder(resp)
844	if err != nil {
845		err = autorest.NewErrorWithError(err, "batch.AccountClient", "Update", resp, "Failure responding to request")
846		return
847	}
848
849	return
850}
851
852// UpdatePreparer prepares the Update request.
853func (client AccountClient) UpdatePreparer(ctx context.Context, resourceGroupName string, accountName string, parameters AccountUpdateParameters) (*http.Request, error) {
854	pathParameters := map[string]interface{}{
855		"accountName":       autorest.Encode("path", accountName),
856		"resourceGroupName": autorest.Encode("path", resourceGroupName),
857		"subscriptionId":    autorest.Encode("path", client.SubscriptionID),
858	}
859
860	const APIVersion = "2015-12-01"
861	queryParameters := map[string]interface{}{
862		"api-version": APIVersion,
863	}
864
865	preparer := autorest.CreatePreparer(
866		autorest.AsContentType("application/json; charset=utf-8"),
867		autorest.AsPatch(),
868		autorest.WithBaseURL(client.BaseURI),
869		autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}", pathParameters),
870		autorest.WithJSON(parameters),
871		autorest.WithQueryParameters(queryParameters))
872	return preparer.Prepare((&http.Request{}).WithContext(ctx))
873}
874
875// UpdateSender sends the Update request. The method will close the
876// http.Response Body if it receives an error.
877func (client AccountClient) UpdateSender(req *http.Request) (*http.Response, error) {
878	return client.Send(req, azure.DoRetryWithRegistration(client.Client))
879}
880
881// UpdateResponder handles the response to the Update request. The method always
882// closes the http.Response Body.
883func (client AccountClient) UpdateResponder(resp *http.Response) (result Account, err error) {
884	err = autorest.Respond(
885		resp,
886		azure.WithErrorUnlessStatusCode(http.StatusOK),
887		autorest.ByUnmarshallingJSON(&result),
888		autorest.ByClosing())
889	result.Response = autorest.Response{Response: resp}
890	return
891}
892