From 643f69151fef8be52be92147f313d0d73ad2e4d8 Mon Sep 17 00:00:00 2001 From: Azure SDK for Python bot Date: Tue, 7 Aug 2018 23:16:37 +0000 Subject: [PATCH] Generated from 0dc16e7f2fcf746f4c39a977d4a04c862b47dd26 Added location parameter to managementgroupId and also added Get To method name of AggregatedCost --- .../consumption/mgmt/consumption/models.go | 9 + .../2018-06-30/consumption/aggregatedcost.go | 173 ++++++++++++ .../mgmt/2018-06-30/consumption/models.go | 111 ++++++++ .../2018-06-30/consumption/usagedetails.go | 259 ++++++++++++++++++ 4 files changed, 552 insertions(+) create mode 100644 services/consumption/mgmt/2018-06-30/consumption/aggregatedcost.go diff --git a/profiles/preview/consumption/mgmt/consumption/models.go b/profiles/preview/consumption/mgmt/consumption/models.go index b61b98361ba9..887121daae5f 100644 --- a/profiles/preview/consumption/mgmt/consumption/models.go +++ b/profiles/preview/consumption/mgmt/consumption/models.go @@ -21,6 +21,7 @@ package consumption import original "github.com/Azure/azure-sdk-for-go/services/consumption/mgmt/2018-06-30/consumption" +type AggregatedCostClient = original.AggregatedCostClient type BalancesClient = original.BalancesClient type BudgetsClient = original.BudgetsClient @@ -113,6 +114,8 @@ type Forecast = original.Forecast type ForecastProperties = original.ForecastProperties type ForecastPropertiesConfidenceLevelsItem = original.ForecastPropertiesConfidenceLevelsItem type ForecastsListResult = original.ForecastsListResult +type ManagementGroupAggregatedCostProperties = original.ManagementGroupAggregatedCostProperties +type ManagementGroupAggregatedCostResult = original.ManagementGroupAggregatedCostResult type Marketplace = original.Marketplace type MarketplaceProperties = original.MarketplaceProperties type MarketplacesListResult = original.MarketplacesListResult @@ -162,6 +165,12 @@ type ReservationsSummariesClient = original.ReservationsSummariesClient type TagsClient = original.TagsClient type UsageDetailsClient = original.UsageDetailsClient +func NewAggregatedCostClient(subscriptionID string) AggregatedCostClient { + return original.NewAggregatedCostClient(subscriptionID) +} +func NewAggregatedCostClientWithBaseURI(baseURI string, subscriptionID string) AggregatedCostClient { + return original.NewAggregatedCostClientWithBaseURI(baseURI, subscriptionID) +} func NewBalancesClient(subscriptionID string) BalancesClient { return original.NewBalancesClient(subscriptionID) } diff --git a/services/consumption/mgmt/2018-06-30/consumption/aggregatedcost.go b/services/consumption/mgmt/2018-06-30/consumption/aggregatedcost.go new file mode 100644 index 000000000000..916ca1df1056 --- /dev/null +++ b/services/consumption/mgmt/2018-06-30/consumption/aggregatedcost.go @@ -0,0 +1,173 @@ +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" +) + +// AggregatedCostClient is the consumption management client provides access to consumption resources for Azure +// Enterprise Subscriptions. +type AggregatedCostClient struct { + BaseClient +} + +// NewAggregatedCostClient creates an instance of the AggregatedCostClient client. +func NewAggregatedCostClient(subscriptionID string) AggregatedCostClient { + return NewAggregatedCostClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewAggregatedCostClientWithBaseURI creates an instance of the AggregatedCostClient client. +func NewAggregatedCostClientWithBaseURI(baseURI string, subscriptionID string) AggregatedCostClient { + return AggregatedCostClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// GetByManagementGroup provides the aggregate cost of a management group and all child management groups by current +// billing period. +// Parameters: +// managementGroupID - azure Management Group ID. +func (client AggregatedCostClient) GetByManagementGroup(ctx context.Context, managementGroupID string) (result ManagementGroupAggregatedCostResult, err error) { + req, err := client.GetByManagementGroupPreparer(ctx, managementGroupID) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.AggregatedCostClient", "GetByManagementGroup", nil, "Failure preparing request") + return + } + + resp, err := client.GetByManagementGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.AggregatedCostClient", "GetByManagementGroup", resp, "Failure sending request") + return + } + + result, err = client.GetByManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.AggregatedCostClient", "GetByManagementGroup", resp, "Failure responding to request") + } + + return +} + +// GetByManagementGroupPreparer prepares the GetByManagementGroup request. +func (client AggregatedCostClient) GetByManagementGroupPreparer(ctx context.Context, managementGroupID string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "managementGroupId": autorest.Encode("path", managementGroupID), + } + + const APIVersion = "2018-06-30" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Consumption/aggregatedcost", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetByManagementGroupSender sends the GetByManagementGroup request. The method will close the +// http.Response Body if it receives an error. +func (client AggregatedCostClient) GetByManagementGroupSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetByManagementGroupResponder handles the response to the GetByManagementGroup request. The method always +// closes the http.Response Body. +func (client AggregatedCostClient) GetByManagementGroupResponder(resp *http.Response) (result ManagementGroupAggregatedCostResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// GetForBillingPeriodByManagementGroup provides the aggregate cost of a management group and all child management +// groups by specified billing period +// Parameters: +// managementGroupID - azure Management Group ID. +// billingPeriodName - billing Period Name. +func (client AggregatedCostClient) GetForBillingPeriodByManagementGroup(ctx context.Context, managementGroupID string, billingPeriodName string) (result ManagementGroupAggregatedCostResult, err error) { + req, err := client.GetForBillingPeriodByManagementGroupPreparer(ctx, managementGroupID, billingPeriodName) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.AggregatedCostClient", "GetForBillingPeriodByManagementGroup", nil, "Failure preparing request") + return + } + + resp, err := client.GetForBillingPeriodByManagementGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.AggregatedCostClient", "GetForBillingPeriodByManagementGroup", resp, "Failure sending request") + return + } + + result, err = client.GetForBillingPeriodByManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.AggregatedCostClient", "GetForBillingPeriodByManagementGroup", resp, "Failure responding to request") + } + + return +} + +// GetForBillingPeriodByManagementGroupPreparer prepares the GetForBillingPeriodByManagementGroup request. +func (client AggregatedCostClient) GetForBillingPeriodByManagementGroupPreparer(ctx context.Context, managementGroupID string, billingPeriodName string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "billingPeriodName": autorest.Encode("path", billingPeriodName), + "managementGroupId": autorest.Encode("path", managementGroupID), + } + + const APIVersion = "2018-06-30" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}/Microsoft.Consumption/aggregatedcost", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// GetForBillingPeriodByManagementGroupSender sends the GetForBillingPeriodByManagementGroup request. The method will close the +// http.Response Body if it receives an error. +func (client AggregatedCostClient) GetForBillingPeriodByManagementGroupSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// GetForBillingPeriodByManagementGroupResponder handles the response to the GetForBillingPeriodByManagementGroup request. The method always +// closes the http.Response Body. +func (client AggregatedCostClient) GetForBillingPeriodByManagementGroupResponder(resp *http.Response) (result ManagementGroupAggregatedCostResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} diff --git a/services/consumption/mgmt/2018-06-30/consumption/models.go b/services/consumption/mgmt/2018-06-30/consumption/models.go index 6dc23f97a07d..b956b3f4b489 100644 --- a/services/consumption/mgmt/2018-06-30/consumption/models.go +++ b/services/consumption/mgmt/2018-06-30/consumption/models.go @@ -837,6 +837,117 @@ type ForecastsListResult struct { Value *[]Forecast `json:"value,omitempty"` } +// ManagementGroupAggregatedCostProperties the properties of the Management Group Aggregated Cost. +type ManagementGroupAggregatedCostProperties struct { + // BillingPeriodID - The id of the billing period resource that the aggregated cost belongs to. + BillingPeriodID *string `json:"billingPeriodId,omitempty"` + // AzureCharges - Azure Charges. + AzureCharges *decimal.Decimal `json:"azureCharges,omitempty"` + // MarketplaceCharges - Marketplace Charges. + MarketplaceCharges *decimal.Decimal `json:"marketplaceCharges,omitempty"` + // ChargesBilledSeparately - Charges Billed Separately. + ChargesBilledSeparately *decimal.Decimal `json:"chargesBilledSeparately,omitempty"` + // Currency - The ISO currency in which the meter is charged, for example, USD. + Currency *string `json:"currency,omitempty"` + // Children - Children of a management group + Children *[]ManagementGroupAggregatedCostResult `json:"children,omitempty"` +} + +// ManagementGroupAggregatedCostResult a management group aggregated cost resource. +type ManagementGroupAggregatedCostResult struct { + autorest.Response `json:"-"` + *ManagementGroupAggregatedCostProperties `json:"properties,omitempty"` + // 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"` +} + +// MarshalJSON is the custom marshaler for ManagementGroupAggregatedCostResult. +func (mgacr ManagementGroupAggregatedCostResult) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if mgacr.ManagementGroupAggregatedCostProperties != nil { + objectMap["properties"] = mgacr.ManagementGroupAggregatedCostProperties + } + if mgacr.ID != nil { + objectMap["id"] = mgacr.ID + } + if mgacr.Name != nil { + objectMap["name"] = mgacr.Name + } + if mgacr.Type != nil { + objectMap["type"] = mgacr.Type + } + if mgacr.Tags != nil { + objectMap["tags"] = mgacr.Tags + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for ManagementGroupAggregatedCostResult struct. +func (mgacr *ManagementGroupAggregatedCostResult) 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 "properties": + if v != nil { + var managementGroupAggregatedCostProperties ManagementGroupAggregatedCostProperties + err = json.Unmarshal(*v, &managementGroupAggregatedCostProperties) + if err != nil { + return err + } + mgacr.ManagementGroupAggregatedCostProperties = &managementGroupAggregatedCostProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + mgacr.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + mgacr.Name = &name + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + mgacr.Type = &typeVar + } + case "tags": + if v != nil { + var tags map[string]*string + err = json.Unmarshal(*v, &tags) + if err != nil { + return err + } + mgacr.Tags = tags + } + } + } + + return nil +} + // Marketplace an marketplace resource. type Marketplace struct { *MarketplaceProperties `json:"properties,omitempty"` diff --git a/services/consumption/mgmt/2018-06-30/consumption/usagedetails.go b/services/consumption/mgmt/2018-06-30/consumption/usagedetails.go index 78d08ac932aa..2bc86b7d3d67 100644 --- a/services/consumption/mgmt/2018-06-30/consumption/usagedetails.go +++ b/services/consumption/mgmt/2018-06-30/consumption/usagedetails.go @@ -682,6 +682,134 @@ func (client UsageDetailsClient) ListByEnrollmentAccountComplete(ctx context.Con return } +// ListByManagementGroup lists the usage detail records for all subscriptions belonging to a management group scope by +// current billing period. Usage details are available via this API only for May 1, 2014 or later. +// Parameters: +// managementGroupID - azure Management Group ID. +// expand - 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 - may be used to filter usageDetails by properties/usageEnd (Utc time), properties/usageStart (Utc +// time), 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 - 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 - may be used to limit the number of results to the most recent N usageDetails. +// apply - oData apply expression to aggregate usageDetails by tags or (tags and properties/usageStart) +func (client UsageDetailsClient) ListByManagementGroup(ctx context.Context, managementGroupID string, 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, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil}, + {Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("consumption.UsageDetailsClient", "ListByManagementGroup", err.Error()) + } + + result.fn = client.listByManagementGroupNextResults + req, err := client.ListByManagementGroupPreparer(ctx, managementGroupID, expand, filter, skiptoken, top, apply) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsClient", "ListByManagementGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListByManagementGroupSender(req) + if err != nil { + result.udlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsClient", "ListByManagementGroup", resp, "Failure sending request") + return + } + + result.udlr, err = client.ListByManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsClient", "ListByManagementGroup", resp, "Failure responding to request") + } + + return +} + +// ListByManagementGroupPreparer prepares the ListByManagementGroup request. +func (client UsageDetailsClient) ListByManagementGroupPreparer(ctx context.Context, managementGroupID string, expand string, filter string, skiptoken string, top *int32, apply string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "managementGroupId": autorest.Encode("path", managementGroupID), + } + + const APIVersion = "2018-06-30" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(expand) > 0 { + queryParameters["$expand"] = autorest.Encode("query", expand) + } + if len(filter) > 0 { + queryParameters["$filter"] = autorest.Encode("query", filter) + } + if len(skiptoken) > 0 { + queryParameters["$skiptoken"] = autorest.Encode("query", skiptoken) + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + if len(apply) > 0 { + queryParameters["$apply"] = autorest.Encode("query", apply) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Consumption/usageDetails", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListByManagementGroupSender sends the ListByManagementGroup request. The method will close the +// http.Response Body if it receives an error. +func (client UsageDetailsClient) ListByManagementGroupSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListByManagementGroupResponder handles the response to the ListByManagementGroup request. The method always +// closes the http.Response Body. +func (client UsageDetailsClient) ListByManagementGroupResponder(resp *http.Response) (result UsageDetailsListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listByManagementGroupNextResults retrieves the next set of results, if any. +func (client UsageDetailsClient) listByManagementGroupNextResults(lastResults UsageDetailsListResult) (result UsageDetailsListResult, err error) { + req, err := lastResults.usageDetailsListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "consumption.UsageDetailsClient", "listByManagementGroupNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListByManagementGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "consumption.UsageDetailsClient", "listByManagementGroupNextResults", resp, "Failure sending next results request") + } + result, err = client.ListByManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsClient", "listByManagementGroupNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListByManagementGroupComplete enumerates all values, automatically crossing page boundaries as required. +func (client UsageDetailsClient) ListByManagementGroupComplete(ctx context.Context, managementGroupID string, expand string, filter string, skiptoken string, top *int32, apply string) (result UsageDetailsListResultIterator, err error) { + result.page, err = client.ListByManagementGroup(ctx, managementGroupID, expand, filter, skiptoken, top, apply) + return +} + // ListForBillingPeriodByBillingAccount lists the usage details based on billingAccountId for a scope by billing // period. Usage details are available via this API only for May 1, 2014 or later. // Parameters: @@ -1074,3 +1202,134 @@ func (client UsageDetailsClient) ListForBillingPeriodByEnrollmentAccountComplete result.page, err = client.ListForBillingPeriodByEnrollmentAccount(ctx, enrollmentAccountID, billingPeriodName, expand, filter, apply, skiptoken, top) return } + +// ListForBillingPeriodByManagementGroup lists the usage detail records for all subscriptions belonging to a management +// group scope by specified billing period. Usage details are available via this API only for May 1, 2014 or later. +// Parameters: +// managementGroupID - azure Management Group ID. +// billingPeriodName - billing Period Name. +// expand - 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 - 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 - oData apply expression to aggregate usageDetails by tags or (tags and properties/usageStart) for +// specified billing period +// skiptoken - 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 - may be used to limit the number of results to the most recent N usageDetails. +func (client UsageDetailsClient) ListForBillingPeriodByManagementGroup(ctx context.Context, managementGroupID string, 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, + Chain: []validation.Constraint{{Target: "top", Name: validation.InclusiveMaximum, Rule: int64(1000), Chain: nil}, + {Target: "top", Name: validation.InclusiveMinimum, Rule: 1, Chain: nil}, + }}}}}); err != nil { + return result, validation.NewError("consumption.UsageDetailsClient", "ListForBillingPeriodByManagementGroup", err.Error()) + } + + result.fn = client.listForBillingPeriodByManagementGroupNextResults + req, err := client.ListForBillingPeriodByManagementGroupPreparer(ctx, managementGroupID, billingPeriodName, expand, filter, apply, skiptoken, top) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsClient", "ListForBillingPeriodByManagementGroup", nil, "Failure preparing request") + return + } + + resp, err := client.ListForBillingPeriodByManagementGroupSender(req) + if err != nil { + result.udlr.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsClient", "ListForBillingPeriodByManagementGroup", resp, "Failure sending request") + return + } + + result.udlr, err = client.ListForBillingPeriodByManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsClient", "ListForBillingPeriodByManagementGroup", resp, "Failure responding to request") + } + + return +} + +// ListForBillingPeriodByManagementGroupPreparer prepares the ListForBillingPeriodByManagementGroup request. +func (client UsageDetailsClient) ListForBillingPeriodByManagementGroupPreparer(ctx context.Context, managementGroupID string, billingPeriodName string, expand string, filter string, apply string, skiptoken string, top *int32) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "billingPeriodName": autorest.Encode("path", billingPeriodName), + "managementGroupId": autorest.Encode("path", managementGroupID), + } + + const APIVersion = "2018-06-30" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(expand) > 0 { + queryParameters["$expand"] = autorest.Encode("query", expand) + } + 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) + } + if top != nil { + queryParameters["$top"] = autorest.Encode("query", *top) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Billing/billingPeriods/{billingPeriodName}/providers/Microsoft.Consumption/usageDetails", pathParameters), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// ListForBillingPeriodByManagementGroupSender sends the ListForBillingPeriodByManagementGroup request. The method will close the +// http.Response Body if it receives an error. +func (client UsageDetailsClient) ListForBillingPeriodByManagementGroupSender(req *http.Request) (*http.Response, error) { + return autorest.SendWithSender(client, req, + autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) +} + +// ListForBillingPeriodByManagementGroupResponder handles the response to the ListForBillingPeriodByManagementGroup request. The method always +// closes the http.Response Body. +func (client UsageDetailsClient) ListForBillingPeriodByManagementGroupResponder(resp *http.Response) (result UsageDetailsListResult, err error) { + err = autorest.Respond( + resp, + client.ByInspecting(), + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result), + autorest.ByClosing()) + result.Response = autorest.Response{Response: resp} + return +} + +// listForBillingPeriodByManagementGroupNextResults retrieves the next set of results, if any. +func (client UsageDetailsClient) listForBillingPeriodByManagementGroupNextResults(lastResults UsageDetailsListResult) (result UsageDetailsListResult, err error) { + req, err := lastResults.usageDetailsListResultPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "consumption.UsageDetailsClient", "listForBillingPeriodByManagementGroupNextResults", nil, "Failure preparing next results request") + } + if req == nil { + return + } + resp, err := client.ListForBillingPeriodByManagementGroupSender(req) + if err != nil { + result.Response = autorest.Response{Response: resp} + return result, autorest.NewErrorWithError(err, "consumption.UsageDetailsClient", "listForBillingPeriodByManagementGroupNextResults", resp, "Failure sending next results request") + } + result, err = client.ListForBillingPeriodByManagementGroupResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "consumption.UsageDetailsClient", "listForBillingPeriodByManagementGroupNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListForBillingPeriodByManagementGroupComplete enumerates all values, automatically crossing page boundaries as required. +func (client UsageDetailsClient) ListForBillingPeriodByManagementGroupComplete(ctx context.Context, managementGroupID string, billingPeriodName string, expand string, filter string, apply string, skiptoken string, top *int32) (result UsageDetailsListResultIterator, err error) { + result.page, err = client.ListForBillingPeriodByManagementGroup(ctx, managementGroupID, billingPeriodName, expand, filter, apply, skiptoken, top) + return +}