github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6@v6.2.0/loadbalancers_client.go (about) 1 //go:build go1.18 2 // +build go1.18 3 4 // Copyright (c) Microsoft Corporation. All rights reserved. 5 // Licensed under the MIT License. See License.txt in the project root for license information. 6 // Code generated by Microsoft (R) AutoRest Code Generator. DO NOT EDIT. 7 // Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9 package armnetwork 10 11 import ( 12 "context" 13 "errors" 14 "github.com/Azure/azure-sdk-for-go/sdk/azcore" 15 "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" 16 "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" 17 "github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime" 18 "net/http" 19 "net/url" 20 "strings" 21 ) 22 23 // LoadBalancersClient contains the methods for the LoadBalancers group. 24 // Don't use this type directly, use NewLoadBalancersClient() instead. 25 type LoadBalancersClient struct { 26 internal *arm.Client 27 subscriptionID string 28 } 29 30 // NewLoadBalancersClient creates a new instance of LoadBalancersClient with the specified values. 31 // - subscriptionID - The subscription credentials which uniquely identify the Microsoft Azure subscription. The subscription 32 // ID forms part of the URI for every service call. 33 // - credential - used to authorize requests. Usually a credential from azidentity. 34 // - options - pass nil to accept the default values. 35 func NewLoadBalancersClient(subscriptionID string, credential azcore.TokenCredential, options *arm.ClientOptions) (*LoadBalancersClient, error) { 36 cl, err := arm.NewClient(moduleName, moduleVersion, credential, options) 37 if err != nil { 38 return nil, err 39 } 40 client := &LoadBalancersClient{ 41 subscriptionID: subscriptionID, 42 internal: cl, 43 } 44 return client, nil 45 } 46 47 // BeginCreateOrUpdate - Creates or updates a load balancer. 48 // If the operation fails it returns an *azcore.ResponseError type. 49 // 50 // Generated from API version 2024-05-01 51 // - resourceGroupName - The name of the resource group. 52 // - loadBalancerName - The name of the load balancer. 53 // - parameters - Parameters supplied to the create or update load balancer operation. 54 // - options - LoadBalancersClientBeginCreateOrUpdateOptions contains the optional parameters for the LoadBalancersClient.BeginCreateOrUpdate 55 // method. 56 func (client *LoadBalancersClient) BeginCreateOrUpdate(ctx context.Context, resourceGroupName string, loadBalancerName string, parameters LoadBalancer, options *LoadBalancersClientBeginCreateOrUpdateOptions) (*runtime.Poller[LoadBalancersClientCreateOrUpdateResponse], error) { 57 if options == nil || options.ResumeToken == "" { 58 resp, err := client.createOrUpdate(ctx, resourceGroupName, loadBalancerName, parameters, options) 59 if err != nil { 60 return nil, err 61 } 62 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LoadBalancersClientCreateOrUpdateResponse]{ 63 FinalStateVia: runtime.FinalStateViaAzureAsyncOp, 64 Tracer: client.internal.Tracer(), 65 }) 66 return poller, err 67 } else { 68 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[LoadBalancersClientCreateOrUpdateResponse]{ 69 Tracer: client.internal.Tracer(), 70 }) 71 } 72 } 73 74 // CreateOrUpdate - Creates or updates a load balancer. 75 // If the operation fails it returns an *azcore.ResponseError type. 76 // 77 // Generated from API version 2024-05-01 78 func (client *LoadBalancersClient) createOrUpdate(ctx context.Context, resourceGroupName string, loadBalancerName string, parameters LoadBalancer, options *LoadBalancersClientBeginCreateOrUpdateOptions) (*http.Response, error) { 79 var err error 80 const operationName = "LoadBalancersClient.BeginCreateOrUpdate" 81 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 82 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 83 defer func() { endSpan(err) }() 84 req, err := client.createOrUpdateCreateRequest(ctx, resourceGroupName, loadBalancerName, parameters, options) 85 if err != nil { 86 return nil, err 87 } 88 httpResp, err := client.internal.Pipeline().Do(req) 89 if err != nil { 90 return nil, err 91 } 92 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusCreated) { 93 err = runtime.NewResponseError(httpResp) 94 return nil, err 95 } 96 return httpResp, nil 97 } 98 99 // createOrUpdateCreateRequest creates the CreateOrUpdate request. 100 func (client *LoadBalancersClient) createOrUpdateCreateRequest(ctx context.Context, resourceGroupName string, loadBalancerName string, parameters LoadBalancer, options *LoadBalancersClientBeginCreateOrUpdateOptions) (*policy.Request, error) { 101 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}" 102 if resourceGroupName == "" { 103 return nil, errors.New("parameter resourceGroupName cannot be empty") 104 } 105 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 106 if loadBalancerName == "" { 107 return nil, errors.New("parameter loadBalancerName cannot be empty") 108 } 109 urlPath = strings.ReplaceAll(urlPath, "{loadBalancerName}", url.PathEscape(loadBalancerName)) 110 if client.subscriptionID == "" { 111 return nil, errors.New("parameter client.subscriptionID cannot be empty") 112 } 113 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 114 req, err := runtime.NewRequest(ctx, http.MethodPut, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 115 if err != nil { 116 return nil, err 117 } 118 reqQP := req.Raw().URL.Query() 119 reqQP.Set("api-version", "2024-05-01") 120 req.Raw().URL.RawQuery = reqQP.Encode() 121 req.Raw().Header["Accept"] = []string{"application/json"} 122 if err := runtime.MarshalAsJSON(req, parameters); err != nil { 123 return nil, err 124 } 125 return req, nil 126 } 127 128 // BeginDelete - Deletes the specified load balancer. 129 // If the operation fails it returns an *azcore.ResponseError type. 130 // 131 // Generated from API version 2024-05-01 132 // - resourceGroupName - The name of the resource group. 133 // - loadBalancerName - The name of the load balancer. 134 // - options - LoadBalancersClientBeginDeleteOptions contains the optional parameters for the LoadBalancersClient.BeginDelete 135 // method. 136 func (client *LoadBalancersClient) BeginDelete(ctx context.Context, resourceGroupName string, loadBalancerName string, options *LoadBalancersClientBeginDeleteOptions) (*runtime.Poller[LoadBalancersClientDeleteResponse], error) { 137 if options == nil || options.ResumeToken == "" { 138 resp, err := client.deleteOperation(ctx, resourceGroupName, loadBalancerName, options) 139 if err != nil { 140 return nil, err 141 } 142 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LoadBalancersClientDeleteResponse]{ 143 FinalStateVia: runtime.FinalStateViaLocation, 144 Tracer: client.internal.Tracer(), 145 }) 146 return poller, err 147 } else { 148 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[LoadBalancersClientDeleteResponse]{ 149 Tracer: client.internal.Tracer(), 150 }) 151 } 152 } 153 154 // Delete - Deletes the specified load balancer. 155 // If the operation fails it returns an *azcore.ResponseError type. 156 // 157 // Generated from API version 2024-05-01 158 func (client *LoadBalancersClient) deleteOperation(ctx context.Context, resourceGroupName string, loadBalancerName string, options *LoadBalancersClientBeginDeleteOptions) (*http.Response, error) { 159 var err error 160 const operationName = "LoadBalancersClient.BeginDelete" 161 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 162 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 163 defer func() { endSpan(err) }() 164 req, err := client.deleteCreateRequest(ctx, resourceGroupName, loadBalancerName, options) 165 if err != nil { 166 return nil, err 167 } 168 httpResp, err := client.internal.Pipeline().Do(req) 169 if err != nil { 170 return nil, err 171 } 172 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted, http.StatusNoContent) { 173 err = runtime.NewResponseError(httpResp) 174 return nil, err 175 } 176 return httpResp, nil 177 } 178 179 // deleteCreateRequest creates the Delete request. 180 func (client *LoadBalancersClient) deleteCreateRequest(ctx context.Context, resourceGroupName string, loadBalancerName string, options *LoadBalancersClientBeginDeleteOptions) (*policy.Request, error) { 181 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}" 182 if resourceGroupName == "" { 183 return nil, errors.New("parameter resourceGroupName cannot be empty") 184 } 185 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 186 if loadBalancerName == "" { 187 return nil, errors.New("parameter loadBalancerName cannot be empty") 188 } 189 urlPath = strings.ReplaceAll(urlPath, "{loadBalancerName}", url.PathEscape(loadBalancerName)) 190 if client.subscriptionID == "" { 191 return nil, errors.New("parameter client.subscriptionID cannot be empty") 192 } 193 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 194 req, err := runtime.NewRequest(ctx, http.MethodDelete, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 195 if err != nil { 196 return nil, err 197 } 198 reqQP := req.Raw().URL.Query() 199 reqQP.Set("api-version", "2024-05-01") 200 req.Raw().URL.RawQuery = reqQP.Encode() 201 req.Raw().Header["Accept"] = []string{"application/json"} 202 return req, nil 203 } 204 205 // Get - Gets the specified load balancer. 206 // If the operation fails it returns an *azcore.ResponseError type. 207 // 208 // Generated from API version 2024-05-01 209 // - resourceGroupName - The name of the resource group. 210 // - loadBalancerName - The name of the load balancer. 211 // - options - LoadBalancersClientGetOptions contains the optional parameters for the LoadBalancersClient.Get method. 212 func (client *LoadBalancersClient) Get(ctx context.Context, resourceGroupName string, loadBalancerName string, options *LoadBalancersClientGetOptions) (LoadBalancersClientGetResponse, error) { 213 var err error 214 const operationName = "LoadBalancersClient.Get" 215 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 216 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 217 defer func() { endSpan(err) }() 218 req, err := client.getCreateRequest(ctx, resourceGroupName, loadBalancerName, options) 219 if err != nil { 220 return LoadBalancersClientGetResponse{}, err 221 } 222 httpResp, err := client.internal.Pipeline().Do(req) 223 if err != nil { 224 return LoadBalancersClientGetResponse{}, err 225 } 226 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 227 err = runtime.NewResponseError(httpResp) 228 return LoadBalancersClientGetResponse{}, err 229 } 230 resp, err := client.getHandleResponse(httpResp) 231 return resp, err 232 } 233 234 // getCreateRequest creates the Get request. 235 func (client *LoadBalancersClient) getCreateRequest(ctx context.Context, resourceGroupName string, loadBalancerName string, options *LoadBalancersClientGetOptions) (*policy.Request, error) { 236 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}" 237 if resourceGroupName == "" { 238 return nil, errors.New("parameter resourceGroupName cannot be empty") 239 } 240 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 241 if loadBalancerName == "" { 242 return nil, errors.New("parameter loadBalancerName cannot be empty") 243 } 244 urlPath = strings.ReplaceAll(urlPath, "{loadBalancerName}", url.PathEscape(loadBalancerName)) 245 if client.subscriptionID == "" { 246 return nil, errors.New("parameter client.subscriptionID cannot be empty") 247 } 248 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 249 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 250 if err != nil { 251 return nil, err 252 } 253 reqQP := req.Raw().URL.Query() 254 if options != nil && options.Expand != nil { 255 reqQP.Set("$expand", *options.Expand) 256 } 257 reqQP.Set("api-version", "2024-05-01") 258 req.Raw().URL.RawQuery = reqQP.Encode() 259 req.Raw().Header["Accept"] = []string{"application/json"} 260 return req, nil 261 } 262 263 // getHandleResponse handles the Get response. 264 func (client *LoadBalancersClient) getHandleResponse(resp *http.Response) (LoadBalancersClientGetResponse, error) { 265 result := LoadBalancersClientGetResponse{} 266 if err := runtime.UnmarshalAsJSON(resp, &result.LoadBalancer); err != nil { 267 return LoadBalancersClientGetResponse{}, err 268 } 269 return result, nil 270 } 271 272 // NewListPager - Gets all the load balancers in a resource group. 273 // 274 // Generated from API version 2024-05-01 275 // - resourceGroupName - The name of the resource group. 276 // - options - LoadBalancersClientListOptions contains the optional parameters for the LoadBalancersClient.NewListPager method. 277 func (client *LoadBalancersClient) NewListPager(resourceGroupName string, options *LoadBalancersClientListOptions) *runtime.Pager[LoadBalancersClientListResponse] { 278 return runtime.NewPager(runtime.PagingHandler[LoadBalancersClientListResponse]{ 279 More: func(page LoadBalancersClientListResponse) bool { 280 return page.NextLink != nil && len(*page.NextLink) > 0 281 }, 282 Fetcher: func(ctx context.Context, page *LoadBalancersClientListResponse) (LoadBalancersClientListResponse, error) { 283 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "LoadBalancersClient.NewListPager") 284 nextLink := "" 285 if page != nil { 286 nextLink = *page.NextLink 287 } 288 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 289 return client.listCreateRequest(ctx, resourceGroupName, options) 290 }, nil) 291 if err != nil { 292 return LoadBalancersClientListResponse{}, err 293 } 294 return client.listHandleResponse(resp) 295 }, 296 Tracer: client.internal.Tracer(), 297 }) 298 } 299 300 // listCreateRequest creates the List request. 301 func (client *LoadBalancersClient) listCreateRequest(ctx context.Context, resourceGroupName string, options *LoadBalancersClientListOptions) (*policy.Request, error) { 302 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers" 303 if resourceGroupName == "" { 304 return nil, errors.New("parameter resourceGroupName cannot be empty") 305 } 306 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 307 if client.subscriptionID == "" { 308 return nil, errors.New("parameter client.subscriptionID cannot be empty") 309 } 310 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 311 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 312 if err != nil { 313 return nil, err 314 } 315 reqQP := req.Raw().URL.Query() 316 reqQP.Set("api-version", "2024-05-01") 317 req.Raw().URL.RawQuery = reqQP.Encode() 318 req.Raw().Header["Accept"] = []string{"application/json"} 319 return req, nil 320 } 321 322 // listHandleResponse handles the List response. 323 func (client *LoadBalancersClient) listHandleResponse(resp *http.Response) (LoadBalancersClientListResponse, error) { 324 result := LoadBalancersClientListResponse{} 325 if err := runtime.UnmarshalAsJSON(resp, &result.LoadBalancerListResult); err != nil { 326 return LoadBalancersClientListResponse{}, err 327 } 328 return result, nil 329 } 330 331 // NewListAllPager - Gets all the load balancers in a subscription. 332 // 333 // Generated from API version 2024-05-01 334 // - options - LoadBalancersClientListAllOptions contains the optional parameters for the LoadBalancersClient.NewListAllPager 335 // method. 336 func (client *LoadBalancersClient) NewListAllPager(options *LoadBalancersClientListAllOptions) *runtime.Pager[LoadBalancersClientListAllResponse] { 337 return runtime.NewPager(runtime.PagingHandler[LoadBalancersClientListAllResponse]{ 338 More: func(page LoadBalancersClientListAllResponse) bool { 339 return page.NextLink != nil && len(*page.NextLink) > 0 340 }, 341 Fetcher: func(ctx context.Context, page *LoadBalancersClientListAllResponse) (LoadBalancersClientListAllResponse, error) { 342 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, "LoadBalancersClient.NewListAllPager") 343 nextLink := "" 344 if page != nil { 345 nextLink = *page.NextLink 346 } 347 resp, err := runtime.FetcherForNextLink(ctx, client.internal.Pipeline(), nextLink, func(ctx context.Context) (*policy.Request, error) { 348 return client.listAllCreateRequest(ctx, options) 349 }, nil) 350 if err != nil { 351 return LoadBalancersClientListAllResponse{}, err 352 } 353 return client.listAllHandleResponse(resp) 354 }, 355 Tracer: client.internal.Tracer(), 356 }) 357 } 358 359 // listAllCreateRequest creates the ListAll request. 360 func (client *LoadBalancersClient) listAllCreateRequest(ctx context.Context, options *LoadBalancersClientListAllOptions) (*policy.Request, error) { 361 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/loadBalancers" 362 if client.subscriptionID == "" { 363 return nil, errors.New("parameter client.subscriptionID cannot be empty") 364 } 365 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 366 req, err := runtime.NewRequest(ctx, http.MethodGet, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 367 if err != nil { 368 return nil, err 369 } 370 reqQP := req.Raw().URL.Query() 371 reqQP.Set("api-version", "2024-05-01") 372 req.Raw().URL.RawQuery = reqQP.Encode() 373 req.Raw().Header["Accept"] = []string{"application/json"} 374 return req, nil 375 } 376 377 // listAllHandleResponse handles the ListAll response. 378 func (client *LoadBalancersClient) listAllHandleResponse(resp *http.Response) (LoadBalancersClientListAllResponse, error) { 379 result := LoadBalancersClientListAllResponse{} 380 if err := runtime.UnmarshalAsJSON(resp, &result.LoadBalancerListResult); err != nil { 381 return LoadBalancersClientListAllResponse{}, err 382 } 383 return result, nil 384 } 385 386 // BeginListInboundNatRulePortMappings - List of inbound NAT rule port mappings. 387 // If the operation fails it returns an *azcore.ResponseError type. 388 // 389 // Generated from API version 2024-05-01 390 // - groupName - The name of the resource group. 391 // - loadBalancerName - The name of the load balancer. 392 // - backendPoolName - The name of the load balancer backend address pool. 393 // - parameters - Query inbound NAT rule port mapping request. 394 // - options - LoadBalancersClientBeginListInboundNatRulePortMappingsOptions contains the optional parameters for the LoadBalancersClient.BeginListInboundNatRulePortMappings 395 // method. 396 func (client *LoadBalancersClient) BeginListInboundNatRulePortMappings(ctx context.Context, groupName string, loadBalancerName string, backendPoolName string, parameters QueryInboundNatRulePortMappingRequest, options *LoadBalancersClientBeginListInboundNatRulePortMappingsOptions) (*runtime.Poller[LoadBalancersClientListInboundNatRulePortMappingsResponse], error) { 397 if options == nil || options.ResumeToken == "" { 398 resp, err := client.listInboundNatRulePortMappings(ctx, groupName, loadBalancerName, backendPoolName, parameters, options) 399 if err != nil { 400 return nil, err 401 } 402 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LoadBalancersClientListInboundNatRulePortMappingsResponse]{ 403 FinalStateVia: runtime.FinalStateViaLocation, 404 Tracer: client.internal.Tracer(), 405 }) 406 return poller, err 407 } else { 408 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[LoadBalancersClientListInboundNatRulePortMappingsResponse]{ 409 Tracer: client.internal.Tracer(), 410 }) 411 } 412 } 413 414 // ListInboundNatRulePortMappings - List of inbound NAT rule port mappings. 415 // If the operation fails it returns an *azcore.ResponseError type. 416 // 417 // Generated from API version 2024-05-01 418 func (client *LoadBalancersClient) listInboundNatRulePortMappings(ctx context.Context, groupName string, loadBalancerName string, backendPoolName string, parameters QueryInboundNatRulePortMappingRequest, options *LoadBalancersClientBeginListInboundNatRulePortMappingsOptions) (*http.Response, error) { 419 var err error 420 const operationName = "LoadBalancersClient.BeginListInboundNatRulePortMappings" 421 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 422 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 423 defer func() { endSpan(err) }() 424 req, err := client.listInboundNatRulePortMappingsCreateRequest(ctx, groupName, loadBalancerName, backendPoolName, parameters, options) 425 if err != nil { 426 return nil, err 427 } 428 httpResp, err := client.internal.Pipeline().Do(req) 429 if err != nil { 430 return nil, err 431 } 432 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { 433 err = runtime.NewResponseError(httpResp) 434 return nil, err 435 } 436 return httpResp, nil 437 } 438 439 // listInboundNatRulePortMappingsCreateRequest creates the ListInboundNatRulePortMappings request. 440 func (client *LoadBalancersClient) listInboundNatRulePortMappingsCreateRequest(ctx context.Context, groupName string, loadBalancerName string, backendPoolName string, parameters QueryInboundNatRulePortMappingRequest, options *LoadBalancersClientBeginListInboundNatRulePortMappingsOptions) (*policy.Request, error) { 441 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}/backendAddressPools/{backendPoolName}/queryInboundNatRulePortMapping" 442 if groupName == "" { 443 return nil, errors.New("parameter groupName cannot be empty") 444 } 445 urlPath = strings.ReplaceAll(urlPath, "{groupName}", url.PathEscape(groupName)) 446 if loadBalancerName == "" { 447 return nil, errors.New("parameter loadBalancerName cannot be empty") 448 } 449 urlPath = strings.ReplaceAll(urlPath, "{loadBalancerName}", url.PathEscape(loadBalancerName)) 450 if backendPoolName == "" { 451 return nil, errors.New("parameter backendPoolName cannot be empty") 452 } 453 urlPath = strings.ReplaceAll(urlPath, "{backendPoolName}", url.PathEscape(backendPoolName)) 454 if client.subscriptionID == "" { 455 return nil, errors.New("parameter client.subscriptionID cannot be empty") 456 } 457 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 458 req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 459 if err != nil { 460 return nil, err 461 } 462 reqQP := req.Raw().URL.Query() 463 reqQP.Set("api-version", "2024-05-01") 464 req.Raw().URL.RawQuery = reqQP.Encode() 465 req.Raw().Header["Accept"] = []string{"application/json"} 466 if err := runtime.MarshalAsJSON(req, parameters); err != nil { 467 return nil, err 468 } 469 return req, nil 470 } 471 472 // MigrateToIPBased - Migrate load balancer to IP Based 473 // If the operation fails it returns an *azcore.ResponseError type. 474 // 475 // Generated from API version 2024-05-01 476 // - groupName - The name of the resource group. 477 // - loadBalancerName - The name of the load balancer. 478 // - options - LoadBalancersClientMigrateToIPBasedOptions contains the optional parameters for the LoadBalancersClient.MigrateToIPBased 479 // method. 480 func (client *LoadBalancersClient) MigrateToIPBased(ctx context.Context, groupName string, loadBalancerName string, options *LoadBalancersClientMigrateToIPBasedOptions) (LoadBalancersClientMigrateToIPBasedResponse, error) { 481 var err error 482 const operationName = "LoadBalancersClient.MigrateToIPBased" 483 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 484 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 485 defer func() { endSpan(err) }() 486 req, err := client.migrateToIPBasedCreateRequest(ctx, groupName, loadBalancerName, options) 487 if err != nil { 488 return LoadBalancersClientMigrateToIPBasedResponse{}, err 489 } 490 httpResp, err := client.internal.Pipeline().Do(req) 491 if err != nil { 492 return LoadBalancersClientMigrateToIPBasedResponse{}, err 493 } 494 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 495 err = runtime.NewResponseError(httpResp) 496 return LoadBalancersClientMigrateToIPBasedResponse{}, err 497 } 498 resp, err := client.migrateToIPBasedHandleResponse(httpResp) 499 return resp, err 500 } 501 502 // migrateToIPBasedCreateRequest creates the MigrateToIPBased request. 503 func (client *LoadBalancersClient) migrateToIPBasedCreateRequest(ctx context.Context, groupName string, loadBalancerName string, options *LoadBalancersClientMigrateToIPBasedOptions) (*policy.Request, error) { 504 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}/migrateToIpBased" 505 if groupName == "" { 506 return nil, errors.New("parameter groupName cannot be empty") 507 } 508 urlPath = strings.ReplaceAll(urlPath, "{groupName}", url.PathEscape(groupName)) 509 if loadBalancerName == "" { 510 return nil, errors.New("parameter loadBalancerName cannot be empty") 511 } 512 urlPath = strings.ReplaceAll(urlPath, "{loadBalancerName}", url.PathEscape(loadBalancerName)) 513 if client.subscriptionID == "" { 514 return nil, errors.New("parameter client.subscriptionID cannot be empty") 515 } 516 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 517 req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 518 if err != nil { 519 return nil, err 520 } 521 reqQP := req.Raw().URL.Query() 522 reqQP.Set("api-version", "2024-05-01") 523 req.Raw().URL.RawQuery = reqQP.Encode() 524 req.Raw().Header["Accept"] = []string{"application/json"} 525 if options != nil && options.Parameters != nil { 526 if err := runtime.MarshalAsJSON(req, *options.Parameters); err != nil { 527 return nil, err 528 } 529 return req, nil 530 } 531 return req, nil 532 } 533 534 // migrateToIPBasedHandleResponse handles the MigrateToIPBased response. 535 func (client *LoadBalancersClient) migrateToIPBasedHandleResponse(resp *http.Response) (LoadBalancersClientMigrateToIPBasedResponse, error) { 536 result := LoadBalancersClientMigrateToIPBasedResponse{} 537 if err := runtime.UnmarshalAsJSON(resp, &result.MigratedPools); err != nil { 538 return LoadBalancersClientMigrateToIPBasedResponse{}, err 539 } 540 return result, nil 541 } 542 543 // BeginSwapPublicIPAddresses - Swaps VIPs between two load balancers. 544 // If the operation fails it returns an *azcore.ResponseError type. 545 // 546 // Generated from API version 2024-05-01 547 // - location - The region where load balancers are located at. 548 // - parameters - Parameters that define which VIPs should be swapped. 549 // - options - LoadBalancersClientBeginSwapPublicIPAddressesOptions contains the optional parameters for the LoadBalancersClient.BeginSwapPublicIPAddresses 550 // method. 551 func (client *LoadBalancersClient) BeginSwapPublicIPAddresses(ctx context.Context, location string, parameters LoadBalancerVipSwapRequest, options *LoadBalancersClientBeginSwapPublicIPAddressesOptions) (*runtime.Poller[LoadBalancersClientSwapPublicIPAddressesResponse], error) { 552 if options == nil || options.ResumeToken == "" { 553 resp, err := client.swapPublicIPAddresses(ctx, location, parameters, options) 554 if err != nil { 555 return nil, err 556 } 557 poller, err := runtime.NewPoller(resp, client.internal.Pipeline(), &runtime.NewPollerOptions[LoadBalancersClientSwapPublicIPAddressesResponse]{ 558 FinalStateVia: runtime.FinalStateViaLocation, 559 Tracer: client.internal.Tracer(), 560 }) 561 return poller, err 562 } else { 563 return runtime.NewPollerFromResumeToken(options.ResumeToken, client.internal.Pipeline(), &runtime.NewPollerFromResumeTokenOptions[LoadBalancersClientSwapPublicIPAddressesResponse]{ 564 Tracer: client.internal.Tracer(), 565 }) 566 } 567 } 568 569 // SwapPublicIPAddresses - Swaps VIPs between two load balancers. 570 // If the operation fails it returns an *azcore.ResponseError type. 571 // 572 // Generated from API version 2024-05-01 573 func (client *LoadBalancersClient) swapPublicIPAddresses(ctx context.Context, location string, parameters LoadBalancerVipSwapRequest, options *LoadBalancersClientBeginSwapPublicIPAddressesOptions) (*http.Response, error) { 574 var err error 575 const operationName = "LoadBalancersClient.BeginSwapPublicIPAddresses" 576 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 577 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 578 defer func() { endSpan(err) }() 579 req, err := client.swapPublicIPAddressesCreateRequest(ctx, location, parameters, options) 580 if err != nil { 581 return nil, err 582 } 583 httpResp, err := client.internal.Pipeline().Do(req) 584 if err != nil { 585 return nil, err 586 } 587 if !runtime.HasStatusCode(httpResp, http.StatusOK, http.StatusAccepted) { 588 err = runtime.NewResponseError(httpResp) 589 return nil, err 590 } 591 return httpResp, nil 592 } 593 594 // swapPublicIPAddressesCreateRequest creates the SwapPublicIPAddresses request. 595 func (client *LoadBalancersClient) swapPublicIPAddressesCreateRequest(ctx context.Context, location string, parameters LoadBalancerVipSwapRequest, options *LoadBalancersClientBeginSwapPublicIPAddressesOptions) (*policy.Request, error) { 596 urlPath := "/subscriptions/{subscriptionId}/providers/Microsoft.Network/locations/{location}/setLoadBalancerFrontendPublicIpAddresses" 597 if location == "" { 598 return nil, errors.New("parameter location cannot be empty") 599 } 600 urlPath = strings.ReplaceAll(urlPath, "{location}", url.PathEscape(location)) 601 if client.subscriptionID == "" { 602 return nil, errors.New("parameter client.subscriptionID cannot be empty") 603 } 604 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 605 req, err := runtime.NewRequest(ctx, http.MethodPost, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 606 if err != nil { 607 return nil, err 608 } 609 reqQP := req.Raw().URL.Query() 610 reqQP.Set("api-version", "2024-05-01") 611 req.Raw().URL.RawQuery = reqQP.Encode() 612 req.Raw().Header["Accept"] = []string{"application/json"} 613 if err := runtime.MarshalAsJSON(req, parameters); err != nil { 614 return nil, err 615 } 616 return req, nil 617 } 618 619 // UpdateTags - Updates a load balancer tags. 620 // If the operation fails it returns an *azcore.ResponseError type. 621 // 622 // Generated from API version 2024-05-01 623 // - resourceGroupName - The name of the resource group. 624 // - loadBalancerName - The name of the load balancer. 625 // - parameters - Parameters supplied to update load balancer tags. 626 // - options - LoadBalancersClientUpdateTagsOptions contains the optional parameters for the LoadBalancersClient.UpdateTags 627 // method. 628 func (client *LoadBalancersClient) UpdateTags(ctx context.Context, resourceGroupName string, loadBalancerName string, parameters TagsObject, options *LoadBalancersClientUpdateTagsOptions) (LoadBalancersClientUpdateTagsResponse, error) { 629 var err error 630 const operationName = "LoadBalancersClient.UpdateTags" 631 ctx = context.WithValue(ctx, runtime.CtxAPINameKey{}, operationName) 632 ctx, endSpan := runtime.StartSpan(ctx, operationName, client.internal.Tracer(), nil) 633 defer func() { endSpan(err) }() 634 req, err := client.updateTagsCreateRequest(ctx, resourceGroupName, loadBalancerName, parameters, options) 635 if err != nil { 636 return LoadBalancersClientUpdateTagsResponse{}, err 637 } 638 httpResp, err := client.internal.Pipeline().Do(req) 639 if err != nil { 640 return LoadBalancersClientUpdateTagsResponse{}, err 641 } 642 if !runtime.HasStatusCode(httpResp, http.StatusOK) { 643 err = runtime.NewResponseError(httpResp) 644 return LoadBalancersClientUpdateTagsResponse{}, err 645 } 646 resp, err := client.updateTagsHandleResponse(httpResp) 647 return resp, err 648 } 649 650 // updateTagsCreateRequest creates the UpdateTags request. 651 func (client *LoadBalancersClient) updateTagsCreateRequest(ctx context.Context, resourceGroupName string, loadBalancerName string, parameters TagsObject, options *LoadBalancersClientUpdateTagsOptions) (*policy.Request, error) { 652 urlPath := "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/loadBalancers/{loadBalancerName}" 653 if resourceGroupName == "" { 654 return nil, errors.New("parameter resourceGroupName cannot be empty") 655 } 656 urlPath = strings.ReplaceAll(urlPath, "{resourceGroupName}", url.PathEscape(resourceGroupName)) 657 if loadBalancerName == "" { 658 return nil, errors.New("parameter loadBalancerName cannot be empty") 659 } 660 urlPath = strings.ReplaceAll(urlPath, "{loadBalancerName}", url.PathEscape(loadBalancerName)) 661 if client.subscriptionID == "" { 662 return nil, errors.New("parameter client.subscriptionID cannot be empty") 663 } 664 urlPath = strings.ReplaceAll(urlPath, "{subscriptionId}", url.PathEscape(client.subscriptionID)) 665 req, err := runtime.NewRequest(ctx, http.MethodPatch, runtime.JoinPaths(client.internal.Endpoint(), urlPath)) 666 if err != nil { 667 return nil, err 668 } 669 reqQP := req.Raw().URL.Query() 670 reqQP.Set("api-version", "2024-05-01") 671 req.Raw().URL.RawQuery = reqQP.Encode() 672 req.Raw().Header["Accept"] = []string{"application/json"} 673 if err := runtime.MarshalAsJSON(req, parameters); err != nil { 674 return nil, err 675 } 676 return req, nil 677 } 678 679 // updateTagsHandleResponse handles the UpdateTags response. 680 func (client *LoadBalancersClient) updateTagsHandleResponse(resp *http.Response) (LoadBalancersClientUpdateTagsResponse, error) { 681 result := LoadBalancersClientUpdateTagsResponse{} 682 if err := runtime.UnmarshalAsJSON(resp, &result.LoadBalancer); err != nil { 683 return LoadBalancersClientUpdateTagsResponse{}, err 684 } 685 return result, nil 686 }