1// Package reservations implements the Azure ARM Reservations service API version 2019-04-01. 2// 3// This API describe Azure Reservation 4package reservations 5 6// Copyright (c) Microsoft and contributors. All rights reserved. 7// 8// Licensed under the Apache License, Version 2.0 (the "License"); 9// you may not use this file except in compliance with the License. 10// You may obtain a copy of the License at 11// http://www.apache.org/licenses/LICENSE-2.0 12// 13// Unless required by applicable law or agreed to in writing, software 14// distributed under the License is distributed on an "AS IS" BASIS, 15// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16// 17// See the License for the specific language governing permissions and 18// limitations under the License. 19// 20// Code generated by Microsoft (R) AutoRest Code Generator. 21// Changes may cause incorrect behavior and will be lost if the code is regenerated. 22 23import ( 24 "context" 25 "github.com/Azure/go-autorest/autorest" 26 "github.com/Azure/go-autorest/autorest/azure" 27 "github.com/Azure/go-autorest/tracing" 28 "net/http" 29) 30 31const ( 32 // DefaultBaseURI is the default URI used for the service Reservations 33 DefaultBaseURI = "https://management.azure.com" 34) 35 36// BaseClient is the base client for Reservations. 37type BaseClient struct { 38 autorest.Client 39 BaseURI string 40} 41 42// New creates an instance of the BaseClient client. 43func New() BaseClient { 44 return NewWithBaseURI(DefaultBaseURI) 45} 46 47// NewWithBaseURI creates an instance of the BaseClient client using a custom endpoint. Use this when interacting with 48// an Azure cloud that uses a non-standard base URI (sovereign clouds, Azure stack). 49func NewWithBaseURI(baseURI string) BaseClient { 50 return BaseClient{ 51 Client: autorest.NewClientWithUserAgent(UserAgent()), 52 BaseURI: baseURI, 53 } 54} 55 56// GetAppliedReservationList get applicable `Reservation`s that are applied to this subscription or a resource group 57// under this subscription. 58// Parameters: 59// subscriptionID - id of the subscription 60func (client BaseClient) GetAppliedReservationList(ctx context.Context, subscriptionID string) (result AppliedReservations, err error) { 61 if tracing.IsEnabled() { 62 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetAppliedReservationList") 63 defer func() { 64 sc := -1 65 if result.Response.Response != nil { 66 sc = result.Response.Response.StatusCode 67 } 68 tracing.EndSpan(ctx, sc, err) 69 }() 70 } 71 req, err := client.GetAppliedReservationListPreparer(ctx, subscriptionID) 72 if err != nil { 73 err = autorest.NewErrorWithError(err, "reservations.BaseClient", "GetAppliedReservationList", nil, "Failure preparing request") 74 return 75 } 76 77 resp, err := client.GetAppliedReservationListSender(req) 78 if err != nil { 79 result.Response = autorest.Response{Response: resp} 80 err = autorest.NewErrorWithError(err, "reservations.BaseClient", "GetAppliedReservationList", resp, "Failure sending request") 81 return 82 } 83 84 result, err = client.GetAppliedReservationListResponder(resp) 85 if err != nil { 86 err = autorest.NewErrorWithError(err, "reservations.BaseClient", "GetAppliedReservationList", resp, "Failure responding to request") 87 } 88 89 return 90} 91 92// GetAppliedReservationListPreparer prepares the GetAppliedReservationList request. 93func (client BaseClient) GetAppliedReservationListPreparer(ctx context.Context, subscriptionID string) (*http.Request, error) { 94 pathParameters := map[string]interface{}{ 95 "subscriptionId": autorest.Encode("path", subscriptionID), 96 } 97 98 const APIVersion = "2019-04-01" 99 queryParameters := map[string]interface{}{ 100 "api-version": APIVersion, 101 } 102 103 preparer := autorest.CreatePreparer( 104 autorest.AsGet(), 105 autorest.WithBaseURL(client.BaseURI), 106 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Capacity/appliedReservations", pathParameters), 107 autorest.WithQueryParameters(queryParameters)) 108 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 109} 110 111// GetAppliedReservationListSender sends the GetAppliedReservationList request. The method will close the 112// http.Response Body if it receives an error. 113func (client BaseClient) GetAppliedReservationListSender(req *http.Request) (*http.Response, error) { 114 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 115} 116 117// GetAppliedReservationListResponder handles the response to the GetAppliedReservationList request. The method always 118// closes the http.Response Body. 119func (client BaseClient) GetAppliedReservationListResponder(resp *http.Response) (result AppliedReservations, err error) { 120 err = autorest.Respond( 121 resp, 122 client.ByInspecting(), 123 azure.WithErrorUnlessStatusCode(http.StatusOK), 124 autorest.ByUnmarshallingJSON(&result), 125 autorest.ByClosing()) 126 result.Response = autorest.Response{Response: resp} 127 return 128} 129 130// GetCatalog sends the get catalog request. 131// Parameters: 132// subscriptionID - id of the subscription 133// reservedResourceType - the type of the resource for which the skus should be provided. 134// location - filters the skus based on the location specified in this parameter. This can be an azure region 135// or global 136func (client BaseClient) GetCatalog(ctx context.Context, subscriptionID string, reservedResourceType string, location string) (result ListCatalog, err error) { 137 if tracing.IsEnabled() { 138 ctx = tracing.StartSpan(ctx, fqdn+"/BaseClient.GetCatalog") 139 defer func() { 140 sc := -1 141 if result.Response.Response != nil { 142 sc = result.Response.Response.StatusCode 143 } 144 tracing.EndSpan(ctx, sc, err) 145 }() 146 } 147 req, err := client.GetCatalogPreparer(ctx, subscriptionID, reservedResourceType, location) 148 if err != nil { 149 err = autorest.NewErrorWithError(err, "reservations.BaseClient", "GetCatalog", nil, "Failure preparing request") 150 return 151 } 152 153 resp, err := client.GetCatalogSender(req) 154 if err != nil { 155 result.Response = autorest.Response{Response: resp} 156 err = autorest.NewErrorWithError(err, "reservations.BaseClient", "GetCatalog", resp, "Failure sending request") 157 return 158 } 159 160 result, err = client.GetCatalogResponder(resp) 161 if err != nil { 162 err = autorest.NewErrorWithError(err, "reservations.BaseClient", "GetCatalog", resp, "Failure responding to request") 163 } 164 165 return 166} 167 168// GetCatalogPreparer prepares the GetCatalog request. 169func (client BaseClient) GetCatalogPreparer(ctx context.Context, subscriptionID string, reservedResourceType string, location string) (*http.Request, error) { 170 pathParameters := map[string]interface{}{ 171 "subscriptionId": autorest.Encode("path", subscriptionID), 172 } 173 174 const APIVersion = "2019-04-01" 175 queryParameters := map[string]interface{}{ 176 "api-version": APIVersion, 177 "reservedResourceType": autorest.Encode("query", reservedResourceType), 178 } 179 if len(location) > 0 { 180 queryParameters["location"] = autorest.Encode("query", location) 181 } 182 183 preparer := autorest.CreatePreparer( 184 autorest.AsGet(), 185 autorest.WithBaseURL(client.BaseURI), 186 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Capacity/catalogs", pathParameters), 187 autorest.WithQueryParameters(queryParameters)) 188 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 189} 190 191// GetCatalogSender sends the GetCatalog request. The method will close the 192// http.Response Body if it receives an error. 193func (client BaseClient) GetCatalogSender(req *http.Request) (*http.Response, error) { 194 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 195} 196 197// GetCatalogResponder handles the response to the GetCatalog request. The method always 198// closes the http.Response Body. 199func (client BaseClient) GetCatalogResponder(resp *http.Response) (result ListCatalog, err error) { 200 err = autorest.Respond( 201 resp, 202 client.ByInspecting(), 203 azure.WithErrorUnlessStatusCode(http.StatusOK), 204 autorest.ByUnmarshallingJSON(&result.Value), 205 autorest.ByClosing()) 206 result.Response = autorest.Response{Response: resp} 207 return 208} 209