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. 39func NewLocationClientWithBaseURI(baseURI string, subscriptionID string) LocationClient { 40 return LocationClient{NewWithBaseURI(baseURI, subscriptionID)} 41} 42 43// GetQuotas gets the Batch service quotas for the specified subscription at the given location. 44// Parameters: 45// locationName - the desired region for the quotas. 46func (client LocationClient) GetQuotas(ctx context.Context, locationName string) (result LocationQuota, err error) { 47 if tracing.IsEnabled() { 48 ctx = tracing.StartSpan(ctx, fqdn+"/LocationClient.GetQuotas") 49 defer func() { 50 sc := -1 51 if result.Response.Response != nil { 52 sc = result.Response.Response.StatusCode 53 } 54 tracing.EndSpan(ctx, sc, err) 55 }() 56 } 57 req, err := client.GetQuotasPreparer(ctx, locationName) 58 if err != nil { 59 err = autorest.NewErrorWithError(err, "batch.LocationClient", "GetQuotas", nil, "Failure preparing request") 60 return 61 } 62 63 resp, err := client.GetQuotasSender(req) 64 if err != nil { 65 result.Response = autorest.Response{Response: resp} 66 err = autorest.NewErrorWithError(err, "batch.LocationClient", "GetQuotas", resp, "Failure sending request") 67 return 68 } 69 70 result, err = client.GetQuotasResponder(resp) 71 if err != nil { 72 err = autorest.NewErrorWithError(err, "batch.LocationClient", "GetQuotas", resp, "Failure responding to request") 73 } 74 75 return 76} 77 78// GetQuotasPreparer prepares the GetQuotas request. 79func (client LocationClient) GetQuotasPreparer(ctx context.Context, locationName string) (*http.Request, error) { 80 pathParameters := map[string]interface{}{ 81 "locationName": autorest.Encode("path", locationName), 82 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 83 } 84 85 const APIVersion = "2015-12-01" 86 queryParameters := map[string]interface{}{ 87 "api-version": APIVersion, 88 } 89 90 preparer := autorest.CreatePreparer( 91 autorest.AsGet(), 92 autorest.WithBaseURL(client.BaseURI), 93 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Batch/locations/{locationName}/quotas", pathParameters), 94 autorest.WithQueryParameters(queryParameters)) 95 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 96} 97 98// GetQuotasSender sends the GetQuotas request. The method will close the 99// http.Response Body if it receives an error. 100func (client LocationClient) GetQuotasSender(req *http.Request) (*http.Response, error) { 101 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 102 return autorest.SendWithSender(client, req, sd...) 103} 104 105// GetQuotasResponder handles the response to the GetQuotas request. The method always 106// closes the http.Response Body. 107func (client LocationClient) GetQuotasResponder(resp *http.Response) (result LocationQuota, err error) { 108 err = autorest.Respond( 109 resp, 110 client.ByInspecting(), 111 azure.WithErrorUnlessStatusCode(http.StatusOK), 112 autorest.ByUnmarshallingJSON(&result), 113 autorest.ByClosing()) 114 result.Response = autorest.Response{Response: resp} 115 return 116} 117