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