From ab4c5867a89e853cd2d4e2ef30a0940df7ddbf4e Mon Sep 17 00:00:00 2001 From: Azure SDK for Python bot Date: Thu, 29 Mar 2018 18:18:16 -0700 Subject: [PATCH] [AutoPR web/resource-manager] Adding BillingMeters API (#1423) * Generated from 2c9ced71b2b53f7039ec9ddbcbe4f23f05897e89 Adding reference to readme.md * Generated from 1723dbe3e971a273cd0d143700e69c20912f9bce Merge branch 'master' of https://github.com/andreyse/azure-rest-api-specs * Generated from 1723dbe3e971a273cd0d143700e69c20912f9bce Merge branch 'master' of https://github.com/andreyse/azure-rest-api-specs --- .../web/mgmt/2016-09-01/web/billingmeters.go | 135 +++++++++++ services/web/mgmt/2016-09-01/web/models.go | 212 ++++++++++++++++++ 2 files changed, 347 insertions(+) create mode 100644 services/web/mgmt/2016-09-01/web/billingmeters.go diff --git a/services/web/mgmt/2016-09-01/web/billingmeters.go b/services/web/mgmt/2016-09-01/web/billingmeters.go new file mode 100644 index 000000000000..c1043768b341 --- /dev/null +++ b/services/web/mgmt/2016-09-01/web/billingmeters.go @@ -0,0 +1,135 @@ +package web + +// 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" +) + +// BillingMetersClient is the webSite Management Client +type BillingMetersClient struct { + BaseClient +} + +// NewBillingMetersClient creates an instance of the BillingMetersClient client. +func NewBillingMetersClient(subscriptionID string) BillingMetersClient { + return NewBillingMetersClientWithBaseURI(DefaultBaseURI, subscriptionID) +} + +// NewBillingMetersClientWithBaseURI creates an instance of the BillingMetersClient client. +func NewBillingMetersClientWithBaseURI(baseURI string, subscriptionID string) BillingMetersClient { + return BillingMetersClient{NewWithBaseURI(baseURI, subscriptionID)} +} + +// List gets a list of meters for a given location. +// +// billingLocation is azure Location of billable resource +func (client BillingMetersClient) List(ctx context.Context, billingLocation string) (result BillingMeterCollectionPage, err error) { + result.fn = client.listNextResults + req, err := client.ListPreparer(ctx, billingLocation) + if err != nil { + err = autorest.NewErrorWithError(err, "web.BillingMetersClient", "List", nil, "Failure preparing request") + return + } + + resp, err := client.ListSender(req) + if err != nil { + result.bmc.Response = autorest.Response{Response: resp} + err = autorest.NewErrorWithError(err, "web.BillingMetersClient", "List", resp, "Failure sending request") + return + } + + result.bmc, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "web.BillingMetersClient", "List", resp, "Failure responding to request") + } + + return +} + +// ListPreparer prepares the List request. +func (client BillingMetersClient) ListPreparer(ctx context.Context, billingLocation string) (*http.Request, error) { + pathParameters := map[string]interface{}{ + "subscriptionId": autorest.Encode("path", client.SubscriptionID), + } + + const APIVersion = "2016-03-01" + queryParameters := map[string]interface{}{ + "api-version": APIVersion, + } + if len(billingLocation) > 0 { + queryParameters["billingLocation"] = autorest.Encode("query", billingLocation) + } + + preparer := autorest.CreatePreparer( + autorest.AsGet(), + autorest.WithBaseURL(client.BaseURI), + autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Web/billingMeters", 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 BillingMetersClient) 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 BillingMetersClient) ListResponder(resp *http.Response) (result BillingMeterCollection, 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 BillingMetersClient) listNextResults(lastResults BillingMeterCollection) (result BillingMeterCollection, err error) { + req, err := lastResults.billingMeterCollectionPreparer() + if err != nil { + return result, autorest.NewErrorWithError(err, "web.BillingMetersClient", "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, "web.BillingMetersClient", "listNextResults", resp, "Failure sending next results request") + } + result, err = client.ListResponder(resp) + if err != nil { + err = autorest.NewErrorWithError(err, "web.BillingMetersClient", "listNextResults", resp, "Failure responding to next results request") + } + return +} + +// ListComplete enumerates all values, automatically crossing page boundaries as required. +func (client BillingMetersClient) ListComplete(ctx context.Context, billingLocation string) (result BillingMeterCollectionIterator, err error) { + result.page, err = client.List(ctx, billingLocation) + return +} diff --git a/services/web/mgmt/2016-09-01/web/models.go b/services/web/mgmt/2016-09-01/web/models.go index f92303797b48..38fbf5c47b04 100644 --- a/services/web/mgmt/2016-09-01/web/models.go +++ b/services/web/mgmt/2016-09-01/web/models.go @@ -5408,6 +5408,218 @@ type BackupSchedule struct { LastExecutionTime *date.Time `json:"lastExecutionTime,omitempty"` } +// BillingMeter app Service billing entity that contains information about meter which the Azure billing system +// utilizes to charge users for services. +type BillingMeter struct { + // BillingMeterProperties - BillingMeter resource specific properties + *BillingMeterProperties `json:"properties,omitempty"` + // ID - Resource Id. + ID *string `json:"id,omitempty"` + // Name - Resource Name. + Name *string `json:"name,omitempty"` + // Kind - Kind of resource. + Kind *string `json:"kind,omitempty"` + // Type - Resource type. + Type *string `json:"type,omitempty"` +} + +// MarshalJSON is the custom marshaler for BillingMeter. +func (bm BillingMeter) MarshalJSON() ([]byte, error) { + objectMap := make(map[string]interface{}) + if bm.BillingMeterProperties != nil { + objectMap["properties"] = bm.BillingMeterProperties + } + if bm.ID != nil { + objectMap["id"] = bm.ID + } + if bm.Name != nil { + objectMap["name"] = bm.Name + } + if bm.Kind != nil { + objectMap["kind"] = bm.Kind + } + if bm.Type != nil { + objectMap["type"] = bm.Type + } + return json.Marshal(objectMap) +} + +// UnmarshalJSON is the custom unmarshaler for BillingMeter struct. +func (bm *BillingMeter) 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 billingMeterProperties BillingMeterProperties + err = json.Unmarshal(*v, &billingMeterProperties) + if err != nil { + return err + } + bm.BillingMeterProperties = &billingMeterProperties + } + case "id": + if v != nil { + var ID string + err = json.Unmarshal(*v, &ID) + if err != nil { + return err + } + bm.ID = &ID + } + case "name": + if v != nil { + var name string + err = json.Unmarshal(*v, &name) + if err != nil { + return err + } + bm.Name = &name + } + case "kind": + if v != nil { + var kind string + err = json.Unmarshal(*v, &kind) + if err != nil { + return err + } + bm.Kind = &kind + } + case "type": + if v != nil { + var typeVar string + err = json.Unmarshal(*v, &typeVar) + if err != nil { + return err + } + bm.Type = &typeVar + } + } + } + + return nil +} + +// BillingMeterCollection collection of Billing Meters +type BillingMeterCollection struct { + autorest.Response `json:"-"` + // Value - Collection of Billing Meters. + Value *[]BillingMeter `json:"value,omitempty"` + // NextLink - Link to next page of resources. + NextLink *string `json:"nextLink,omitempty"` +} + +// BillingMeterCollectionIterator provides access to a complete listing of BillingMeter values. +type BillingMeterCollectionIterator struct { + i int + page BillingMeterCollectionPage +} + +// 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 *BillingMeterCollectionIterator) 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 BillingMeterCollectionIterator) 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 BillingMeterCollectionIterator) Response() BillingMeterCollection { + 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 BillingMeterCollectionIterator) Value() BillingMeter { + if !iter.page.NotDone() { + return BillingMeter{} + } + return iter.page.Values()[iter.i] +} + +// IsEmpty returns true if the ListResult contains no values. +func (bmc BillingMeterCollection) IsEmpty() bool { + return bmc.Value == nil || len(*bmc.Value) == 0 +} + +// billingMeterCollectionPreparer prepares a request to retrieve the next set of results. +// It returns nil if no more results exist. +func (bmc BillingMeterCollection) billingMeterCollectionPreparer() (*http.Request, error) { + if bmc.NextLink == nil || len(to.String(bmc.NextLink)) < 1 { + return nil, nil + } + return autorest.Prepare(&http.Request{}, + autorest.AsJSON(), + autorest.AsGet(), + autorest.WithBaseURL(to.String(bmc.NextLink))) +} + +// BillingMeterCollectionPage contains a page of BillingMeter values. +type BillingMeterCollectionPage struct { + fn func(BillingMeterCollection) (BillingMeterCollection, error) + bmc BillingMeterCollection +} + +// 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 *BillingMeterCollectionPage) Next() error { + next, err := page.fn(page.bmc) + if err != nil { + return err + } + page.bmc = next + return nil +} + +// NotDone returns true if the page enumeration should be started or is not yet complete. +func (page BillingMeterCollectionPage) NotDone() bool { + return !page.bmc.IsEmpty() +} + +// Response returns the raw server response from the last page request. +func (page BillingMeterCollectionPage) Response() BillingMeterCollection { + return page.bmc +} + +// Values returns the slice of values for the current page or nil if there are no values. +func (page BillingMeterCollectionPage) Values() []BillingMeter { + if page.bmc.IsEmpty() { + return nil + } + return *page.bmc.Value +} + +// BillingMeterProperties billingMeter resource specific properties +type BillingMeterProperties struct { + // MeterID - Meter GUID onboarded in Commerce + MeterID *string `json:"meterId,omitempty"` + // BillingLocation - Azure Location of billable resource + BillingLocation *string `json:"billingLocation,omitempty"` + // ShortName - Short Name from App Service Azure pricing Page + ShortName *string `json:"shortName,omitempty"` + // FriendlyName - Friendly name of the meter + FriendlyName *string `json:"friendlyName,omitempty"` + // ResourceType - App Service resource type meter used for + ResourceType *string `json:"resourceType,omitempty"` +} + // Capability describes the capabilities/features allowed for a specific SKU. type Capability struct { // Name - Name of the SKU capability.