|
Packit Service |
4d2de5 |
package network
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
// Copyright (c) Microsoft and contributors. All rights reserved.
|
|
Packit Service |
4d2de5 |
//
|
|
Packit Service |
4d2de5 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
Packit Service |
4d2de5 |
// you may not use this file except in compliance with the License.
|
|
Packit Service |
4d2de5 |
// You may obtain a copy of the License at
|
|
Packit Service |
4d2de5 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit Service |
4d2de5 |
//
|
|
Packit Service |
4d2de5 |
// Unless required by applicable law or agreed to in writing, software
|
|
Packit Service |
4d2de5 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit Service |
4d2de5 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit Service |
4d2de5 |
//
|
|
Packit Service |
4d2de5 |
// See the License for the specific language governing permissions and
|
|
Packit Service |
4d2de5 |
// limitations under the License.
|
|
Packit Service |
4d2de5 |
//
|
|
Packit Service |
4d2de5 |
// Code generated by Microsoft (R) AutoRest Code Generator.
|
|
Packit Service |
4d2de5 |
// Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
import (
|
|
Packit Service |
4d2de5 |
"context"
|
|
Packit Service |
4d2de5 |
"github.com/Azure/go-autorest/autorest"
|
|
Packit Service |
4d2de5 |
"github.com/Azure/go-autorest/autorest/azure"
|
|
Packit Service |
4d2de5 |
"github.com/Azure/go-autorest/autorest/validation"
|
|
Packit Service |
4d2de5 |
"github.com/Azure/go-autorest/tracing"
|
|
Packit Service |
4d2de5 |
"net/http"
|
|
Packit Service |
4d2de5 |
)
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
// UsagesClient is the network Client
|
|
Packit Service |
4d2de5 |
type UsagesClient struct {
|
|
Packit Service |
4d2de5 |
BaseClient
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
// NewUsagesClient creates an instance of the UsagesClient client.
|
|
Packit Service |
4d2de5 |
func NewUsagesClient(subscriptionID string) UsagesClient {
|
|
Packit Service |
4d2de5 |
return NewUsagesClientWithBaseURI(DefaultBaseURI, subscriptionID)
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
// NewUsagesClientWithBaseURI creates an instance of the UsagesClient client using a custom endpoint. Use this when
|
|
Packit Service |
4d2de5 |
// interacting with an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack).
|
|
Packit Service |
4d2de5 |
func NewUsagesClientWithBaseURI(baseURI string, subscriptionID string) UsagesClient {
|
|
Packit Service |
4d2de5 |
return UsagesClient{NewWithBaseURI(baseURI, subscriptionID)}
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
// List list network usages for a subscription.
|
|
Packit Service |
4d2de5 |
// Parameters:
|
|
Packit Service |
4d2de5 |
// location - the location where resource usage is queried.
|
|
Packit Service |
4d2de5 |
func (client UsagesClient) List(ctx context.Context, location string) (result UsagesListResultPage, err error) {
|
|
Packit Service |
4d2de5 |
if tracing.IsEnabled() {
|
|
Packit Service |
4d2de5 |
ctx = tracing.StartSpan(ctx, fqdn+"/UsagesClient.List")
|
|
Packit Service |
4d2de5 |
defer func() {
|
|
Packit Service |
4d2de5 |
sc := -1
|
|
Packit Service |
4d2de5 |
if result.ulr.Response.Response != nil {
|
|
Packit Service |
4d2de5 |
sc = result.ulr.Response.Response.StatusCode
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
tracing.EndSpan(ctx, sc, err)
|
|
Packit Service |
4d2de5 |
}()
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
if err := validation.Validate([]validation.Validation{
|
|
Packit Service |
4d2de5 |
{TargetValue: location,
|
|
Packit Service |
4d2de5 |
Constraints: []validation.Constraint{{Target: "location", Name: validation.Pattern, Rule: `^[-\w\._ ]+$`, Chain: nil}}}}); err != nil {
|
|
Packit Service |
4d2de5 |
return result, validation.NewError("network.UsagesClient", "List", err.Error())
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
result.fn = client.listNextResults
|
|
Packit Service |
4d2de5 |
req, err := client.ListPreparer(ctx, location)
|
|
Packit Service |
4d2de5 |
if err != nil {
|
|
Packit Service |
4d2de5 |
err = autorest.NewErrorWithError(err, "network.UsagesClient", "List", nil, "Failure preparing request")
|
|
Packit Service |
4d2de5 |
return
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
resp, err := client.ListSender(req)
|
|
Packit Service |
4d2de5 |
if err != nil {
|
|
Packit Service |
4d2de5 |
result.ulr.Response = autorest.Response{Response: resp}
|
|
Packit Service |
4d2de5 |
err = autorest.NewErrorWithError(err, "network.UsagesClient", "List", resp, "Failure sending request")
|
|
Packit Service |
4d2de5 |
return
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
result.ulr, err = client.ListResponder(resp)
|
|
Packit Service |
4d2de5 |
if err != nil {
|
|
Packit Service |
4d2de5 |
err = autorest.NewErrorWithError(err, "network.UsagesClient", "List", resp, "Failure responding to request")
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
return
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
// ListPreparer prepares the List request.
|
|
Packit Service |
4d2de5 |
func (client UsagesClient) ListPreparer(ctx context.Context, location string) (*http.Request, error) {
|
|
Packit Service |
4d2de5 |
pathParameters := map[string]interface{}{
|
|
Packit Service |
4d2de5 |
"location": autorest.Encode("path", location),
|
|
Packit Service |
4d2de5 |
"subscriptionId": autorest.Encode("path", client.SubscriptionID),
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
const APIVersion = "2019-09-01"
|
|
Packit Service |
4d2de5 |
queryParameters := map[string]interface{}{
|
|
Packit Service |
4d2de5 |
"api-version": APIVersion,
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
preparer := autorest.CreatePreparer(
|
|
Packit Service |
4d2de5 |
autorest.AsGet(),
|
|
Packit Service |
4d2de5 |
autorest.WithBaseURL(client.BaseURI),
|
|
Packit Service |
4d2de5 |
autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/locations/{location}/usages", pathParameters),
|
|
Packit Service |
4d2de5 |
autorest.WithQueryParameters(queryParameters))
|
|
Packit Service |
4d2de5 |
return preparer.Prepare((&http.Request{}).WithContext(ctx))
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
// ListSender sends the List request. The method will close the
|
|
Packit Service |
4d2de5 |
// http.Response Body if it receives an error.
|
|
Packit Service |
4d2de5 |
func (client UsagesClient) ListSender(req *http.Request) (*http.Response, error) {
|
|
Packit Service |
4d2de5 |
return client.Send(req, azure.DoRetryWithRegistration(client.Client))
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
// ListResponder handles the response to the List request. The method always
|
|
Packit Service |
4d2de5 |
// closes the http.Response Body.
|
|
Packit Service |
4d2de5 |
func (client UsagesClient) ListResponder(resp *http.Response) (result UsagesListResult, err error) {
|
|
Packit Service |
4d2de5 |
err = autorest.Respond(
|
|
Packit Service |
4d2de5 |
resp,
|
|
Packit Service |
4d2de5 |
client.ByInspecting(),
|
|
Packit Service |
4d2de5 |
azure.WithErrorUnlessStatusCode(http.StatusOK),
|
|
Packit Service |
4d2de5 |
autorest.ByUnmarshallingJSON(&result),
|
|
Packit Service |
4d2de5 |
autorest.ByClosing())
|
|
Packit Service |
4d2de5 |
result.Response = autorest.Response{Response: resp}
|
|
Packit Service |
4d2de5 |
return
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
// listNextResults retrieves the next set of results, if any.
|
|
Packit Service |
4d2de5 |
func (client UsagesClient) listNextResults(ctx context.Context, lastResults UsagesListResult) (result UsagesListResult, err error) {
|
|
Packit Service |
4d2de5 |
req, err := lastResults.usagesListResultPreparer(ctx)
|
|
Packit Service |
4d2de5 |
if err != nil {
|
|
Packit Service |
4d2de5 |
return result, autorest.NewErrorWithError(err, "network.UsagesClient", "listNextResults", nil, "Failure preparing next results request")
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
if req == nil {
|
|
Packit Service |
4d2de5 |
return
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
resp, err := client.ListSender(req)
|
|
Packit Service |
4d2de5 |
if err != nil {
|
|
Packit Service |
4d2de5 |
result.Response = autorest.Response{Response: resp}
|
|
Packit Service |
4d2de5 |
return result, autorest.NewErrorWithError(err, "network.UsagesClient", "listNextResults", resp, "Failure sending next results request")
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
result, err = client.ListResponder(resp)
|
|
Packit Service |
4d2de5 |
if err != nil {
|
|
Packit Service |
4d2de5 |
err = autorest.NewErrorWithError(err, "network.UsagesClient", "listNextResults", resp, "Failure responding to next results request")
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
return
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
|
|
Packit Service |
4d2de5 |
// ListComplete enumerates all values, automatically crossing page boundaries as required.
|
|
Packit Service |
4d2de5 |
func (client UsagesClient) ListComplete(ctx context.Context, location string) (result UsagesListResultIterator, err error) {
|
|
Packit Service |
4d2de5 |
if tracing.IsEnabled() {
|
|
Packit Service |
4d2de5 |
ctx = tracing.StartSpan(ctx, fqdn+"/UsagesClient.List")
|
|
Packit Service |
4d2de5 |
defer func() {
|
|
Packit Service |
4d2de5 |
sc := -1
|
|
Packit Service |
4d2de5 |
if result.Response().Response.Response != nil {
|
|
Packit Service |
4d2de5 |
sc = result.page.Response().Response.Response.StatusCode
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
tracing.EndSpan(ctx, sc, err)
|
|
Packit Service |
4d2de5 |
}()
|
|
Packit Service |
4d2de5 |
}
|
|
Packit Service |
4d2de5 |
result.page, err = client.List(ctx, location)
|
|
Packit Service |
4d2de5 |
return
|
|
Packit Service |
4d2de5 |
}
|