1package network 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 "net/http" 25) 26 27// LoadBalancersClient is the network Client 28type LoadBalancersClient struct { 29 BaseClient 30} 31 32// NewLoadBalancersClient creates an instance of the LoadBalancersClient client. 33func NewLoadBalancersClient(subscriptionID string) LoadBalancersClient { 34 return NewLoadBalancersClientWithBaseURI(DefaultBaseURI, subscriptionID) 35} 36 37// NewLoadBalancersClientWithBaseURI creates an instance of the LoadBalancersClient client. 38func NewLoadBalancersClientWithBaseURI(baseURI string, subscriptionID string) LoadBalancersClient { 39 return LoadBalancersClient{NewWithBaseURI(baseURI, subscriptionID)} 40} 41 42// CreateOrUpdate creates or updates a load balancer. 43// Parameters: 44// resourceGroupName - the name of the resource group. 45// loadBalancerName - the name of the load balancer. 46// parameters - parameters supplied to the create or update load balancer operation. 47func (client LoadBalancersClient) CreateOrUpdate(ctx context.Context, resourceGroupName string, loadBalancerName string, parameters LoadBalancer) (result LoadBalancersCreateOrUpdateFuture, err error) { 48 req, err := client.CreateOrUpdatePreparer(ctx, resourceGroupName, loadBalancerName, parameters) 49 if err != nil { 50 err = autorest.NewErrorWithError(err, "network.LoadBalancersClient", "CreateOrUpdate", nil, "Failure preparing request") 51 return 52 } 53 54 result, err = client.CreateOrUpdateSender(req) 55 if err != nil { 56 err = autorest.NewErrorWithError(err, "network.LoadBalancersClient", "CreateOrUpdate", result.Response(), "Failure sending request") 57 return 58 } 59 60 return 61} 62 63// CreateOrUpdatePreparer prepares the CreateOrUpdate request. 64func (client LoadBalancersClient) CreateOrUpdatePreparer(ctx context.Context, resourceGroupName string, loadBalancerName string, parameters LoadBalancer) (*http.Request, error) { 65 pathParameters := map[string]interface{}{ 66 "loadBalancerName": autorest.Encode("path", loadBalancerName), 67 "resourceGroupName": autorest.Encode("path", resourceGroupName), 68 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 69 } 70 71 const APIVersion = "2016-09-01" 72 queryParameters := map[string]interface{}{ 73 "api-version": APIVersion, 74 } 75 76 preparer := autorest.CreatePreparer( 77 autorest.AsContentType("application/json; charset=utf-8"), 78 autorest.AsPut(), 79 autorest.WithBaseURL(client.BaseURI), 80 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}", pathParameters), 81 autorest.WithJSON(parameters), 82 autorest.WithQueryParameters(queryParameters)) 83 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 84} 85 86// CreateOrUpdateSender sends the CreateOrUpdate request. The method will close the 87// http.Response Body if it receives an error. 88func (client LoadBalancersClient) CreateOrUpdateSender(req *http.Request) (future LoadBalancersCreateOrUpdateFuture, err error) { 89 var resp *http.Response 90 resp, err = autorest.SendWithSender(client, req, 91 azure.DoRetryWithRegistration(client.Client)) 92 if err != nil { 93 return 94 } 95 err = autorest.Respond(resp, azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated)) 96 if err != nil { 97 return 98 } 99 future.Future, err = azure.NewFutureFromResponse(resp) 100 return 101} 102 103// CreateOrUpdateResponder handles the response to the CreateOrUpdate request. The method always 104// closes the http.Response Body. 105func (client LoadBalancersClient) CreateOrUpdateResponder(resp *http.Response) (result LoadBalancer, err error) { 106 err = autorest.Respond( 107 resp, 108 client.ByInspecting(), 109 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusCreated), 110 autorest.ByUnmarshallingJSON(&result), 111 autorest.ByClosing()) 112 result.Response = autorest.Response{Response: resp} 113 return 114} 115 116// Delete deletes the specified load balancer. 117// Parameters: 118// resourceGroupName - the name of the resource group. 119// loadBalancerName - the name of the load balancer. 120func (client LoadBalancersClient) Delete(ctx context.Context, resourceGroupName string, loadBalancerName string) (result LoadBalancersDeleteFuture, err error) { 121 req, err := client.DeletePreparer(ctx, resourceGroupName, loadBalancerName) 122 if err != nil { 123 err = autorest.NewErrorWithError(err, "network.LoadBalancersClient", "Delete", nil, "Failure preparing request") 124 return 125 } 126 127 result, err = client.DeleteSender(req) 128 if err != nil { 129 err = autorest.NewErrorWithError(err, "network.LoadBalancersClient", "Delete", result.Response(), "Failure sending request") 130 return 131 } 132 133 return 134} 135 136// DeletePreparer prepares the Delete request. 137func (client LoadBalancersClient) DeletePreparer(ctx context.Context, resourceGroupName string, loadBalancerName string) (*http.Request, error) { 138 pathParameters := map[string]interface{}{ 139 "loadBalancerName": autorest.Encode("path", loadBalancerName), 140 "resourceGroupName": autorest.Encode("path", resourceGroupName), 141 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 142 } 143 144 const APIVersion = "2016-09-01" 145 queryParameters := map[string]interface{}{ 146 "api-version": APIVersion, 147 } 148 149 preparer := autorest.CreatePreparer( 150 autorest.AsDelete(), 151 autorest.WithBaseURL(client.BaseURI), 152 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}", pathParameters), 153 autorest.WithQueryParameters(queryParameters)) 154 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 155} 156 157// DeleteSender sends the Delete request. The method will close the 158// http.Response Body if it receives an error. 159func (client LoadBalancersClient) DeleteSender(req *http.Request) (future LoadBalancersDeleteFuture, err error) { 160 var resp *http.Response 161 resp, err = autorest.SendWithSender(client, req, 162 azure.DoRetryWithRegistration(client.Client)) 163 if err != nil { 164 return 165 } 166 err = autorest.Respond(resp, azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent)) 167 if err != nil { 168 return 169 } 170 future.Future, err = azure.NewFutureFromResponse(resp) 171 return 172} 173 174// DeleteResponder handles the response to the Delete request. The method always 175// closes the http.Response Body. 176func (client LoadBalancersClient) DeleteResponder(resp *http.Response) (result autorest.Response, err error) { 177 err = autorest.Respond( 178 resp, 179 client.ByInspecting(), 180 azure.WithErrorUnlessStatusCode(http.StatusOK, http.StatusAccepted, http.StatusNoContent), 181 autorest.ByClosing()) 182 result.Response = resp 183 return 184} 185 186// Get gets the specified load balancer. 187// Parameters: 188// resourceGroupName - the name of the resource group. 189// loadBalancerName - the name of the load balancer. 190// expand - expands referenced resources. 191func (client LoadBalancersClient) Get(ctx context.Context, resourceGroupName string, loadBalancerName string, expand string) (result LoadBalancer, err error) { 192 req, err := client.GetPreparer(ctx, resourceGroupName, loadBalancerName, expand) 193 if err != nil { 194 err = autorest.NewErrorWithError(err, "network.LoadBalancersClient", "Get", nil, "Failure preparing request") 195 return 196 } 197 198 resp, err := client.GetSender(req) 199 if err != nil { 200 result.Response = autorest.Response{Response: resp} 201 err = autorest.NewErrorWithError(err, "network.LoadBalancersClient", "Get", resp, "Failure sending request") 202 return 203 } 204 205 result, err = client.GetResponder(resp) 206 if err != nil { 207 err = autorest.NewErrorWithError(err, "network.LoadBalancersClient", "Get", resp, "Failure responding to request") 208 } 209 210 return 211} 212 213// GetPreparer prepares the Get request. 214func (client LoadBalancersClient) GetPreparer(ctx context.Context, resourceGroupName string, loadBalancerName string, expand string) (*http.Request, error) { 215 pathParameters := map[string]interface{}{ 216 "loadBalancerName": autorest.Encode("path", loadBalancerName), 217 "resourceGroupName": autorest.Encode("path", resourceGroupName), 218 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 219 } 220 221 const APIVersion = "2016-09-01" 222 queryParameters := map[string]interface{}{ 223 "api-version": APIVersion, 224 } 225 if len(expand) > 0 { 226 queryParameters["$expand"] = autorest.Encode("query", expand) 227 } 228 229 preparer := autorest.CreatePreparer( 230 autorest.AsGet(), 231 autorest.WithBaseURL(client.BaseURI), 232 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}", pathParameters), 233 autorest.WithQueryParameters(queryParameters)) 234 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 235} 236 237// GetSender sends the Get request. The method will close the 238// http.Response Body if it receives an error. 239func (client LoadBalancersClient) GetSender(req *http.Request) (*http.Response, error) { 240 return autorest.SendWithSender(client, req, 241 azure.DoRetryWithRegistration(client.Client)) 242} 243 244// GetResponder handles the response to the Get request. The method always 245// closes the http.Response Body. 246func (client LoadBalancersClient) GetResponder(resp *http.Response) (result LoadBalancer, err error) { 247 err = autorest.Respond( 248 resp, 249 client.ByInspecting(), 250 azure.WithErrorUnlessStatusCode(http.StatusOK), 251 autorest.ByUnmarshallingJSON(&result), 252 autorest.ByClosing()) 253 result.Response = autorest.Response{Response: resp} 254 return 255} 256 257// List gets all the load balancers in a resource group. 258// Parameters: 259// resourceGroupName - the name of the resource group. 260func (client LoadBalancersClient) List(ctx context.Context, resourceGroupName string) (result LoadBalancerListResultPage, err error) { 261 result.fn = client.listNextResults 262 req, err := client.ListPreparer(ctx, resourceGroupName) 263 if err != nil { 264 err = autorest.NewErrorWithError(err, "network.LoadBalancersClient", "List", nil, "Failure preparing request") 265 return 266 } 267 268 resp, err := client.ListSender(req) 269 if err != nil { 270 result.lblr.Response = autorest.Response{Response: resp} 271 err = autorest.NewErrorWithError(err, "network.LoadBalancersClient", "List", resp, "Failure sending request") 272 return 273 } 274 275 result.lblr, err = client.ListResponder(resp) 276 if err != nil { 277 err = autorest.NewErrorWithError(err, "network.LoadBalancersClient", "List", resp, "Failure responding to request") 278 } 279 280 return 281} 282 283// ListPreparer prepares the List request. 284func (client LoadBalancersClient) ListPreparer(ctx context.Context, resourceGroupName string) (*http.Request, error) { 285 pathParameters := map[string]interface{}{ 286 "resourceGroupName": autorest.Encode("path", resourceGroupName), 287 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 288 } 289 290 const APIVersion = "2016-09-01" 291 queryParameters := map[string]interface{}{ 292 "api-version": APIVersion, 293 } 294 295 preparer := autorest.CreatePreparer( 296 autorest.AsGet(), 297 autorest.WithBaseURL(client.BaseURI), 298 autorest.WithPathParameters("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers", pathParameters), 299 autorest.WithQueryParameters(queryParameters)) 300 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 301} 302 303// ListSender sends the List request. The method will close the 304// http.Response Body if it receives an error. 305func (client LoadBalancersClient) ListSender(req *http.Request) (*http.Response, error) { 306 return autorest.SendWithSender(client, req, 307 azure.DoRetryWithRegistration(client.Client)) 308} 309 310// ListResponder handles the response to the List request. The method always 311// closes the http.Response Body. 312func (client LoadBalancersClient) ListResponder(resp *http.Response) (result LoadBalancerListResult, err error) { 313 err = autorest.Respond( 314 resp, 315 client.ByInspecting(), 316 azure.WithErrorUnlessStatusCode(http.StatusOK), 317 autorest.ByUnmarshallingJSON(&result), 318 autorest.ByClosing()) 319 result.Response = autorest.Response{Response: resp} 320 return 321} 322 323// listNextResults retrieves the next set of results, if any. 324func (client LoadBalancersClient) listNextResults(lastResults LoadBalancerListResult) (result LoadBalancerListResult, err error) { 325 req, err := lastResults.loadBalancerListResultPreparer() 326 if err != nil { 327 return result, autorest.NewErrorWithError(err, "network.LoadBalancersClient", "listNextResults", nil, "Failure preparing next results request") 328 } 329 if req == nil { 330 return 331 } 332 resp, err := client.ListSender(req) 333 if err != nil { 334 result.Response = autorest.Response{Response: resp} 335 return result, autorest.NewErrorWithError(err, "network.LoadBalancersClient", "listNextResults", resp, "Failure sending next results request") 336 } 337 result, err = client.ListResponder(resp) 338 if err != nil { 339 err = autorest.NewErrorWithError(err, "network.LoadBalancersClient", "listNextResults", resp, "Failure responding to next results request") 340 } 341 return 342} 343 344// ListComplete enumerates all values, automatically crossing page boundaries as required. 345func (client LoadBalancersClient) ListComplete(ctx context.Context, resourceGroupName string) (result LoadBalancerListResultIterator, err error) { 346 result.page, err = client.List(ctx, resourceGroupName) 347 return 348} 349 350// ListAll gets all the load balancers in a subscription. 351func (client LoadBalancersClient) ListAll(ctx context.Context) (result LoadBalancerListResultPage, err error) { 352 result.fn = client.listAllNextResults 353 req, err := client.ListAllPreparer(ctx) 354 if err != nil { 355 err = autorest.NewErrorWithError(err, "network.LoadBalancersClient", "ListAll", nil, "Failure preparing request") 356 return 357 } 358 359 resp, err := client.ListAllSender(req) 360 if err != nil { 361 result.lblr.Response = autorest.Response{Response: resp} 362 err = autorest.NewErrorWithError(err, "network.LoadBalancersClient", "ListAll", resp, "Failure sending request") 363 return 364 } 365 366 result.lblr, err = client.ListAllResponder(resp) 367 if err != nil { 368 err = autorest.NewErrorWithError(err, "network.LoadBalancersClient", "ListAll", resp, "Failure responding to request") 369 } 370 371 return 372} 373 374// ListAllPreparer prepares the ListAll request. 375func (client LoadBalancersClient) ListAllPreparer(ctx context.Context) (*http.Request, error) { 376 pathParameters := map[string]interface{}{ 377 "subscriptionId": autorest.Encode("path", client.SubscriptionID), 378 } 379 380 const APIVersion = "2016-09-01" 381 queryParameters := map[string]interface{}{ 382 "api-version": APIVersion, 383 } 384 385 preparer := autorest.CreatePreparer( 386 autorest.AsGet(), 387 autorest.WithBaseURL(client.BaseURI), 388 autorest.WithPathParameters("/subscriptions/{subscriptionId}/providers/Microsoft.Network/loadBalancers", pathParameters), 389 autorest.WithQueryParameters(queryParameters)) 390 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 391} 392 393// ListAllSender sends the ListAll request. The method will close the 394// http.Response Body if it receives an error. 395func (client LoadBalancersClient) ListAllSender(req *http.Request) (*http.Response, error) { 396 return autorest.SendWithSender(client, req, 397 azure.DoRetryWithRegistration(client.Client)) 398} 399 400// ListAllResponder handles the response to the ListAll request. The method always 401// closes the http.Response Body. 402func (client LoadBalancersClient) ListAllResponder(resp *http.Response) (result LoadBalancerListResult, err error) { 403 err = autorest.Respond( 404 resp, 405 client.ByInspecting(), 406 azure.WithErrorUnlessStatusCode(http.StatusOK), 407 autorest.ByUnmarshallingJSON(&result), 408 autorest.ByClosing()) 409 result.Response = autorest.Response{Response: resp} 410 return 411} 412 413// listAllNextResults retrieves the next set of results, if any. 414func (client LoadBalancersClient) listAllNextResults(lastResults LoadBalancerListResult) (result LoadBalancerListResult, err error) { 415 req, err := lastResults.loadBalancerListResultPreparer() 416 if err != nil { 417 return result, autorest.NewErrorWithError(err, "network.LoadBalancersClient", "listAllNextResults", nil, "Failure preparing next results request") 418 } 419 if req == nil { 420 return 421 } 422 resp, err := client.ListAllSender(req) 423 if err != nil { 424 result.Response = autorest.Response{Response: resp} 425 return result, autorest.NewErrorWithError(err, "network.LoadBalancersClient", "listAllNextResults", resp, "Failure sending next results request") 426 } 427 result, err = client.ListAllResponder(resp) 428 if err != nil { 429 err = autorest.NewErrorWithError(err, "network.LoadBalancersClient", "listAllNextResults", resp, "Failure responding to next results request") 430 } 431 return 432} 433 434// ListAllComplete enumerates all values, automatically crossing page boundaries as required. 435func (client LoadBalancersClient) ListAllComplete(ctx context.Context) (result LoadBalancerListResultIterator, err error) { 436 result.page, err = client.ListAll(ctx) 437 return 438} 439