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/tracing" 25 "net/http" 26) 27 28// LocationClient is the client for the Location methods of the Batch service. 29type LocationClient struct { 30 BaseClient 31} 32 33// NewLocationClient creates an instance of the LocationClient client. 34func NewLocationClient(subscriptionID string) LocationClient { 35 return NewLocationClientWithBaseURI(DefaultBaseURI, subscriptionID) 36} 37 38// NewLocationClientWithBaseURI creates an instance of the LocationClient client using a custom endpoint. Use this 39// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 40func NewLocationClientWithBaseURI(baseURI string, subscriptionID string) LocationClient { 41 return LocationClient{NewWithBaseURI(baseURI, subscriptionID)} 42} 43 44// GetQuotas gets the Batch service quotas for the specified subscription at the given location. 45// Parameters: 46// locationName - the desired region for the quotas. 47func (client LocationClient) GetQuotas(ctx context.Context, locationName string) (result LocationQuota, err error) { 48 if tracing.IsEnabled() { 49 ctx = tracing.StartSpan(ctx, fqdn+"/LocationClient.GetQuotas") 50 defer func() { 51 sc := -1 52 if result.Response.Response != nil { 53 sc = result.Response.Response.StatusCode 54 } 55 tracing.EndSpan(ctx, sc, err) 56 }() 57 } 58 req, err := client.GetQuotasPreparer(ctx, locationName) 59 if err != nil { 60 err = autorest.NewErrorWithError(err, "batch.LocationClient", "GetQuotas", nil, "Failure preparing request") 61 return 62 } 63 64 resp, err := client.GetQuotasSender(req) 65 if err != nil { 66 result.Response = autorest.Response{Response: resp} 67 err = autorest.NewErrorWithError(err, "batch.LocationClient", "GetQuotas", resp, "Failure sending request") 68 return 69 } 70 71 result, err = client.GetQuotasResponder(resp) 72 if err != nil { 73 err = autorest.NewErrorWithError(err, "batch.LocationClient", "GetQuotas", resp, "Failure responding to request") 74 return 75 } 76 77 return 78} 79 80// GetQuotasPreparer prepares the GetQuotas request. 81func (client LocationClient) GetQuotasPreparer(ctx context.Context, locationName string) (*http.Request, error) { 82 pathParameters := map[string]interface{}{ 83 "locationName": autorest.Encode("path", locationName), 84 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 85 } 86 87 const APIVersion = "2017-01-01" 88 queryParameters := map[string]interface{}{ 89 "api-version": APIVersion, 90 } 91 92 preparer := autorest.CreatePreparer( 93 autorest.AsGet(), 94 autorest.WithBaseURL(client.BaseURI), 95 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Batch/locations/{locationName}/quotas", pathParameters), 96 autorest.WithQueryParameters(queryParameters)) 97 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 98} 99 100// GetQuotasSender sends the GetQuotas request. The method will close the 101// http.Response Body if it receives an error. 102func (client LocationClient) GetQuotasSender(req *http.Request) (*http.Response, error) { 103 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 104} 105 106// GetQuotasResponder handles the response to the GetQuotas request. The method always 107// closes the http.Response Body. 108func (client LocationClient) GetQuotasResponder(resp *http.Response) (result LocationQuota, err error) { 109 err = autorest.Respond( 110 resp, 111 azure.WithErrorUnlessStatusCode(http.StatusOK), 112 autorest.ByUnmarshallingJSON(&result), 113 autorest.ByClosing()) 114 result.Response = autorest.Response{Response: resp} 115 return 116} 117