1package consumption 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// ReservationsSummariesClient is the consumption management client provides access to consumption resources for Azure 29// Enterprise Subscriptions. 30type ReservationsSummariesClient struct { 31 BaseClient 32} 33 34// NewReservationsSummariesClient creates an instance of the ReservationsSummariesClient client. 35func NewReservationsSummariesClient(subscriptionID string) ReservationsSummariesClient { 36 return NewReservationsSummariesClientWithBaseURI(DefaultBaseURI, subscriptionID) 37} 38 39// NewReservationsSummariesClientWithBaseURI creates an instance of the ReservationsSummariesClient client using a 40// custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, 41// Azure stack). 42func NewReservationsSummariesClientWithBaseURI(baseURI string, subscriptionID string) ReservationsSummariesClient { 43 return ReservationsSummariesClient{NewWithBaseURI(baseURI, subscriptionID)} 44} 45 46// List lists the reservations summaries for daily or monthly grain. 47// Parameters: 48// scope - the scope of the reservation summaries. The scope can be 49// 'providers/Microsoft.Capacity/reservationorders/{ReservationOrderId}' or 50// 'providers/Microsoft.Capacity/reservationorders/{ReservationOrderId}/reservations/{ReservationId}' 51// grain - can be daily or monthly 52// filter - required only for daily grain. The properties/UsageDate for start date and end date. The filter 53// supports 'le' and 'ge' 54func (client ReservationsSummariesClient) List(ctx context.Context, scope string, grain Datagrain, filter string) (result ReservationSummariesListResult, err error) { 55 if tracing.IsEnabled() { 56 ctx = tracing.StartSpan(ctx, fqdn+"/ReservationsSummariesClient.List") 57 defer func() { 58 sc := -1 59 if result.Response.Response != nil { 60 sc = result.Response.Response.StatusCode 61 } 62 tracing.EndSpan(ctx, sc, err) 63 }() 64 } 65 req, err := client.ListPreparer(ctx, scope, grain, filter) 66 if err != nil { 67 err = autorest.NewErrorWithError(err, "consumption.ReservationsSummariesClient", "List", nil, "Failure preparing request") 68 return 69 } 70 71 resp, err := client.ListSender(req) 72 if err != nil { 73 result.Response = autorest.Response{Response: resp} 74 err = autorest.NewErrorWithError(err, "consumption.ReservationsSummariesClient", "List", resp, "Failure sending request") 75 return 76 } 77 78 result, err = client.ListResponder(resp) 79 if err != nil { 80 err = autorest.NewErrorWithError(err, "consumption.ReservationsSummariesClient", "List", resp, "Failure responding to request") 81 } 82 83 return 84} 85 86// ListPreparer prepares the List request. 87func (client ReservationsSummariesClient) ListPreparer(ctx context.Context, scope string, grain Datagrain, filter string) (*http.Request, error) { 88 pathParameters := map[string]interface{}{ 89 "scope": scope, 90 } 91 92 const APIVersion = "2017-11-30" 93 queryParameters := map[string]interface{}{ 94 "api-version": APIVersion, 95 "grain": autorest.Encode("query", grain), 96 } 97 if len(filter) > 0 { 98 queryParameters["$filter"] = autorest.Encode("query", filter) 99 } 100 101 preparer := autorest.CreatePreparer( 102 autorest.AsGet(), 103 autorest.WithBaseURL(client.BaseURI), 104 autorest.WithPathParameters("/{scope}/providers/Microsoft.Consumption/reservationSummaries", pathParameters), 105 autorest.WithQueryParameters(queryParameters)) 106 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 107} 108 109// ListSender sends the List request. The method will close the 110// http.Response Body if it receives an error. 111func (client ReservationsSummariesClient) ListSender(req *http.Request) (*http.Response, error) { 112 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 113} 114 115// ListResponder handles the response to the List request. The method always 116// closes the http.Response Body. 117func (client ReservationsSummariesClient) ListResponder(resp *http.Response) (result ReservationSummariesListResult, err error) { 118 err = autorest.Respond( 119 resp, 120 client.ByInspecting(), 121 azure.WithErrorUnlessStatusCode(http.StatusOK), 122 autorest.ByUnmarshallingJSON(&result), 123 autorest.ByClosing()) 124 result.Response = autorest.Response{Response: resp} 125 return 126} 127