1package network 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// 6// Code generated by Microsoft (R) AutoRest Code Generator. 7// Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9import ( 10 "context" 11 "github.com/Azure/go-autorest/autorest" 12 "github.com/Azure/go-autorest/autorest/azure" 13 "github.com/Azure/go-autorest/tracing" 14 "net/http" 15) 16 17// LoadBalancerBackendAddressPoolsClient is the network Client 18type LoadBalancerBackendAddressPoolsClient struct { 19 BaseClient 20} 21 22// NewLoadBalancerBackendAddressPoolsClient creates an instance of the LoadBalancerBackendAddressPoolsClient client. 23func NewLoadBalancerBackendAddressPoolsClient(subscriptionID string) LoadBalancerBackendAddressPoolsClient { 24 return NewLoadBalancerBackendAddressPoolsClientWithBaseURI(DefaultBaseURI, subscriptionID) 25} 26 27// NewLoadBalancerBackendAddressPoolsClientWithBaseURI creates an instance of the LoadBalancerBackendAddressPoolsClient 28// client using a custom endpoint. Use this when interacting with an Azure cloud that uses a non-standard base URI 29// (sovereign clouds, Azure stack). 30func NewLoadBalancerBackendAddressPoolsClientWithBaseURI(baseURI string, subscriptionID string) LoadBalancerBackendAddressPoolsClient { 31 return LoadBalancerBackendAddressPoolsClient{NewWithBaseURI(baseURI, subscriptionID)} 32} 33 34// CreateOrUpdate creates or updates a load balancer backend address pool. 35// Parameters: 36// resourceGroupName - the name of the resource group. 37// loadBalancerName - the name of the load balancer. 38// backendAddressPoolName - the name of the backend address pool. 39// parameters - parameters supplied to the create or update load balancer backend address pool operation. 40func (client LoadBalancerBackendAddressPoolsClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, loadBalancerName string, backendAddressPoolName string, parameters BackendAddressPool) (result LoadBalancerBackendAddressPoolsCreateOrUpdateFuture, err error) { 41 if tracing.IsEnabled() { 42 ctx = tracing.StartSpan(ctx, fqdn+"/LoadBalancerBackendAddressPoolsClient.CreateOrUpdate") 43 defer func() { 44 sc := -1 45 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 46 sc = result.FutureAPI.Response().StatusCode 47 } 48 tracing.EndSpan(ctx, sc, err) 49 }() 50 } 51 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, loadBalancerName, backendAddressPoolName, parameters) 52 if err != nil { 53 err = autorest.NewErrorWithError(err, "network.LoadBalancerBackendAddressPoolsClient", "CreateOrUpdate", nil, "Failure preparing request") 54 return 55 } 56 57 result, err = client.CreateOrUpdateSender(req) 58 if err != nil { 59 err = autorest.NewErrorWithError(err, "network.LoadBalancerBackendAddressPoolsClient", "CreateOrUpdate", nil, "Failure sending request") 60 return 61 } 62 63 return 64} 65 66// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 67func (client LoadBalancerBackendAddressPoolsClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, loadBalancerName string, backendAddressPoolName string, parameters BackendAddressPool) (*http.Request, error) { 68 pathParameters := map[string]interface{}{ 69 "backendAddressPoolName": autorest.Encode("path", backendAddressPoolName), 70 "loadBalancerName": autorest.Encode("path", loadBalancerName), 71 "resourceGroupName": autorest.Encode("path", resourceGroupName), 72 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 73 } 74 75 const APIVersion = "2021-02-01" 76 queryParameters := map[string]interface{}{ 77 "api-version": APIVersion, 78 } 79 80 parameters.Etag = nil 81 parameters.Type = nil 82 preparer := autorest.CreatePreparer( 83 autorest.AsContentType("application/json; charset=utf-8"), 84 autorest.AsPut(), 85 autorest.WithBaseURL(client.BaseURI), 86 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}/backendAddressPools/{backendAddressPoolName}", pathParameters), 87 autorest.WithJSON(parameters), 88 autorest.WithQueryParameters(queryParameters)) 89 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 90} 91 92// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 93// http.Response Body if it receives an error. 94func (client LoadBalancerBackendAddressPoolsClient) CreateOrUpdateSender(req *http.Request) (future LoadBalancerBackendAddressPoolsCreateOrUpdateFuture, err error) { 95 var resp *http.Response 96 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 97 if err != nil { 98 return 99 } 100 var azf azure.Future 101 azf, err = azure.NewFutureFromResponse(resp) 102 future.FutureAPI = &azf 103 future.Result = future.result 104 return 105} 106 107// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 108// closes the http.Response Body. 109func (client LoadBalancerBackendAddressPoolsClient) CreateOrUpdateResponder(resp *http.Response) (result BackendAddressPool, err error) { 110 err = autorest.Respond( 111 resp, 112 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 113 autorest.ByUnmarshallingJSON(&result), 114 autorest.ByClosing()) 115 result.Response = autorest.Response{Response: resp} 116 return 117} 118 119// Delete deletes the specified load balancer backend address pool. 120// Parameters: 121// resourceGroupName - the name of the resource group. 122// loadBalancerName - the name of the load balancer. 123// backendAddressPoolName - the name of the backend address pool. 124func (client LoadBalancerBackendAddressPoolsClient) Delete(ctx context.Context, resourceGroupName string, loadBalancerName string, backendAddressPoolName string) (result LoadBalancerBackendAddressPoolsDeleteFuture, err error) { 125 if tracing.IsEnabled() { 126 ctx = tracing.StartSpan(ctx, fqdn+"/LoadBalancerBackendAddressPoolsClient.Delete") 127 defer func() { 128 sc := -1 129 if result.FutureAPI != nil && result.FutureAPI.Response() != nil { 130 sc = result.FutureAPI.Response().StatusCode 131 } 132 tracing.EndSpan(ctx, sc, err) 133 }() 134 } 135 req, err := client.DeletePreparer(ctx, resourceGroupName, loadBalancerName, backendAddressPoolName) 136 if err != nil { 137 err = autorest.NewErrorWithError(err, "network.LoadBalancerBackendAddressPoolsClient", "Delete", nil, "Failure preparing request") 138 return 139 } 140 141 result, err = client.DeleteSender(req) 142 if err != nil { 143 err = autorest.NewErrorWithError(err, "network.LoadBalancerBackendAddressPoolsClient", "Delete", nil, "Failure sending request") 144 return 145 } 146 147 return 148} 149 150// DeletePreparer prepares the Delete request. 151func (client LoadBalancerBackendAddressPoolsClient) DeletePreparer(ctx context.Context, resourceGroupName string, loadBalancerName string, backendAddressPoolName string) (*http.Request, error) { 152 pathParameters := map[string]interface{}{ 153 "backendAddressPoolName": autorest.Encode("path", backendAddressPoolName), 154 "loadBalancerName": autorest.Encode("path", loadBalancerName), 155 "resourceGroupName": autorest.Encode("path", resourceGroupName), 156 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 157 } 158 159 const APIVersion = "2021-02-01" 160 queryParameters := map[string]interface{}{ 161 "api-version": APIVersion, 162 } 163 164 preparer := autorest.CreatePreparer( 165 autorest.AsDelete(), 166 autorest.WithBaseURL(client.BaseURI), 167 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}/backendAddressPools/{backendAddressPoolName}", pathParameters), 168 autorest.WithQueryParameters(queryParameters)) 169 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 170} 171 172// DeleteSender sends the Delete request. The method will close the 173// http.Response Body if it receives an error. 174func (client LoadBalancerBackendAddressPoolsClient) DeleteSender(req *http.Request) (future LoadBalancerBackendAddressPoolsDeleteFuture, err error) { 175 var resp *http.Response 176 resp, err = client.Send(req, azure.DoRetryWithRegistration(client.Client)) 177 if err != nil { 178 return 179 } 180 var azf azure.Future 181 azf, err = azure.NewFutureFromResponse(resp) 182 future.FutureAPI = &azf 183 future.Result = future.result 184 return 185} 186 187// DeleteResponder handles the response to the Delete request. The method always 188// closes the http.Response Body. 189func (client LoadBalancerBackendAddressPoolsClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 190 err = autorest.Respond( 191 resp, 192 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 193 autorest.ByClosing()) 194 result.Response = resp 195 return 196} 197 198// Get gets load balancer backend address pool. 199// Parameters: 200// resourceGroupName - the name of the resource group. 201// loadBalancerName - the name of the load balancer. 202// backendAddressPoolName - the name of the backend address pool. 203func (client LoadBalancerBackendAddressPoolsClient) Get(ctx context.Context, resourceGroupName string, loadBalancerName string, backendAddressPoolName string) (result BackendAddressPool, err error) { 204 if tracing.IsEnabled() { 205 ctx = tracing.StartSpan(ctx, fqdn+"/LoadBalancerBackendAddressPoolsClient.Get") 206 defer func() { 207 sc := -1 208 if result.Response.Response != nil { 209 sc = result.Response.Response.StatusCode 210 } 211 tracing.EndSpan(ctx, sc, err) 212 }() 213 } 214 req, err := client.GetPreparer(ctx, resourceGroupName, loadBalancerName, backendAddressPoolName) 215 if err != nil { 216 err = autorest.NewErrorWithError(err, "network.LoadBalancerBackendAddressPoolsClient", "Get", nil, "Failure preparing request") 217 return 218 } 219 220 resp, err := client.GetSender(req) 221 if err != nil { 222 result.Response = autorest.Response{Response: resp} 223 err = autorest.NewErrorWithError(err, "network.LoadBalancerBackendAddressPoolsClient", "Get", resp, "Failure sending request") 224 return 225 } 226 227 result, err = client.GetResponder(resp) 228 if err != nil { 229 err = autorest.NewErrorWithError(err, "network.LoadBalancerBackendAddressPoolsClient", "Get", resp, "Failure responding to request") 230 return 231 } 232 233 return 234} 235 236// GetPreparer prepares the Get request. 237func (client LoadBalancerBackendAddressPoolsClient) GetPreparer(ctx context.Context, resourceGroupName string, loadBalancerName string, backendAddressPoolName string) (*http.Request, error) { 238 pathParameters := map[string]interface{}{ 239 "backendAddressPoolName": autorest.Encode("path", backendAddressPoolName), 240 "loadBalancerName": autorest.Encode("path", loadBalancerName), 241 "resourceGroupName": autorest.Encode("path", resourceGroupName), 242 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 243 } 244 245 const APIVersion = "2021-02-01" 246 queryParameters := map[string]interface{}{ 247 "api-version": APIVersion, 248 } 249 250 preparer := autorest.CreatePreparer( 251 autorest.AsGet(), 252 autorest.WithBaseURL(client.BaseURI), 253 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}/backendAddressPools/{backendAddressPoolName}", pathParameters), 254 autorest.WithQueryParameters(queryParameters)) 255 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 256} 257 258// GetSender sends the Get request. The method will close the 259// http.Response Body if it receives an error. 260func (client LoadBalancerBackendAddressPoolsClient) GetSender(req *http.Request) (*http.Response, error) { 261 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 262} 263 264// GetResponder handles the response to the Get request. The method always 265// closes the http.Response Body. 266func (client LoadBalancerBackendAddressPoolsClient) GetResponder(resp *http.Response) (result BackendAddressPool, err error) { 267 err = autorest.Respond( 268 resp, 269 azure.WithErrorUnlessStatusCode(http.StatusOK), 270 autorest.ByUnmarshallingJSON(&result), 271 autorest.ByClosing()) 272 result.Response = autorest.Response{Response: resp} 273 return 274} 275 276// List gets all the load balancer backed address pools. 277// Parameters: 278// resourceGroupName - the name of the resource group. 279// loadBalancerName - the name of the load balancer. 280func (client LoadBalancerBackendAddressPoolsClient) List(ctx context.Context, resourceGroupName string, loadBalancerName string) (result LoadBalancerBackendAddressPoolListResultPage, err error) { 281 if tracing.IsEnabled() { 282 ctx = tracing.StartSpan(ctx, fqdn+"/LoadBalancerBackendAddressPoolsClient.List") 283 defer func() { 284 sc := -1 285 if result.lbbaplr.Response.Response != nil { 286 sc = result.lbbaplr.Response.Response.StatusCode 287 } 288 tracing.EndSpan(ctx, sc, err) 289 }() 290 } 291 result.fn = client.listNextResults 292 req, err := client.ListPreparer(ctx, resourceGroupName, loadBalancerName) 293 if err != nil { 294 err = autorest.NewErrorWithError(err, "network.LoadBalancerBackendAddressPoolsClient", "List", nil, "Failure preparing request") 295 return 296 } 297 298 resp, err := client.ListSender(req) 299 if err != nil { 300 result.lbbaplr.Response = autorest.Response{Response: resp} 301 err = autorest.NewErrorWithError(err, "network.LoadBalancerBackendAddressPoolsClient", "List", resp, "Failure sending request") 302 return 303 } 304 305 result.lbbaplr, err = client.ListResponder(resp) 306 if err != nil { 307 err = autorest.NewErrorWithError(err, "network.LoadBalancerBackendAddressPoolsClient", "List", resp, "Failure responding to request") 308 return 309 } 310 if result.lbbaplr.hasNextLink() && result.lbbaplr.IsEmpty() { 311 err = result.NextWithContext(ctx) 312 return 313 } 314 315 return 316} 317 318// ListPreparer prepares the List request. 319func (client LoadBalancerBackendAddressPoolsClient) ListPreparer(ctx context.Context, resourceGroupName string, loadBalancerName string) (*http.Request, error) { 320 pathParameters := map[string]interface{}{ 321 "loadBalancerName": autorest.Encode("path", loadBalancerName), 322 "resourceGroupName": autorest.Encode("path", resourceGroupName), 323 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 324 } 325 326 const APIVersion = "2021-02-01" 327 queryParameters := map[string]interface{}{ 328 "api-version": APIVersion, 329 } 330 331 preparer := autorest.CreatePreparer( 332 autorest.AsGet(), 333 autorest.WithBaseURL(client.BaseURI), 334 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}/backendAddressPools", pathParameters), 335 autorest.WithQueryParameters(queryParameters)) 336 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 337} 338 339// ListSender sends the List request. The method will close the 340// http.Response Body if it receives an error. 341func (client LoadBalancerBackendAddressPoolsClient) ListSender(req *http.Request) (*http.Response, error) { 342 return client.Send(req, azure.DoRetryWithRegistration(client.Client)) 343} 344 345// ListResponder handles the response to the List request. The method always 346// closes the http.Response Body. 347func (client LoadBalancerBackendAddressPoolsClient) ListResponder(resp *http.Response) (result LoadBalancerBackendAddressPoolListResult, err error) { 348 err = autorest.Respond( 349 resp, 350 azure.WithErrorUnlessStatusCode(http.StatusOK), 351 autorest.ByUnmarshallingJSON(&result), 352 autorest.ByClosing()) 353 result.Response = autorest.Response{Response: resp} 354 return 355} 356 357// listNextResults retrieves the next set of results, if any. 358func (client LoadBalancerBackendAddressPoolsClient) listNextResults(ctx context.Context, lastResults LoadBalancerBackendAddressPoolListResult) (result LoadBalancerBackendAddressPoolListResult, err error) { 359 req, err := lastResults.loadBalancerBackendAddressPoolListResultPreparer(ctx) 360 if err != nil { 361 return result, autorest.NewErrorWithError(err, "network.LoadBalancerBackendAddressPoolsClient", "listNextResults", nil, "Failure preparing next results request") 362 } 363 if req == nil { 364 return 365 } 366 resp, err := client.ListSender(req) 367 if err != nil { 368 result.Response = autorest.Response{Response: resp} 369 return result, autorest.NewErrorWithError(err, "network.LoadBalancerBackendAddressPoolsClient", "listNextResults", resp, "Failure sending next results request") 370 } 371 result, err = client.ListResponder(resp) 372 if err != nil { 373 err = autorest.NewErrorWithError(err, "network.LoadBalancerBackendAddressPoolsClient", "listNextResults", resp, "Failure responding to next results request") 374 } 375 return 376} 377 378// ListComplete enumerates all values, automatically crossing page boundaries as required. 379func (client LoadBalancerBackendAddressPoolsClient) ListComplete(ctx context.Context, resourceGroupName string, loadBalancerName string) (result LoadBalancerBackendAddressPoolListResultIterator, err error) { 380 if tracing.IsEnabled() { 381 ctx = tracing.StartSpan(ctx, fqdn+"/LoadBalancerBackendAddressPoolsClient.List") 382 defer func() { 383 sc := -1 384 if result.Response().Response.Response != nil { 385 sc = result.page.Response().Response.Response.StatusCode 386 } 387 tracing.EndSpan(ctx, sc, err) 388 }() 389 } 390 result.page, err = client.List(ctx, resourceGroupName, loadBalancerName) 391 return 392} 393