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