1package reservations 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// QuotaClient is the client for the Quota methods of the Reservations service. 29type QuotaClient struct { 30 BaseClient 31} 32 33// NewQuotaClient creates an instance of the QuotaClient client. 34func NewQuotaClient() QuotaClient { 35 return NewQuotaClientWithBaseURI(DefaultBaseURI) 36} 37 38// NewQuotaClientWithBaseURI creates an instance of the QuotaClient client using a custom endpoint. Use this when 39// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 40func NewQuotaClientWithBaseURI(baseURI string) QuotaClient { 41 return QuotaClient{NewWithBaseURI(baseURI)} 42} 43 44// CreateOrUpdate submits Quota change request for a resource provider for the specified location for the specific 45// resource in the parameter. To use, first make a Get request to get quota information for the specific resource. This 46// information consists of information regarding that specific resources. For the specific resource, if it requires an 47// update to the quota, update the limit field in the response from the Get request to the new value of quota. Then, 48// submit this updated JSON object to this quota request API. This will update the quota to the value specified. The 49// location header in the response will be used to track the status of the quota request. Please check the 50// provisioningState field in the response. The Patch operation can be used also to update the quota. 51// Parameters: 52// subscriptionID - azure subscription id. 53// providerID - azure resource Provider id. 54// location - azure region. 55// resourceName - the Resource name for the specific resource provider, such as SKU name for Microsoft.Compute, 56// pool for Microsoft.Batch. 57// createQuotaRequest - quota requests payload. 58func (client QuotaClient) CreateOrUpdate(ctx context.Context, subscriptionID string, providerID string, location string, resourceName string, createQuotaRequest CurrentQuotaLimitBase) (result QuotaCreateOrUpdateFuture, err error) { 59 if tracing.IsEnabled() { 60 ctx = tracing.StartSpan(ctx, fqdn+"/QuotaClient.CreateOrUpdate") 61 defer func() { 62 sc := -1 63 if result.Response() != nil { 64 sc = result.Response().StatusCode 65 } 66 tracing.EndSpan(ctx, sc, err) 67 }() 68 } 69 req, err := client.CreateOrUpdatePreparer(ctx, subscriptionID, providerID, location, resourceName, createQuotaRequest) 70 if err != nil { 71 err = autorest.NewErrorWithError(err, "reservations.QuotaClient", "CreateOrUpdate", nil, "Failure preparing request") 72 return 73 } 74 75 result, err = client.CreateOrUpdateSender(req) 76 if err != nil { 77 err = autorest.NewErrorWithError(err, "reservations.QuotaClient", "CreateOrUpdate", result.Response(), "Failure sending request") 78 return 79 } 80 81 return 82} 83 84// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 85func (client QuotaClient) CreateOrUpdatePreparer(ctx context.Context, subscriptionID string, providerID string, location string, resourceName string, createQuotaRequest CurrentQuotaLimitBase) (*http.Request, error) { 86 pathParameters := map[string]interface{}{ 87 "location": autorest.Encode("path", location), 88 "providerId": autorest.Encode("path", providerID), 89 "resourceName": autorest.Encode("path", resourceName), 90 "subscriptionId": autorest.Encode("path", subscriptionID), 91 } 92 93 const APIVersion = "2019-07-19-preview" 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}/providers/Microsoft.Capacity/resourceProviders/{providerId}/locations/{location}/serviceLimits/{resourceName}", pathParameters), 103 autorest.WithJSON(createQuotaRequest), 104 autorest.WithQueryParameters(queryParameters)) 105 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 106} 107 108// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 109// http.Response Body if it receives an error. 110func (client QuotaClient) CreateOrUpdateSender(req *http.Request) (future QuotaCreateOrUpdateFuture, 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 future.Future, err = azure.NewFutureFromResponse(resp) 117 return 118} 119 120// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 121// closes the http.Response Body. 122func (client QuotaClient) CreateOrUpdateResponder(resp *http.Response) (result SetObject, err error) { 123 err = autorest.Respond( 124 resp, 125 client.ByInspecting(), 126 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 127 autorest.ByUnmarshallingJSON(&result), 128 autorest.ByClosing()) 129 result.Response = autorest.Response{Response: resp} 130 return 131} 132 133// Get this API gets the current quota limit and usages for the specific resource for resource provider for the 134// specified location. This response can be used to submit quotaRequests. 135// Parameters: 136// subscriptionID - azure subscription id. 137// providerID - azure resource Provider id. 138// location - azure region. 139// resourceName - the Resource name for the specific resource provider, such as SKU name for Microsoft.Compute, 140// pool for Microsoft.Batch. 141func (client QuotaClient) Get(ctx context.Context, subscriptionID string, providerID string, location string, resourceName string) (result CurrentQuotaLimitBase, err error) { 142 if tracing.IsEnabled() { 143 ctx = tracing.StartSpan(ctx, fqdn+"/QuotaClient.Get") 144 defer func() { 145 sc := -1 146 if result.Response.Response != nil { 147 sc = result.Response.Response.StatusCode 148 } 149 tracing.EndSpan(ctx, sc, err) 150 }() 151 } 152 req, err := client.GetPreparer(ctx, subscriptionID, providerID, location, resourceName) 153 if err != nil { 154 err = autorest.NewErrorWithError(err, "reservations.QuotaClient", "Get", nil, "Failure preparing request") 155 return 156 } 157 158 resp, err := client.GetSender(req) 159 if err != nil { 160 result.Response = autorest.Response{Response: resp} 161 err = autorest.NewErrorWithError(err, "reservations.QuotaClient", "Get", resp, "Failure sending request") 162 return 163 } 164 165 result, err = client.GetResponder(resp) 166 if err != nil { 167 err = autorest.NewErrorWithError(err, "reservations.QuotaClient", "Get", resp, "Failure responding to request") 168 } 169 170 return 171} 172 173// GetPreparer prepares the Get request. 174func (client QuotaClient) GetPreparer(ctx context.Context, subscriptionID string, providerID string, location string, resourceName string) (*http.Request, error) { 175 pathParameters := map[string]interface{}{ 176 "location": autorest.Encode("path", location), 177 "providerId": autorest.Encode("path", providerID), 178 "resourceName": autorest.Encode("path", resourceName), 179 "subscriptionId": autorest.Encode("path", subscriptionID), 180 } 181 182 const APIVersion = "2019-07-19-preview" 183 queryParameters := map[string]interface{}{ 184 "api-version": APIVersion, 185 } 186 187 preparer := autorest.CreatePreparer( 188 autorest.AsGet(), 189 autorest.WithBaseURL(client.BaseURI), 190 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Capacity/resourceProviders/{providerId}/locations/{location}/serviceLimits/{resourceName}", pathParameters), 191 autorest.WithQueryParameters(queryParameters)) 192 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 193} 194 195// GetSender sends the Get request. The method will close the 196// http.Response Body if it receives an error. 197func (client QuotaClient) GetSender(req *http.Request) (*http.Response, error) { 198 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 199} 200 201// GetResponder handles the response to the Get request. The method always 202// closes the http.Response Body. 203func (client QuotaClient) GetResponder(resp *http.Response) (result CurrentQuotaLimitBase, err error) { 204 err = autorest.Respond( 205 resp, 206 client.ByInspecting(), 207 azure.WithErrorUnlessStatusCode(http.StatusOK), 208 autorest.ByUnmarshallingJSON(&result), 209 autorest.ByClosing()) 210 result.Response = autorest.Response{Response: resp} 211 return 212} 213 214// List this API gets the current quota limits and usages for the resource provider for the specified location. This 215// response can be used to submit quotaRequests. 216// Parameters: 217// subscriptionID - azure subscription id. 218// providerID - azure resource Provider id. 219// location - azure region. 220func (client QuotaClient) List(ctx context.Context, subscriptionID string, providerID string, location string) (result QuotaLimitsPage, err error) { 221 if tracing.IsEnabled() { 222 ctx = tracing.StartSpan(ctx, fqdn+"/QuotaClient.List") 223 defer func() { 224 sc := -1 225 if result.ql.Response.Response != nil { 226 sc = result.ql.Response.Response.StatusCode 227 } 228 tracing.EndSpan(ctx, sc, err) 229 }() 230 } 231 result.fn = client.listNextResults 232 req, err := client.ListPreparer(ctx, subscriptionID, providerID, location) 233 if err != nil { 234 err = autorest.NewErrorWithError(err, "reservations.QuotaClient", "List", nil, "Failure preparing request") 235 return 236 } 237 238 resp, err := client.ListSender(req) 239 if err != nil { 240 result.ql.Response = autorest.Response{Response: resp} 241 err = autorest.NewErrorWithError(err, "reservations.QuotaClient", "List", resp, "Failure sending request") 242 return 243 } 244 245 result.ql, err = client.ListResponder(resp) 246 if err != nil { 247 err = autorest.NewErrorWithError(err, "reservations.QuotaClient", "List", resp, "Failure responding to request") 248 } 249 250 return 251} 252 253// ListPreparer prepares the List request. 254func (client QuotaClient) ListPreparer(ctx context.Context, subscriptionID string, providerID string, location string) (*http.Request, error) { 255 pathParameters := map[string]interface{}{ 256 "location": autorest.Encode("path", location), 257 "providerId": autorest.Encode("path", providerID), 258 "subscriptionId": autorest.Encode("path", subscriptionID), 259 } 260 261 const APIVersion = "2019-07-19-preview" 262 queryParameters := map[string]interface{}{ 263 "api-version": APIVersion, 264 } 265 266 preparer := autorest.CreatePreparer( 267 autorest.AsGet(), 268 autorest.WithBaseURL(client.BaseURI), 269 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Capacity/resourceProviders/{providerId}/locations/{location}/serviceLimits", pathParameters), 270 autorest.WithQueryParameters(queryParameters)) 271 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 272} 273 274// ListSender sends the List request. The method will close the 275// http.Response Body if it receives an error. 276func (client QuotaClient) ListSender(req *http.Request) (*http.Response, error) { 277 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 278} 279 280// ListResponder handles the response to the List request. The method always 281// closes the http.Response Body. 282func (client QuotaClient) ListResponder(resp *http.Response) (result QuotaLimits, err error) { 283 err = autorest.Respond( 284 resp, 285 client.ByInspecting(), 286 azure.WithErrorUnlessStatusCode(http.StatusOK), 287 autorest.ByUnmarshallingJSON(&result), 288 autorest.ByClosing()) 289 result.Response = autorest.Response{Response: resp} 290 return 291} 292 293// listNextResults retrieves the next set of results, if any. 294func (client QuotaClient) listNextResults(ctx context.Context, lastResults QuotaLimits) (result QuotaLimits, err error) { 295 req, err := lastResults.quotaLimitsPreparer(ctx) 296 if err != nil { 297 return result, autorest.NewErrorWithError(err, "reservations.QuotaClient", "listNextResults", nil, "Failure preparing next results request") 298 } 299 if req == nil { 300 return 301 } 302 resp, err := client.ListSender(req) 303 if err != nil { 304 result.Response = autorest.Response{Response: resp} 305 return result, autorest.NewErrorWithError(err, "reservations.QuotaClient", "listNextResults", resp, "Failure sending next results request") 306 } 307 result, err = client.ListResponder(resp) 308 if err != nil { 309 err = autorest.NewErrorWithError(err, "reservations.QuotaClient", "listNextResults", resp, "Failure responding to next results request") 310 } 311 return 312} 313 314// ListComplete enumerates all values, automatically crossing page boundaries as required. 315func (client QuotaClient) ListComplete(ctx context.Context, subscriptionID string, providerID string, location string) (result QuotaLimitsIterator, err error) { 316 if tracing.IsEnabled() { 317 ctx = tracing.StartSpan(ctx, fqdn+"/QuotaClient.List") 318 defer func() { 319 sc := -1 320 if result.Response().Response.Response != nil { 321 sc = result.page.Response().Response.Response.StatusCode 322 } 323 tracing.EndSpan(ctx, sc, err) 324 }() 325 } 326 result.page, err = client.List(ctx, subscriptionID, providerID, location) 327 return 328} 329 330// Update submits Quota change request for a resource provider for the specified location for the specific resource in 331// the parameter. To use, first make a Get request to get quota information for the specific resource. This information 332// consists of information regarding that specific resources. For the specific resource, if it requires an update to 333// the quota, update the limit field in the response from the Get request to the new value of quota. Then, submit this 334// updated JSON object to this quota request API. This will update the quota to the value specified. The location 335// header in the response will be used to track the status of the quota request. Please check the provisioningState 336// field in the response. The Put operation can be used also to update the quota. 337// Parameters: 338// subscriptionID - azure subscription id. 339// providerID - azure resource Provider id. 340// location - azure region. 341// resourceName - the Resource name for the specific resource provider, such as SKU name for Microsoft.Compute, 342// pool for Microsoft.Batch. 343// createQuotaRequest - quota requests payload. 344func (client QuotaClient) Update(ctx context.Context, subscriptionID string, providerID string, location string, resourceName string, createQuotaRequest CurrentQuotaLimitBase) (result QuotaUpdateFuture, err error) { 345 if tracing.IsEnabled() { 346 ctx = tracing.StartSpan(ctx, fqdn+"/QuotaClient.Update") 347 defer func() { 348 sc := -1 349 if result.Response() != nil { 350 sc = result.Response().StatusCode 351 } 352 tracing.EndSpan(ctx, sc, err) 353 }() 354 } 355 req, err := client.UpdatePreparer(ctx, subscriptionID, providerID, location, resourceName, createQuotaRequest) 356 if err != nil { 357 err = autorest.NewErrorWithError(err, "reservations.QuotaClient", "Update", nil, "Failure preparing request") 358 return 359 } 360 361 result, err = client.UpdateSender(req) 362 if err != nil { 363 err = autorest.NewErrorWithError(err, "reservations.QuotaClient", "Update", result.Response(), "Failure sending request") 364 return 365 } 366 367 return 368} 369 370// UpdatePreparer prepares the Update request. 371func (client QuotaClient) UpdatePreparer(ctx context.Context, subscriptionID string, providerID string, location string, resourceName string, createQuotaRequest CurrentQuotaLimitBase) (*http.Request, error) { 372 pathParameters := map[string]interface{}{ 373 "location": autorest.Encode("path", location), 374 "providerId": autorest.Encode("path", providerID), 375 "resourceName": autorest.Encode("path", resourceName), 376 "subscriptionId": autorest.Encode("path", subscriptionID), 377 } 378 379 const APIVersion = "2019-07-19-preview" 380 queryParameters := map[string]interface{}{ 381 "api-version": APIVersion, 382 } 383 384 preparer := autorest.CreatePreparer( 385 autorest.AsContentType("application/json; charset=utf-8"), 386 autorest.AsPatch(), 387 autorest.WithBaseURL(client.BaseURI), 388 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Capacity/resourceProviders/{providerId}/locations/{location}/serviceLimits/{resourceName}", pathParameters), 389 autorest.WithJSON(createQuotaRequest), 390 autorest.WithQueryParameters(queryParameters)) 391 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 392} 393 394// UpdateSender sends the Update request. The method will close the 395// http.Response Body if it receives an error. 396func (client QuotaClient) UpdateSender(req *http.Request) (future QuotaUpdateFuture, err error) { 397 var resp *http.Response 398 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 399 if err != nil { 400 return 401 } 402 future.Future, err = azure.NewFutureFromResponse(resp) 403 return 404} 405 406// UpdateResponder handles the response to the Update request. The method always 407// closes the http.Response Body. 408func (client QuotaClient) UpdateResponder(resp *http.Response) (result SetObject, err error) { 409 err = autorest.Respond( 410 resp, 411 client.ByInspecting(), 412 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 413 autorest.ByUnmarshallingJSON(&result), 414 autorest.ByClosing()) 415 result.Response = autorest.Response{Response: resp} 416 return 417} 418