diff --git a/services/consumption/mgmt/2018-03-31/consumption/models.go b/services/consumption/mgmt/2018-03-31/consumption/models.go index 048940b41918..d011c22bc063 100644 --- a/services/consumption/mgmt/2018-03-31/consumption/models.go +++ b/services/consumption/mgmt/2018-03-31/consumption/models.go @@ -1149,6 +1149,253 @@ type ReservationDetailsProperties struct { TotalReservedQuantity *decimal.Decimal `json:"totalReservedQuantity,omitempty"` } +// ReservationRecommendations reservation recommendations resource. +type ReservationRecommendations struct { + // ID - Resource Id. + ID *string `json:"id,omitempty"` + // Name - Resource name. + Name *string `json:"name,omitempty"` + // Type - Resource type. + Type *string `json:"type,omitempty"` + // Tags - Resource tags. + Tags map[string]*string `json:"tags"` + // Location - Resource location + Location *string `json:"location,omitempty"` + // Sku - Resource sku + Sku *string `json:"sku,omitempty"` + *ReservationRecommendationsProperties `json:"properties,omitempty"` +} + +// MarshalJSON is the custom marshaler for ReservationRecommendations. +func (rr ReservationRecommendations) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if rr.ID != nil { + objectMap["id"] = rr.ID + } + if rr.Name != nil { + objectMap["name"] = rr.Name + } + if rr.Type != nil { + objectMap["type"] = rr.Type + } + if rr.Tags != nil { + objectMap["tags"] = rr.Tags + } + if rr.Location != nil { + objectMap["location"] = rr.Location + } + if rr.Sku != nil { + objectMap["sku"] = rr.Sku + } + if rr.ReservationRecommendationsProperties != nil { + objectMap["properties"] = rr.ReservationRecommendationsProperties + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for ReservationRecommendations struct. +func (rr *ReservationRecommendations) UnmarshalJSON(body []byte) error { + var m map[string]*json.RawMessage + err := json.Unmarshal(body, &m) + if err != nil { + return err + } + for k, v := range m { + switch k { + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + rr.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + rr.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + rr.Type = &typeVar + } + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + rr.Tags = tags + } + case "location": + if v != nil { + var location string + err = json.Unmarshal(*v, &location) + if err != nil { + return err + } + rr.Location = &location + } + case "sku": + if v != nil { + var sku string + err = json.Unmarshal(*v, &sku) + if err != nil { + return err + } + rr.Sku = &sku + } + case "properties": + if v != nil { + var reservationRecommendationsProperties ReservationRecommendationsProperties + err = json.Unmarshal(*v, &reservationRecommendationsProperties) + if err != nil { + return err + } + rr.ReservationRecommendationsProperties = &reservationRecommendationsProperties + } + } + } + + return nil +} + +// ReservationRecommendationsListResult result of listing reservation recommendations. +type ReservationRecommendationsListResult struct { + autorest.Response `json:"-"` + // Value - The list of reservation recommendations. + Value *[]ReservationRecommendations `json:"value,omitempty"` + // NextLink - The link (url) to the next page of results. + NextLink *string `json:"nextLink,omitempty"` +} + +// ReservationRecommendationsListResultIterator provides access to a complete listing of ReservationRecommendations +// values. +type ReservationRecommendationsListResultIterator struct { + i int + page ReservationRecommendationsListResultPage +} + +// Next advances to the next value. If there was an error making +// the request the iterator does not advance and the error is returned. +func (iter *ReservationRecommendationsListResultIterator) Next() error { + iter.i++ + if iter.i < len(iter.page.Values()) { + return nil + } + err := iter.page.Next() + if err != nil { + iter.i-- + return err + } + iter.i = 0 + return nil +} + +// NotDone returns true if the enumeration should be started or is not yet complete. +func (iter ReservationRecommendationsListResultIterator) NotDone() bool { + return iter.page.NotDone() && iter.i < len(iter.page.Values()) +} + +// Response returns the raw server response from the last page request. +func (iter ReservationRecommendationsListResultIterator) Response() ReservationRecommendationsListResult { + return iter.page.Response() +} + +// Value returns the current value or a zero-initialized value if the +// iterator has advanced beyond the end of the collection. +func (iter ReservationRecommendationsListResultIterator) Value() ReservationRecommendations { + if !iter.page.NotDone() { + return ReservationRecommendations{} + } + return iter.page.Values()[iter.i] +} + +// IsEmpty returns true if the ListResult contains no values. +func (rrlr ReservationRecommendationsListResult) IsEmpty() bool { + return rrlr.Value == nil || len(*rrlr.Value) == 0 +} + +// reservationRecommendationsListResultPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (rrlr ReservationRecommendationsListResult) reservationRecommendationsListResultPreparer() (*http.Request, error) { + if rrlr.NextLink == nil || len(to.String(rrlr.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(rrlr.NextLink))) +} + +// ReservationRecommendationsListResultPage contains a page of ReservationRecommendations values. +type ReservationRecommendationsListResultPage struct { + fn func(ReservationRecommendationsListResult) (ReservationRecommendationsListResult, error) + rrlr ReservationRecommendationsListResult +} + +// Next advances to the next page of values. If there was an error making +// the request the page does not advance and the error is returned. +func (page *ReservationRecommendationsListResultPage) Next() error { + next, err := page.fn(page.rrlr) + if err != nil { + return err + } + page.rrlr = next + return nil +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page ReservationRecommendationsListResultPage) NotDone() bool { + return !page.rrlr.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page ReservationRecommendationsListResultPage) Response() ReservationRecommendationsListResult { + return page.rrlr +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page ReservationRecommendationsListResultPage) Values() []ReservationRecommendations { + if page.rrlr.IsEmpty() { + return nil + } + return *page.rrlr.Value +} + +// ReservationRecommendationsProperties the properties of the reservation recommendations. +type ReservationRecommendationsProperties struct { + // LookBackPeriod - The number of days of usage to look back for recommendations. + LookBackPeriod *string `json:"lookBackPeriod,omitempty"` + // MeterID - The meter id (GUID) + MeterID *uuid.UUID `json:"meterId,omitempty"` + // Term - RI recommendations in one or three year terms. + Term *string `json:"term,omitempty"` + // CostWithNoReservedInstances - The total amount of cost without reserved instances. + CostWithNoReservedInstances *decimal.Decimal `json:"costWithNoReservedInstances,omitempty"` + // RecommendedQuantity - Recomended quality for reserved instances. + RecommendedQuantity *decimal.Decimal `json:"recommendedQuantity,omitempty"` + // TotalCostWithReservedInstances - The total amount of cost with reserved instances. + TotalCostWithReservedInstances *decimal.Decimal `json:"totalCostWithReservedInstances,omitempty"` + // NetSavings - Total estimated savings with reserved instances. + NetSavings *decimal.Decimal `json:"netSavings,omitempty"` + // FirstUsageDate - The usage date for looking back. + FirstUsageDate *date.Time `json:"firstUsageDate,omitempty"` + // Scope - Shared or single recommendation. + Scope *string `json:"scope,omitempty"` +} + // ReservationSummaries reservation summaries resource. type ReservationSummaries struct { *ReservationSummariesProperties `json:"properties,omitempty"` @@ -1397,6 +1644,14 @@ func (r Resource) MarshalJSON() ([]byte, error) { return json.Marshal(objectMap) } +// ResourceAttributes the Resource model definition. +type ResourceAttributes struct { + // Location - Resource location + Location *string `json:"location,omitempty"` + // Sku - Resource sku + Sku *string `json:"sku,omitempty"` +} + // UsageDetail an usage detail resource. type UsageDetail struct { *UsageDetailProperties `json:"properties,omitempty"` diff --git a/services/consumption/mgmt/2018-03-31/consumption/reservationrecommendations.go b/services/consumption/mgmt/2018-03-31/consumption/reservationrecommendations.go new file mode 100644 index 000000000000..c1a6119a548b --- /dev/null +++ b/services/consumption/mgmt/2018-03-31/consumption/reservationrecommendations.go @@ -0,0 +1,136 @@ +package consumption + +// Copyright (c) Microsoft and contributors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Code generated by Microsoft (R) AutoRest Code Generator. +// Changes may cause incorrect behavior and will be lost if the code is regenerated. + +import ( + "context" + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "net/http" +) + +// ReservationRecommendationsClient is the consumption management client provides access to consumption resources for +// Azure Enterprise Subscriptions. +type ReservationRecommendationsClient struct { + BaseClient +} + +// NewReservationRecommendationsClient creates an instance of the ReservationRecommendationsClient client. +func NewReservationRecommendationsClient(subscriptionID string, grain Datagrain) ReservationRecommendationsClient { + return NewReservationRecommendationsClientWithBaseURI(DefaultBaseURI, subscriptionID, grain) +} + +// NewReservationRecommendationsClientWithBaseURI creates an instance of the ReservationRecommendationsClient client. +func NewReservationRecommendationsClientWithBaseURI(baseURI string, subscriptionID string, grain Datagrain) ReservationRecommendationsClient { + return ReservationRecommendationsClient{NewWithBaseURI(baseURI, subscriptionID, grain)} +} + +// List list of recomendations for purchasing reserved instances. +// +// filter is may be used to filter reservationRecommendations by properties/scope and properties/lookBackPeriod. +func (client ReservationRecommendationsClient) List(ctx context.Context, filter string) (result ReservationRecommendationsListResultPage, err error) { + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, filter) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.ReservationRecommendationsClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.rrlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.ReservationRecommendationsClient", "List", resp, "Failure sending request") + return + } + + result.rrlr, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.ReservationRecommendationsClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client ReservationRecommendationsClient) ListPreparer(ctx context.Context, filter string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2018-03-31" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Consumption/reservationRecommendations", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListSender sends the List request. The method will close the +// http.Response Body if it receives an error. +func (client ReservationRecommendationsClient) ListSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + azure.DoRetryWithRegistration(client.Client)) +} + +// ListResponder handles the response to the List request. The method always +// closes the http.Response Body. +func (client ReservationRecommendationsClient) ListResponder(resp *http.Response) (result ReservationRecommendationsListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listNextResults retrieves the next set of results, if any. +func (client ReservationRecommendationsClient) listNextResults(lastResults ReservationRecommendationsListResult) (result ReservationRecommendationsListResult, err error) { + req, err := lastResults.reservationRecommendationsListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "consumption.ReservationRecommendationsClient", "listNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "consumption.ReservationRecommendationsClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.ReservationRecommendationsClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client ReservationRecommendationsClient) ListComplete(ctx context.Context, filter string) (result ReservationRecommendationsListResultIterator, err error) { + result.page, err = client.List(ctx, filter) + return +} diff --git a/services/consumption/mgmt/2018-03-31/consumption/usagedetails.go b/services/consumption/mgmt/2018-03-31/consumption/usagedetails.go index af0d6642d748..28e58f195a4e 100644 --- a/services/consumption/mgmt/2018-03-31/consumption/usagedetails.go +++ b/services/consumption/mgmt/2018-03-31/consumption/usagedetails.go @@ -47,12 +47,14 @@ func NewUsageDetailsClientWithBaseURI(baseURI string, subscriptionID string, gra // expand is may be used to expand the properties/additionalProperties or properties/meterDetails within a list of // usage details. By default, these fields are not included when listing usage details. filter is may be used to // filter usageDetails by properties/usageEnd (Utc time), properties/usageStart (Utc time), -// properties/resourceGroup, properties/instanceName or properties/instanceId. The filter supports 'eq', 'lt', -// 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'. skiptoken is skiptoken is only -// used if a previous operation returned a partial result. If a previous response contains a nextLink element, the -// value of the nextLink element will include a skiptoken parameter that specifies a starting point to use for -// subsequent calls. top is may be used to limit the number of results to the most recent N usageDetails. -func (client UsageDetailsClient) List(ctx context.Context, expand string, filter string, skiptoken string, top *int32) (result UsageDetailsListResultPage, err error) { +// properties/resourceGroup, properties/instanceName, properties/instanceId or tags. The filter supports 'eq', +// 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'. Tag filter is a key value +// pair string where key and value is separated by a colon (:). skiptoken is skiptoken is only used if a previous +// operation returned a partial result. If a previous response contains a nextLink element, the value of the +// nextLink element will include a skiptoken parameter that specifies a starting point to use for subsequent calls. +// top is may be used to limit the number of results to the most recent N usageDetails. apply is oData apply +// expression to aggregatie usageDetails by tags or (tags and properties/usageStart) +func (client UsageDetailsClient) List(ctx context.Context, expand string, filter string, skiptoken string, top *int32, apply string) (result UsageDetailsListResultPage, err error) { if err := validation.Validate([]validation.Validation{ {TargetValue: top, Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, @@ -63,7 +65,7 @@ func (client UsageDetailsClient) List(ctx context.Context, expand string, filter } result.fn = client.listNextResults - req, err := client.ListPreparer(ctx, expand, filter, skiptoken, top) + req, err := client.ListPreparer(ctx, expand, filter, skiptoken, top, apply) if err != nil { err = autorest.NewErrorWithError(err, "consumption.UsageDetailsClient", "List", nil, "Failure preparing request") return @@ -85,7 +87,7 @@ func (client UsageDetailsClient) List(ctx context.Context, expand string, filter } // ListPreparer prepares the List request. -func (client UsageDetailsClient) ListPreparer(ctx context.Context, expand string, filter string, skiptoken string, top *int32) (*http.Request, error) { +func (client UsageDetailsClient) ListPreparer(ctx context.Context, expand string, filter string, skiptoken string, top *int32, apply string) (*http.Request, error) { pathParameters := map[string]interface{}{ "subscriptionId": autorest.Encode("path", client.SubscriptionID), } @@ -106,6 +108,9 @@ func (client UsageDetailsClient) ListPreparer(ctx context.Context, expand string if top != nil { queryParameters["$top"] = autorest.Encode("query", *top) } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } preparer := autorest.CreatePreparer( autorest.AsGet(), @@ -157,8 +162,8 @@ func (client UsageDetailsClient) listNextResults(lastResults UsageDetailsListRes } // ListComplete enumerates all values, automatically crossing page boundaries as required. -func (client UsageDetailsClient) ListComplete(ctx context.Context, expand string, filter string, skiptoken string, top *int32) (result UsageDetailsListResultIterator, err error) { - result.page, err = client.List(ctx, expand, filter, skiptoken, top) +func (client UsageDetailsClient) ListComplete(ctx context.Context, expand string, filter string, skiptoken string, top *int32, apply string) (result UsageDetailsListResultIterator, err error) { + result.page, err = client.List(ctx, expand, filter, skiptoken, top, apply) return } @@ -170,11 +175,13 @@ func (client UsageDetailsClient) ListComplete(ctx context.Context, expand string // usage details. filter is may be used to filter usageDetails by properties/usageEnd (Utc time), // properties/usageStart (Utc time), properties/resourceGroup, properties/instanceName or properties/instanceId. // The filter supports 'eq', 'lt', 'gt', 'le', 'ge', and 'and'. It does not currently support 'ne', 'or', or 'not'. +// Tag filter is a key value pair string where key and value is separated by a colon (:). apply is oData apply +// expression to aggregatie usageDetails by tags or (tags and properties/usageStart) for specified billing period // skiptoken is skiptoken is only used if a previous operation returned a partial result. If a previous response // contains a nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies // a starting point to use for subsequent calls. top is may be used to limit the number of results to the most // recent N usageDetails. -func (client UsageDetailsClient) ListByBillingPeriod(ctx context.Context, billingPeriodName string, expand string, filter string, skiptoken string, top *int32) (result UsageDetailsListResultPage, err error) { +func (client UsageDetailsClient) ListByBillingPeriod(ctx context.Context, billingPeriodName string, expand string, filter string, apply string, skiptoken string, top *int32) (result UsageDetailsListResultPage, err error) { if err := validation.Validate([]validation.Validation{ {TargetValue: top, Constraints: []validation.Constraint{{Target: "top", Name: validation.Null, Rule: false, @@ -185,7 +192,7 @@ func (client UsageDetailsClient) ListByBillingPeriod(ctx context.Context, billin } result.fn = client.listByBillingPeriodNextResults - req, err := client.ListByBillingPeriodPreparer(ctx, billingPeriodName, expand, filter, skiptoken, top) + req, err := client.ListByBillingPeriodPreparer(ctx, billingPeriodName, expand, filter, apply, skiptoken, top) if err != nil { err = autorest.NewErrorWithError(err, "consumption.UsageDetailsClient", "ListByBillingPeriod", nil, "Failure preparing request") return @@ -207,7 +214,7 @@ func (client UsageDetailsClient) ListByBillingPeriod(ctx context.Context, billin } // ListByBillingPeriodPreparer prepares the ListByBillingPeriod request. -func (client UsageDetailsClient) ListByBillingPeriodPreparer(ctx context.Context, billingPeriodName string, expand string, filter string, skiptoken string, top *int32) (*http.Request, error) { +func (client UsageDetailsClient) ListByBillingPeriodPreparer(ctx context.Context, billingPeriodName string, expand string, filter string, apply string, skiptoken string, top *int32) (*http.Request, error) { pathParameters := map[string]interface{}{ "billingPeriodName": autorest.Encode("path", billingPeriodName), "subscriptionId": autorest.Encode("path", client.SubscriptionID), @@ -223,6 +230,9 @@ func (client UsageDetailsClient) ListByBillingPeriodPreparer(ctx context.Context if len(filter) > 0 { queryParameters["$filter"] = autorest.Encode("query", filter) } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } if len(skiptoken) > 0 { queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken) } @@ -280,7 +290,7 @@ func (client UsageDetailsClient) listByBillingPeriodNextResults(lastResults Usag } // ListByBillingPeriodComplete enumerates all values, automatically crossing page boundaries as required. -func (client UsageDetailsClient) ListByBillingPeriodComplete(ctx context.Context, billingPeriodName string, expand string, filter string, skiptoken string, top *int32) (result UsageDetailsListResultIterator, err error) { - result.page, err = client.ListByBillingPeriod(ctx, billingPeriodName, expand, filter, skiptoken, top) +func (client UsageDetailsClient) ListByBillingPeriodComplete(ctx context.Context, billingPeriodName string, expand string, filter string, apply string, skiptoken string, top *int32) (result UsageDetailsListResultIterator, err error) { + result.page, err = client.ListByBillingPeriod(ctx, billingPeriodName, expand, filter, apply, skiptoken, top) return }