1package vmwarecloudsimple 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// UsagesClient is the description of the new service 29type UsagesClient struct { 30 BaseClient 31} 32 33// NewUsagesClient creates an instance of the UsagesClient client. 34func NewUsagesClient(subscriptionID string, referer string) UsagesClient { 35 return NewUsagesClientWithBaseURI(DefaultBaseURI, subscriptionID, referer) 36} 37 38// NewUsagesClientWithBaseURI creates an instance of the UsagesClient client. 39func NewUsagesClientWithBaseURI(baseURI string, subscriptionID string, referer string) UsagesClient { 40 return UsagesClient{NewWithBaseURI(baseURI, subscriptionID, referer)} 41} 42 43// List returns list of usage in region 44// Parameters: 45// regionID - the region Id (westus, eastus) 46// filter - the filter to apply on the list operation. only name.value is allowed here as a filter e.g. 47// $filter=name.value eq 'xxxx' 48func (client UsagesClient) List(ctx context.Context, regionID string, filter string) (result UsageListResponsePage, err error) { 49 if tracing.IsEnabled() { 50 ctx = tracing.StartSpan(ctx, fqdn+"/UsagesClient.List") 51 defer func() { 52 sc := -1 53 if result.ulr.Response.Response != nil { 54 sc = result.ulr.Response.Response.StatusCode 55 } 56 tracing.EndSpan(ctx, sc, err) 57 }() 58 } 59 result.fn = client.listNextResults 60 req, err := client.ListPreparer(ctx, regionID, filter) 61 if err != nil { 62 err = autorest.NewErrorWithError(err, "vmwarecloudsimple.UsagesClient", "List", nil, "Failure preparing request") 63 return 64 } 65 66 resp, err := client.ListSender(req) 67 if err != nil { 68 result.ulr.Response = autorest.Response{Response: resp} 69 err = autorest.NewErrorWithError(err, "vmwarecloudsimple.UsagesClient", "List", resp, "Failure sending request") 70 return 71 } 72 73 result.ulr, err = client.ListResponder(resp) 74 if err != nil { 75 err = autorest.NewErrorWithError(err, "vmwarecloudsimple.UsagesClient", "List", resp, "Failure responding to request") 76 } 77 78 return 79} 80 81// ListPreparer prepares the List request. 82func (client UsagesClient) ListPreparer(ctx context.Context, regionID string, filter string) (*http.Request, error) { 83 pathParameters := map[string]interface{}{ 84 "regionId": autorest.Encode("path", regionID), 85 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 86 } 87 88 const APIVersion = "2019-04-01" 89 queryParameters := map[string]interface{}{ 90 "api-version": APIVersion, 91 } 92 if len(filter) > 0 { 93 queryParameters["$filter"] = autorest.Encode("query", filter) 94 } 95 96 preparer := autorest.CreatePreparer( 97 autorest.AsGet(), 98 autorest.WithBaseURL(client.BaseURI), 99 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.VMwareCloudSimple/locations/{regionId}/usages", pathParameters), 100 autorest.WithQueryParameters(queryParameters)) 101 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 102} 103 104// ListSender sends the List request. The method will close the 105// http.Response Body if it receives an error. 106func (client UsagesClient) ListSender(req *http.Request) (*http.Response, error) { 107 sd := autorest.GetSendDecorators(req.Context(), azure.DoRetryWithRegistration(client.Client)) 108 return autorest.SendWithSender(client, req, sd...) 109} 110 111// ListResponder handles the response to the List request. The method always 112// closes the http.Response Body. 113func (client UsagesClient) ListResponder(resp *http.Response) (result UsageListResponse, err error) { 114 err = autorest.Respond( 115 resp, 116 client.ByInspecting(), 117 azure.WithErrorUnlessStatusCode(http.StatusOK), 118 autorest.ByUnmarshallingJSON(&result), 119 autorest.ByClosing()) 120 result.Response = autorest.Response{Response: resp} 121 return 122} 123 124// listNextResults retrieves the next set of results, if any. 125func (client UsagesClient) listNextResults(ctx context.Context, lastResults UsageListResponse) (result UsageListResponse, err error) { 126 req, err := lastResults.usageListResponsePreparer(ctx) 127 if err != nil { 128 return result, autorest.NewErrorWithError(err, "vmwarecloudsimple.UsagesClient", "listNextResults", nil, "Failure preparing next results request") 129 } 130 if req == nil { 131 return 132 } 133 resp, err := client.ListSender(req) 134 if err != nil { 135 result.Response = autorest.Response{Response: resp} 136 return result, autorest.NewErrorWithError(err, "vmwarecloudsimple.UsagesClient", "listNextResults", resp, "Failure sending next results request") 137 } 138 result, err = client.ListResponder(resp) 139 if err != nil { 140 err = autorest.NewErrorWithError(err, "vmwarecloudsimple.UsagesClient", "listNextResults", resp, "Failure responding to next results request") 141 } 142 return 143} 144 145// ListComplete enumerates all values, automatically crossing page boundaries as required. 146func (client UsagesClient) ListComplete(ctx context.Context, regionID string, filter string) (result UsageListResponseIterator, err error) { 147 if tracing.IsEnabled() { 148 ctx = tracing.StartSpan(ctx, fqdn+"/UsagesClient.List") 149 defer func() { 150 sc := -1 151 if result.Response().Response.Response != nil { 152 sc = result.page.Response().Response.Response.StatusCode 153 } 154 tracing.EndSpan(ctx, sc, err) 155 }() 156 } 157 result.page, err = client.List(ctx, regionID, filter) 158 return 159} 160