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/validation" 25 "github.com/Azure/go-autorest/tracing" 26 "net/http" 27) 28 29// LocationClient is the client for the Location methods of the Batch service. 30type LocationClient struct { 31 BaseClient 32} 33 34// NewLocationClient creates an instance of the LocationClient client. 35func NewLocationClient(subscriptionID string) LocationClient { 36 return NewLocationClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewLocationClientWithBaseURI creates an instance of the LocationClient client using a custom endpoint. Use this 40// when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 41func NewLocationClientWithBaseURI(baseURI string, subscriptionID string) LocationClient { 42 return LocationClient{NewWithBaseURI(baseURI, subscriptionID)} 43} 44 45// CheckNameAvailability checks whether the Batch account name is available in the specified region. 46// Parameters: 47// locationName - the desired region for the name check. 48// parameters - properties needed to check the availability of a name. 49func (client LocationClient) CheckNameAvailability(ctx context.Context, locationName string, parameters CheckNameAvailabilityParameters) (result CheckNameAvailabilityResult, err error) { 50 if tracing.IsEnabled() { 51 ctx = tracing.StartSpan(ctx, fqdn+"/LocationClient.CheckNameAvailability") 52 defer func() { 53 sc := -1 54 if result.Response.Response != nil { 55 sc = result.Response.Response.StatusCode 56 } 57 tracing.EndSpan(ctx, sc, err) 58 }() 59 } 60 if err := validation.Validate([]validation.Validation{ 61 {TargetValue: parameters, 62 Constraints: []validation.Constraint{{Target: "parameters.Name", Name: validation.Null, Rule: true, Chain: nil}, 63 {Target: "parameters.Type", Name: validation.Null, Rule: true, Chain: nil}}}}); err != nil { 64 return result, validation.NewError("batch.LocationClient", "CheckNameAvailability", err.Error()) 65 } 66 67 req, err := client.CheckNameAvailabilityPreparer(ctx, locationName, parameters) 68 if err != nil { 69 err = autorest.NewErrorWithError(err, "batch.LocationClient", "CheckNameAvailability", nil, "Failure preparing request") 70 return 71 } 72 73 resp, err := client.CheckNameAvailabilitySender(req) 74 if err != nil { 75 result.Response = autorest.Response{Response: resp} 76 err = autorest.NewErrorWithError(err, "batch.LocationClient", "CheckNameAvailability", resp, "Failure sending request") 77 return 78 } 79 80 result, err = client.CheckNameAvailabilityResponder(resp) 81 if err != nil { 82 err = autorest.NewErrorWithError(err, "batch.LocationClient", "CheckNameAvailability", resp, "Failure responding to request") 83 } 84 85 return 86} 87 88// CheckNameAvailabilityPreparer prepares the CheckNameAvailability request. 89func (client LocationClient) CheckNameAvailabilityPreparer(ctx context.Context, locationName string, parameters CheckNameAvailabilityParameters) (*http.Request, error) { 90 pathParameters := map[string]interface{}{ 91 "locationName": autorest.Encode("path", locationName), 92 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 93 } 94 95 const APIVersion = "2017-05-01" 96 queryParameters := map[string]interface{}{ 97 "api-version": APIVersion, 98 } 99 100 preparer := autorest.CreatePreparer( 101 autorest.AsContentType("application/json; charset=utf-8"), 102 autorest.AsPost(), 103 autorest.WithBaseURL(client.BaseURI), 104 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Batch/locations/{locationName}/checkNameAvailability", pathParameters), 105 autorest.WithJSON(parameters), 106 autorest.WithQueryParameters(queryParameters)) 107 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 108} 109 110// CheckNameAvailabilitySender sends the CheckNameAvailability request. The method will close the 111// http.Response Body if it receives an error. 112func (client LocationClient) CheckNameAvailabilitySender(req *http.Request) (*http.Response, error) { 113 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 114} 115 116// CheckNameAvailabilityResponder handles the response to the CheckNameAvailability request. The method always 117// closes the http.Response Body. 118func (client LocationClient) CheckNameAvailabilityResponder(resp *http.Response) (result CheckNameAvailabilityResult, err error) { 119 err = autorest.Respond( 120 resp, 121 client.ByInspecting(), 122 azure.WithErrorUnlessStatusCode(http.StatusOK), 123 autorest.ByUnmarshallingJSON(&result), 124 autorest.ByClosing()) 125 result.Response = autorest.Response{Response: resp} 126 return 127} 128 129// GetQuotas gets the Batch service quotas for the specified subscription at the given location. 130// Parameters: 131// locationName - the region for which to retrieve Batch service quotas. 132func (client LocationClient) GetQuotas(ctx context.Context, locationName string) (result LocationQuota, err error) { 133 if tracing.IsEnabled() { 134 ctx = tracing.StartSpan(ctx, fqdn+"/LocationClient.GetQuotas") 135 defer func() { 136 sc := -1 137 if result.Response.Response != nil { 138 sc = result.Response.Response.StatusCode 139 } 140 tracing.EndSpan(ctx, sc, err) 141 }() 142 } 143 req, err := client.GetQuotasPreparer(ctx, locationName) 144 if err != nil { 145 err = autorest.NewErrorWithError(err, "batch.LocationClient", "GetQuotas", nil, "Failure preparing request") 146 return 147 } 148 149 resp, err := client.GetQuotasSender(req) 150 if err != nil { 151 result.Response = autorest.Response{Response: resp} 152 err = autorest.NewErrorWithError(err, "batch.LocationClient", "GetQuotas", resp, "Failure sending request") 153 return 154 } 155 156 result, err = client.GetQuotasResponder(resp) 157 if err != nil { 158 err = autorest.NewErrorWithError(err, "batch.LocationClient", "GetQuotas", resp, "Failure responding to request") 159 } 160 161 return 162} 163 164// GetQuotasPreparer prepares the GetQuotas request. 165func (client LocationClient) GetQuotasPreparer(ctx context.Context, locationName string) (*http.Request, error) { 166 pathParameters := map[string]interface{}{ 167 "locationName": autorest.Encode("path", locationName), 168 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 169 } 170 171 const APIVersion = "2017-05-01" 172 queryParameters := map[string]interface{}{ 173 "api-version": APIVersion, 174 } 175 176 preparer := autorest.CreatePreparer( 177 autorest.AsGet(), 178 autorest.WithBaseURL(client.BaseURI), 179 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Batch/locations/{locationName}/quotas", pathParameters), 180 autorest.WithQueryParameters(queryParameters)) 181 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 182} 183 184// GetQuotasSender sends the GetQuotas request. The method will close the 185// http.Response Body if it receives an error. 186func (client LocationClient) GetQuotasSender(req *http.Request) (*http.Response, error) { 187 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 188} 189 190// GetQuotasResponder handles the response to the GetQuotas request. The method always 191// closes the http.Response Body. 192func (client LocationClient) GetQuotasResponder(resp *http.Response) (result LocationQuota, err error) { 193 err = autorest.Respond( 194 resp, 195 client.ByInspecting(), 196 azure.WithErrorUnlessStatusCode(http.StatusOK), 197 autorest.ByUnmarshallingJSON(&result), 198 autorest.ByClosing()) 199 result.Response = autorest.Response{Response: resp} 200 return 201} 202