Batch Creating Load Balancers
Function
This API is used to create dedicated or shared load balancers in batches.
When you create load balancers, note the following:
-
Specify vip_subnet_cidr_id if you want to bind private IPv4 addresses to the load balancers.
-
Specify publicip and either vpc_id or vip_subnet_cidr_id if you want to bind new IPv4 EIPs to the load balancers.
-
Specify publicip_ids and either vpc_id or vip_subnet_cidr_id if you want to bind existing IPv4 EIPs to the load balancers.
-
Specify ipv6_vip_virsubnet_id if you want to bind private IPv6 addresses to the load balancers.
-
Specify both ipv6_vip_virsubnet_id and ipv6_bandwidth if you want to bind public IPv6 addresses to the load balancers.
-
Specify l4_flavor_id if you want to create network load balancers and l7_flavor_id to create application load balancers. Specify both l4_flavor_id and l7_flavor_id if you want to create load balancers that can work at both Layer 4 and Layer 7.
-
Do not specify publicip_ids, vip_address, or ipv6_vip_address when creating load balancers in batches. You cannot bind existing private IPv4 addresses, IPv6 addresses, or public IP addresses to the load balancers.
-
If prepaid_options is not specified, pay-per-use load balancers will be created, which are billed by fixed specifications or elastic specifications you have selected for l4_flavor_id and l7_flavor_id when creating the load balancers.
-
This is an asynchronous API, returning load balancer IDs and job IDs in its response body. You can use the job ID to query the load balancer creation progress.
-
The rules for specifying parameters in the request body are different when you create dedicated and shared load balancers in batches. For details, see the description of each parameter in the request body.
Constraints
There are some constraints when you create load balancers:
-
vpc_id, vip_subnet_cidr_id, and ipv6_vip_virsubnet_id cannot be left blank at the same time.
-
If the value of number is greater than 1, do not specify publicip_ids, vip_address, and ipv6_vip_address.
-
ip_target_enable specifies whether to enable IP as a Backend. If you set it to true, you can associate servers in a VPC connected through a VPC peering connection, in a VPC connected through a cloud connection, or in an on-premises data center at the other end of a Direct Connect or VPN connection, by using server IP addresses. If you set it to false, the load balancer and the backend servers must be in the same VPC.
-
admin_state_up must be true.
-
provider must be set to vlb.
-
elb_virsubnet_ids indicates the subnets that support IPv4/IPv6 dual stack or only IPv4. If only IPv4 subnets are supported, ipv6_vip_virsubnet_id must be left blank.
-
If you bind an EIP to the load balancer during creation, you cannot unbind it from the load balancer by calling the API after the load balancer is created. Instead, you can unbind the EIP only on the ELB console. Locate the load balancer in the load balancer list and click More > Unbind EIP in the Operation column.
-
publicip_ids and publicip cannot be specified at the same time. Set either publicip_ids to bind an existing EIP to the load balancer, or publicip to bind a new EIP to the load balancer, or neither of them.
-
If you want to add the load balancer to a shared bandwidth, you must specify the ID of the shared bandwidth. If you want the load balancer to use a new dedicated bandwidth, charge_mode, share_type, and size are required.
-
You cannot bind an existing and unoccupied private IPv4 address, IPv6 address, or public IPv6 address to load balancers.
Calling Method
For details, see Calling APIs.
URI
POST /v3/{project_id}/elb/loadbalancers/batch-create
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Specifies the ID of the project where the load balancer is used. |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
No |
String |
Specifies the token used for IAM authentication. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
loadbalancer |
Yes |
Specifies the load balancer. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
id |
No |
String |
Specifies the ID of the load balancer. This parameter is unsupported. Please do not use it. |
ids |
No |
Array of strings |
Specifies the IDs of the load balancers created in batches. This parameter is unsupported. Please do not use it. |
project_id |
No |
String |
Specifies the ID of the project where the load balancer is used. |
number |
No |
Integer |
Specifies the number of load balancers to be created. |
name |
No |
String |
Specifies the load balancer names. Note:
For example, if you create three load balancers and set name to elb-test, the names of these load balancers are elb-test-0001, elb-test-0002, and elb-test-0003. |
description |
No |
String |
Specifies the descriptions of these load balancers. |
vip_address |
No |
String |
Specifies the virtual IPv4 address bound to the load balancer. The IP address must be from the IPv4 subnet where the load balancer resides and should not be used by other services. Note:
|
vip_subnet_cidr_id |
No |
String |
Specifies the ID of the IPv4 subnet where the load balancer works. This parameter is mandatory if you need to create a load balancer with a virtual IPv4 address. You can query parameter neutron_subnet_id in the response by calling the API (GET https://{VPC_Endpoint}/v1/{project_id}/subnets) Note:
|
ipv6_vip_virsubnet_id |
No |
String |
Specifies the ID of the IPv6 subnet where the load balancer works. You can query parameter neutron_network_id in the response by calling the API (GET https://{VPC_Endpoint}/v1/{project_id}/subnets). Note:
|
provider |
No |
String |
Specifies the provider of the load balancer. The value is fixed to vlb. This parameter cannot be specified when shared load balancers are created in batches. |
l4_flavor_id |
No |
String |
Specifies the flavor ID of the network load balancer. Note:
|
l7_flavor_id |
No |
String |
Specifies the flavor ID of the application load balancer. Note:
|
guaranteed |
No |
Boolean |
Specifies whether to create dedicated or shared load balancers. Value options:
Default value: true |
vpc_id |
No |
String |
Specifies the ID of the VPC where the load balancer resides. You can query parameter id in the response by calling the API (GET https://{VPC_Endpoint}/v1/{project_id}/vpcs). Note:
|
availability_zone_list |
Yes |
Array of strings |
Specifies the list of AZs where the load balancer can be created. You can query the AZs by calling the API (GET https://{ELB_Endpoint}/v3/{project_id}/elb/availability-zones). Select one or more AZs in the same set. Note: This parameter cannot be specified when shared load balancers are created in batches. |
enterprise_project_id |
No |
String |
Specifies the ID of the enterprise project where the load balancer is used. The value cannot be "", "0", or the ID of an enterprise project that does not exist. If this parameter is not passed during resource creation, the resource belongs to the default enterprise project, and 0 will be returned. |
tags |
No |
Array of Tag objects |
Specifies the tags added to the load balancer. Example: "tags":[{"key":"my_tag","value":"my_tag_value"}] |
admin_state_up |
No |
Boolean |
Specifies whether the load balancer is enabled. Value options:
Default value: true |
ipv6_bandwidth |
No |
BandwidthRef object |
This parameter cannot be specified when shared load balancers are created in batches. |
bandwidth |
No |
BandwidthRef object |
This parameter cannot be specified when dedicated load balancers are created in batches. |
publicip_ids |
No |
Array of strings |
Specifies the ID of the EIP bound to the load balancer. Only the first EIP in the array will be bound. If the value of number is greater than 1, this parameter cannot be specified and error code 400 will be returned. |
publicip |
No |
Specifies the new EIP that will be bound to the load balancer. |
|
elb_virsubnet_ids |
No |
Array of strings |
Specifies the IDs of subnets on the downstream plane. You can query parameter neutron_network_id in the response by calling the API (GET https://{VPC_Endpoint}/v1/{project_id}/subnets). If this parameter is not specified, the subnet IDs will be used based on the following rules:
If there is more than one subnet, the first subnet in the list will be used to assign IP addresses. The subnets must be in the VPC where the load balancer works. |
ip_target_enable |
No |
Boolean |
Specifies whether to add backend servers that are not in the load balancer's VPC. If you enable this function, you can add servers in a peer VPC connected through a VPC peering connection, servers in other public clouds, or servers in an on-premises data center at the other end of a Direct Connect or VPN connection, by using their IP addresses. Value options:
Note:
|
deletion_protection_enable |
No |
Boolean |
Specifies whether to enable deletion protection. This parameter cannot be specified when shared load balancers are created in batches. Value options:
Disable deletion protection for all your resources before deleting your account. |
autoscaling |
No |
Specifies information about elastic scaling. If elastic scaling is enabled, the load balancer specifications can be automatically adjusted based on incoming traffic. Note:
|
|
waf_failure_action |
No |
String |
Specifies traffic distributing policies when the WAF is faulty.
Note: This parameter takes effect only when WAF is enabled for the load balancer. |
protection_status |
No |
String |
Specifies the protection status. Value options:
|
protection_reason |
No |
String |
Specifies why the modification protection is enabled. Note: This parameter is valid only when protection_status is set to consoleProtection. The value can contain a maximum of 255 Unicode characters, excluding angle brackets (<>). |
ipv6_vip_address |
No |
String |
Specifies the IPv6 address bound to the load balancer. If the value of number is greater than 1, this parameter cannot be specified and error code 400 will be returned. This parameter cannot be specified when shared load balancers are created in batches. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
key |
No |
String |
Specifies the tag key. |
value |
No |
String |
Specifies the tag value. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
id |
Yes |
String |
Specifies the shared bandwidth ID. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
ip_version |
No |
Integer |
Specifies the IP address version. The value can be 4 (IPv4) or 6 (IPv6). The default value is 4. |
network_type |
Yes |
String |
Specifies the EIP type. The default value is 5_bgp. For more information, see the API for assigning an EIP in the Virtual Private Cloud API Reference. |
billing_info |
No |
String |
Provides billing information about the EIP.
This parameter is unsupported. Please do not use it. |
description |
No |
String |
Provides supplementary information about the EIP. |
bandwidth |
Yes |
Provides supplementary information about the bandwidth. |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
name |
No |
String |
Specifies the bandwidth name. The value can contain 1 to 64 characters, including letters, digits, underscores (_), hyphens (-), and periods. Note:
|
size |
No |
Integer |
Specifies the bandwidth range. The default bandwidth range is 1 Mbit/s to 2,000 Mbit/s, which may vary by region and can be viewed on the management console. Note:
|
charge_mode |
No |
String |
Specifies how the bandwidth used by the EIP is billed.
This parameter is mandatory if id is set to null. |
share_type |
No |
String |
Specifies the bandwidth type. Value options:
Note:
|
billing_info |
No |
String |
Specifies bandwidth billing information. Note: This parameter is unsupported. Please do not use it. |
id |
No |
String |
Specifies the ID of the shared bandwidth to which the IP address bound to the load balancer is added. Note:
|
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
enable |
Yes |
Boolean |
Specifies whether to enable elastic scaling for the load balancer. The value can be true (elastic scaling enabled) or false (elastic scaling disabled). |
min_l7_flavor_id |
No |
String |
Specifies the ID of the minimum elastic flavor at Layer 7. This parameter cannot be left blank if there are HTTP or HTTPS listeners. |
Response Parameters
Status code: 202
Parameter |
Type |
Description |
---|---|---|
loadbalancer_ids |
Array of strings |
Specifies the IDs of the load balancers created in batches. |
job_id |
String |
Specifies task ID of the batch creation. |
request_id |
String |
Specifies the request ID. Note: The value is automatically generated. |
Example Requests
-
Example 1: Creating three pay-per-use, dedicated load balancers and binding private IPv4 addresses to them
POST https://{ELB_Endpoint}/v3/060576798a80d5762fafc01a9b5eedc7/elb/loadbalancers/batch-create { "loadbalancer" : { "name" : "loadbalancer", "description" : "simple batch create lb", "vip_subnet_cidr_id" : "1992ec06-f364-4ae3-b936-6a8cc24633b7", "admin_state_up" : true, "availability_zone_list" : [ "AZ1" ], "number" : 3 } }
-
Example 1: Creating three shared load balancers and binding private IPv4 addresses to them
POST https://{ELB_Endpoint}/v3/060576798a80d5762fafc01a9b5eedc7/elb/loadbalancers/batch-create { "loadbalancer" : { "name" : "loadbalancer", "description" : "simple batch create lb", "availability_zone_list" : [ "AZ1" ], "vip_subnet_cidr_id" : "1992ec06-f364-4ae3-b936-6a8cc24633b7", "admin_state_up" : true, "guaranteed" : false, "number" : 3 } }
Example Responses
Status code: 202
Normal response
{ "job_id" : "060576798a80d5762fafc01a9b5eedc7", "loadbalancer_ids" : [ "de7946ba-3b77-4119-8338-acc25eb05611", "ba27f70b-b52f-4a77-9220-fd15726e50bd" ], "request_id" : "bf29597181cb81b30d19f1a0115a157d" }
SDK Sample Code
The SDK sample code is as follows.
-
Example 1: Creating three pay-per-use, dedicated load balancers and binding private IPv4 addresses to them
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.elb.v3.region.ElbRegion; import com.huaweicloud.sdk.elb.v3.*; import com.huaweicloud.sdk.elb.v3.model.*; import java.util.List; import java.util.ArrayList; public class BatchCreateLoadBalancersSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); ElbClient client = ElbClient.newBuilder() .withCredential(auth) .withRegion(ElbRegion.valueOf("<YOUR REGION>")) .build(); BatchCreateLoadBalancersRequest request = new BatchCreateLoadBalancersRequest(); BatchCreateLoadBalancersRequestBody body = new BatchCreateLoadBalancersRequestBody(); List<String> listLoadbalancerAvailabilityZoneList = new ArrayList<>(); listLoadbalancerAvailabilityZoneList.add("AZ1"); BatchCreateLoadBalancerOption loadbalancerbody = new BatchCreateLoadBalancerOption(); loadbalancerbody.withNumber(3) .withName("loadbalancer") .withDescription("simple batch create lb") .withVipSubnetCidrId("1992ec06-f364-4ae3-b936-6a8cc24633b7") .withAvailabilityZoneList(listLoadbalancerAvailabilityZoneList) .withAdminStateUp(true); body.withLoadbalancer(loadbalancerbody); request.withBody(body); try { BatchCreateLoadBalancersResponse response = client.batchCreateLoadBalancers(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } }
-
Example 1: Creating three shared load balancers and binding private IPv4 addresses to them
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.elb.v3.region.ElbRegion; import com.huaweicloud.sdk.elb.v3.*; import com.huaweicloud.sdk.elb.v3.model.*; import java.util.List; import java.util.ArrayList; public class BatchCreateLoadBalancersSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); ElbClient client = ElbClient.newBuilder() .withCredential(auth) .withRegion(ElbRegion.valueOf("<YOUR REGION>")) .build(); BatchCreateLoadBalancersRequest request = new BatchCreateLoadBalancersRequest(); BatchCreateLoadBalancersRequestBody body = new BatchCreateLoadBalancersRequestBody(); List<String> listLoadbalancerAvailabilityZoneList = new ArrayList<>(); listLoadbalancerAvailabilityZoneList.add("AZ1"); BatchCreateLoadBalancerOption loadbalancerbody = new BatchCreateLoadBalancerOption(); loadbalancerbody.withNumber(3) .withName("loadbalancer") .withDescription("simple batch create lb") .withVipSubnetCidrId("1992ec06-f364-4ae3-b936-6a8cc24633b7") .withGuaranteed(false) .withAvailabilityZoneList(listLoadbalancerAvailabilityZoneList) .withAdminStateUp(true); body.withLoadbalancer(loadbalancerbody); request.withBody(body); try { BatchCreateLoadBalancersResponse response = client.batchCreateLoadBalancers(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } }
-
Example 1: Creating three pay-per-use, dedicated load balancers and binding private IPv4 addresses to them
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkelb.v3.region.elb_region import ElbRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkelb.v3 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = ElbClient.new_builder() \ .with_credentials(credentials) \ .with_region(ElbRegion.value_of("<YOUR REGION>")) \ .build() try: request = BatchCreateLoadBalancersRequest() listAvailabilityZoneListLoadbalancer = [ "AZ1" ] loadbalancerbody = BatchCreateLoadBalancerOption( number=3, name="loadbalancer", description="simple batch create lb", vip_subnet_cidr_id="1992ec06-f364-4ae3-b936-6a8cc24633b7", availability_zone_list=listAvailabilityZoneListLoadbalancer, admin_state_up=True ) request.body = BatchCreateLoadBalancersRequestBody( loadbalancer=loadbalancerbody ) response = client.batch_create_load_balancers(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
-
Example 1: Creating three shared load balancers and binding private IPv4 addresses to them
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkelb.v3.region.elb_region import ElbRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkelb.v3 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = ElbClient.new_builder() \ .with_credentials(credentials) \ .with_region(ElbRegion.value_of("<YOUR REGION>")) \ .build() try: request = BatchCreateLoadBalancersRequest() listAvailabilityZoneListLoadbalancer = [ "AZ1" ] loadbalancerbody = BatchCreateLoadBalancerOption( number=3, name="loadbalancer", description="simple batch create lb", vip_subnet_cidr_id="1992ec06-f364-4ae3-b936-6a8cc24633b7", guaranteed=False, availability_zone_list=listAvailabilityZoneListLoadbalancer, admin_state_up=True ) request.body = BatchCreateLoadBalancersRequestBody( loadbalancer=loadbalancerbody ) response = client.batch_create_load_balancers(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
-
Example 1: Creating three pay-per-use, dedicated load balancers and binding private IPv4 addresses to them
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" elb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := elb.NewElbClient( elb.ElbClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.BatchCreateLoadBalancersRequest{} var listAvailabilityZoneListLoadbalancer = []string{ "AZ1", } numberLoadbalancer:= int32(3) nameLoadbalancer:= "loadbalancer" descriptionLoadbalancer:= "simple batch create lb" vipSubnetCidrIdLoadbalancer:= "1992ec06-f364-4ae3-b936-6a8cc24633b7" adminStateUpLoadbalancer:= true loadbalancerbody := &model.BatchCreateLoadBalancerOption{ Number: &numberLoadbalancer, Name: &nameLoadbalancer, Description: &descriptionLoadbalancer, VipSubnetCidrId: &vipSubnetCidrIdLoadbalancer, AvailabilityZoneList: listAvailabilityZoneListLoadbalancer, AdminStateUp: &adminStateUpLoadbalancer, } request.Body = &model.BatchCreateLoadBalancersRequestBody{ Loadbalancer: loadbalancerbody, } response, err := client.BatchCreateLoadBalancers(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
-
Example 1: Creating three shared load balancers and binding private IPv4 addresses to them
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" elb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := elb.NewElbClient( elb.ElbClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.BatchCreateLoadBalancersRequest{} var listAvailabilityZoneListLoadbalancer = []string{ "AZ1", } numberLoadbalancer:= int32(3) nameLoadbalancer:= "loadbalancer" descriptionLoadbalancer:= "simple batch create lb" vipSubnetCidrIdLoadbalancer:= "1992ec06-f364-4ae3-b936-6a8cc24633b7" guaranteedLoadbalancer:= false adminStateUpLoadbalancer:= true loadbalancerbody := &model.BatchCreateLoadBalancerOption{ Number: &numberLoadbalancer, Name: &nameLoadbalancer, Description: &descriptionLoadbalancer, VipSubnetCidrId: &vipSubnetCidrIdLoadbalancer, Guaranteed: &guaranteedLoadbalancer, AvailabilityZoneList: listAvailabilityZoneListLoadbalancer, AdminStateUp: &adminStateUpLoadbalancer, } request.Body = &model.BatchCreateLoadBalancersRequestBody{ Loadbalancer: loadbalancerbody, } response, err := client.BatchCreateLoadBalancers(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
-
Example 1: Creating three pay-per-use, dedicated load balancers and binding private IPv4 addresses to them
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.elb.v3.region.ElbRegion; import com.huaweicloud.sdk.elb.v3.*; import com.huaweicloud.sdk.elb.v3.model.*; import java.util.List; import java.util.ArrayList; public class BatchCreateLoadBalancersSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); ElbClient client = ElbClient.newBuilder() .withCredential(auth) .withRegion(ElbRegion.valueOf("<YOUR REGION>")) .build(); BatchCreateLoadBalancersRequest request = new BatchCreateLoadBalancersRequest(); BatchCreateLoadBalancersRequestBody body = new BatchCreateLoadBalancersRequestBody(); List<String> listLoadbalancerAvailabilityZoneList = new ArrayList<>(); listLoadbalancerAvailabilityZoneList.add("AZ1"); BatchCreateLoadBalancerOption loadbalancerbody = new BatchCreateLoadBalancerOption(); loadbalancerbody.withNumber(3) .withName("loadbalancer") .withDescription("simple batch create lb") .withVipSubnetCidrId("1992ec06-f364-4ae3-b936-6a8cc24633b7") .withAvailabilityZoneList(listLoadbalancerAvailabilityZoneList) .withAdminStateUp(true); body.withLoadbalancer(loadbalancerbody); request.withBody(body); try { BatchCreateLoadBalancersResponse response = client.batchCreateLoadBalancers(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } }
-
Example 1: Creating three shared load balancers and binding private IPv4 addresses to them
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.elb.v3.region.ElbRegion; import com.huaweicloud.sdk.elb.v3.*; import com.huaweicloud.sdk.elb.v3.model.*; import java.util.List; import java.util.ArrayList; public class BatchCreateLoadBalancersSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); ElbClient client = ElbClient.newBuilder() .withCredential(auth) .withRegion(ElbRegion.valueOf("<YOUR REGION>")) .build(); BatchCreateLoadBalancersRequest request = new BatchCreateLoadBalancersRequest(); BatchCreateLoadBalancersRequestBody body = new BatchCreateLoadBalancersRequestBody(); List<String> listLoadbalancerAvailabilityZoneList = new ArrayList<>(); listLoadbalancerAvailabilityZoneList.add("AZ1"); BatchCreateLoadBalancerOption loadbalancerbody = new BatchCreateLoadBalancerOption(); loadbalancerbody.withNumber(3) .withName("loadbalancer") .withDescription("simple batch create lb") .withVipSubnetCidrId("1992ec06-f364-4ae3-b936-6a8cc24633b7") .withGuaranteed(false) .withAvailabilityZoneList(listLoadbalancerAvailabilityZoneList) .withAdminStateUp(true); body.withLoadbalancer(loadbalancerbody); request.withBody(body); try { BatchCreateLoadBalancersResponse response = client.batchCreateLoadBalancers(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } }
-
Example 1: Creating three pay-per-use, dedicated load balancers and binding private IPv4 addresses to them
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkelb.v3.region.elb_region import ElbRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkelb.v3 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = ElbClient.new_builder() \ .with_credentials(credentials) \ .with_region(ElbRegion.value_of("<YOUR REGION>")) \ .build() try: request = BatchCreateLoadBalancersRequest() listAvailabilityZoneListLoadbalancer = [ "AZ1" ] loadbalancerbody = BatchCreateLoadBalancerOption( number=3, name="loadbalancer", description="simple batch create lb", vip_subnet_cidr_id="1992ec06-f364-4ae3-b936-6a8cc24633b7", availability_zone_list=listAvailabilityZoneListLoadbalancer, admin_state_up=True ) request.body = BatchCreateLoadBalancersRequestBody( loadbalancer=loadbalancerbody ) response = client.batch_create_load_balancers(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
-
Example 1: Creating three shared load balancers and binding private IPv4 addresses to them
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkelb.v3.region.elb_region import ElbRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkelb.v3 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = ElbClient.new_builder() \ .with_credentials(credentials) \ .with_region(ElbRegion.value_of("<YOUR REGION>")) \ .build() try: request = BatchCreateLoadBalancersRequest() listAvailabilityZoneListLoadbalancer = [ "AZ1" ] loadbalancerbody = BatchCreateLoadBalancerOption( number=3, name="loadbalancer", description="simple batch create lb", vip_subnet_cidr_id="1992ec06-f364-4ae3-b936-6a8cc24633b7", guaranteed=False, availability_zone_list=listAvailabilityZoneListLoadbalancer, admin_state_up=True ) request.body = BatchCreateLoadBalancersRequestBody( loadbalancer=loadbalancerbody ) response = client.batch_create_load_balancers(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
-
Example 1: Creating three pay-per-use, dedicated load balancers and binding private IPv4 addresses to them
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" elb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := elb.NewElbClient( elb.ElbClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.BatchCreateLoadBalancersRequest{} var listAvailabilityZoneListLoadbalancer = []string{ "AZ1", } numberLoadbalancer:= int32(3) nameLoadbalancer:= "loadbalancer" descriptionLoadbalancer:= "simple batch create lb" vipSubnetCidrIdLoadbalancer:= "1992ec06-f364-4ae3-b936-6a8cc24633b7" adminStateUpLoadbalancer:= true loadbalancerbody := &model.BatchCreateLoadBalancerOption{ Number: &numberLoadbalancer, Name: &nameLoadbalancer, Description: &descriptionLoadbalancer, VipSubnetCidrId: &vipSubnetCidrIdLoadbalancer, AvailabilityZoneList: listAvailabilityZoneListLoadbalancer, AdminStateUp: &adminStateUpLoadbalancer, } request.Body = &model.BatchCreateLoadBalancersRequestBody{ Loadbalancer: loadbalancerbody, } response, err := client.BatchCreateLoadBalancers(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
-
Example 1: Creating three shared load balancers and binding private IPv4 addresses to them
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" elb "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/elb/v3/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := elb.NewElbClient( elb.ElbClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.BatchCreateLoadBalancersRequest{} var listAvailabilityZoneListLoadbalancer = []string{ "AZ1", } numberLoadbalancer:= int32(3) nameLoadbalancer:= "loadbalancer" descriptionLoadbalancer:= "simple batch create lb" vipSubnetCidrIdLoadbalancer:= "1992ec06-f364-4ae3-b936-6a8cc24633b7" guaranteedLoadbalancer:= false adminStateUpLoadbalancer:= true loadbalancerbody := &model.BatchCreateLoadBalancerOption{ Number: &numberLoadbalancer, Name: &nameLoadbalancer, Description: &descriptionLoadbalancer, VipSubnetCidrId: &vipSubnetCidrIdLoadbalancer, Guaranteed: &guaranteedLoadbalancer, AvailabilityZoneList: listAvailabilityZoneListLoadbalancer, AdminStateUp: &adminStateUpLoadbalancer, } request.Body = &model.BatchCreateLoadBalancersRequestBody{ Loadbalancer: loadbalancerbody, } response, err := client.BatchCreateLoadBalancers(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.
Status Codes
Status Code |
Description |
---|---|
202 |
Normal response |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot