更新时间:2025-08-26 GMT+08:00
分享

批量创建负载均衡器

功能介绍

批量创建独享型或者共享型负载均衡器,包括按需及包周期计费负载均衡器。

  • 若要创建内网IPv4负载均衡器,则需要传入vip_subnet_cidr_id。

  • 若要创建公网IPv4负载均衡器,则需要传入publicip,以及传入vpc_id和vip_subnet_cidr_id这两个参数中的一个。

  • 若要绑定有已有公网IPv4地址,则需要传入publicip_ids,以及传入vpc_id和vip_subnet_cidr_id这两个参数中的一个。

  • 若要创建内网双栈负载均衡器,则需要传入ipv6_vip_virsubnet_id。

  • 若要创建公网双栈负载均衡器,则需要传入ipv6_vip_virsubnet_id和ipv6_bandwidth。

  • 若要创建网络型负载均衡器,则需要传入l4_flavor_id(网络型规格ID);若要创建应用型负载均衡器,则需要传入l7_flavor_id(应用型规格ID);若要创建网络型+应用型负载均衡器,则需要传入l4_flavor_id和l7_flavor_id。

  • 如果批量创建的负载均衡器数量大于1,则不支持绑定已有的公网IP,且不支持指定ipv4和ipv6地址。即number大于1时,不支持传入publicip_ids,vip_address和ipv6_vip_address字段。

  • 若要创建包周期负载均衡器,则需要传入prepaid_options,否则创建按需计费负载均衡器。

  • 按需计费分为固定规格计费和弹性规格计费,根据创建时所选规格的类型决定计费方式。具体规格说明见创建LB请求参数l4_flavor_id和l7_flavor_id。

  • 异步接口,返回体中包含需要批量创建的负载均衡的ID列表和批量创建负载均衡器的job ID,可以通过job ID查询当前批量创建负载均衡器的进度。

  • 批量创建独享型和共享型实例时,请求体传参规则有所不同,具体见请求体说明中各个参数的解释。

接口约束

  • vpc_id 或 vip_subnet_cidr_id 或 ipv6_vip_virsubnet_id 不能同时为空。

  • number大于1时,不支持传入publicip_ids,vip_address和ipv6_vip_address字段。

  • ip_target_enable参数表示是否启用IP类型后端转发能力,启用IP类型后端转发的负载均衡器关联的member和VIP可以在不同VPC下,未启用IP类型后端转发的负载均衡器关联的member和VIP必须在同一个VPC下。

  • admin_state_up参数的值必须是true。

  • provider参数的值必须是vlb。

  • elb_virsubnet_ids参数对应的网络类型支持双栈或者只支持ipv4。网络类型为只支持ipv4时,ipv6_vip_virsubnet_id参数需要为空。

  • 只能通过ELB Console控制台来解绑EIP,在ELB列表查询页面选择操作列中的更多按钮->解绑EIP。

  • 创建LB时不能同时设置publicip_ids和publicip,只能选择绑定已有公网IP或者选择新建公网IP,或者都不设置这两个字段。

  • 若要绑定已有带宽,则需要设置共享带宽ID,不支持绑定独享带宽。若需要新建独享带宽,则带宽信息中charge_mode、share_type和size字段是必须的。

  • 不支持绑定已有未使用的内网IPv4、内网IPv6或公网IPv6地址。

调用方法

请参见如何调用API

URI

POST /v3/{project_id}/elb/loadbalancers/batch-create

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数解释:项目ID。获取方式请参见获取项目ID

约束限制:不涉及

取值范围:长度为32个字符,由小写字母和数字组成。

默认取值:不涉及

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

参数解释:IAM鉴权Token。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

表3 请求Body参数

参数

是否必选

参数类型

描述

loadbalancer

BatchCreateLoadBalancerOption object

参数解释:负载均衡器对象。

约束限制:不涉及

表4 BatchCreateLoadBalancerOption

参数

是否必选

参数类型

描述

id

String

参数解释:负载均衡器ID(UUID)。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

不支持该字段,请勿使用。

ids

Array of strings

参数解释:批创负载均衡器ID的列表(UUID)。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

不支持该字段,请勿使用。

project_id

String

参数解释:项目ID。获取方式请参见获取项目ID

约束限制:不涉及

取值范围:长度为32个字符,由小写字母和数字组成。

默认取值:不涉及

number

Integer

参数解释:批量创建负载均衡器的数量。

约束限制:不涉及

取值范围:1-10

默认取值:1

name

String

参数解释:负载均衡器的名称。

  • 当批创负载均衡器数量为1时,负载均衡器的名字即为该传入的值。

  • 当批创负载均衡器数量大于1时,负载均衡器的名字在传入的name后加上4位后缀。例如:批量创建3个负载均衡器,传入name为"elb-test",则三个负载均衡器名字分别为:"elb-test-0001","elb-test-0002","elb-test-0003"

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

description

String

参数解释:负载均衡器的描述。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

vip_address

String

参数解释:负载均衡器的IPv4私网IP。该地址必须包含在所在子网的IPv4网段内,且未被占用。

约束限制

  • 传入vip_address时必须传入vip_subnet_cidr_id。

  • 不传入vip_address,但传入vip_subnet_cidr_id,则自动分配IPv4私网IP。

  • 不传入vip_address,且不传vip_subnet_cidr_id,则不分配私网IP,vip_address=null。

  • 当批量创建的number数量大于1时不支持传入该字段,返回400。

取值范围:不涉及

默认取值:不涉及

vip_subnet_cidr_id

String

参数解释:负载均衡器所在子网的IPv4子网ID。若需要创建带IPv4私网IP的LB,该字段必须传入。

可以通过GET https://{VPC_Endpoint}/v1/{project_id}/subnets 响应参数中的neutron_subnet_id得到。

约束限制

  • vpc_id, vip_subnet_cidr_id, ipv6_vip_virsubnet_id不能同时为空,且需要在同一个vpc下。

  • 若同时传入vpc_id和vip_subnet_cidr_id,则vip_subnet_cidr_id对应的子网必须属于vpc_id对应的VPC。

取值范围:不涉及

默认取值:不涉及

ipv6_vip_virsubnet_id

String

参数解释:双栈类型负载均衡器所在子网的IPv6网络ID。

可以通过GET https://{VPC_Endpoint}/v1/{project_id}/subnets 响应参数中的neutron_network_id得到。

约束限制

  • vpc_id,vip_subnet_cidr_id,ipv6_vip_virsubnet_id不能同时为空,且需要在同一个vpc下。

  • 需要对应的子网开启IPv6。

  • 批量创建共享型实例时,该字段不允许指定。

取值范围:不涉及

默认取值:不涉及

provider

String

参数解释:负载均衡器的生产者名称。固定为vlb。

约束限制:批量创建共享型实例时,该字段不允许指定。

取值范围:不涉及

默认取值:不涉及

l4_flavor_id

String

参数解释:网络型规格ID。

可以通过GET https://{ELB_Endpoint}/v3/{project_id}/elb/flavors?type=L4 响应参数中的id得到。

约束限制

  • 当l4_flavor_id和l7_flavor_id都不传的时,会使用默认flavor

  • 当传入的规格类型为L4,表示该实例为固定规格实例,按规格计费。

  • 当传入的规格类型为L4_elastic_max,表示该实例为弹性实例,按LCU计费。

  • 批量创建共享型实例时,该字段不允许指定。

(默认flavor根据不同局点有所不同,具体以实际值为准)。

取值范围:不涉及

默认取值:不涉及

l7_flavor_id

String

参数解释:应用型规格ID。

可以通过GET https://{ELB_Endpoint}/v3/{project_id}/elb/flavors?type=L7 响应参数中的id得到。

约束限制

  • 当l4_flavor_id和l7_flavor_id都不传的时,会使用默认flavor

  • 当传入的规格类型为L7,表示该实例为固定规格实例,按规格计费。

  • 当传入的规格类型为L7_elastic_max,表示该实例为弹性实例,按LCU计费。

  • 批量创建共享型实例时,该字段不允许指定。

(默认flavor根据不同局点有所不同,具体以实际值为准)。

取值范围:不涉及

默认取值:不涉及

guaranteed

Boolean

参数解释:批量创建的是否是独享型负载均衡器。

约束限制:不涉及

取值范围

  • true:独享型。

  • false:共享型。

默认取值:true

vpc_id

String

参数解释:负载均衡器所在的VPC ID。

可以通过GET https://{VPC_Endpoint}/v1/{project_id}/vpcs 响应参数中的id得到。

约束限制

  • vpc_id,vip_subnet_cidr_id,ipv6_vip_virsubnet_id不能同时为空,且需要在同一个vpc下。

  • 批量创建共享型实例时,该字段不允许指定。

取值范围:不涉及

默认取值:不涉及

availability_zone_list

Array of strings

参数解释:可用区列表。

可通过GET https://{ELB_Endpoint}/v3/{project_id}/elb/availability-zones 接口来查询可用区集合列表。创建负载均衡器时,从查询结果选择某一个可用区集合,并从中选择一个或多个可用区。

约束限制

  • 批量创建共享型实例时,该字段不允许指定。

取值范围:不涉及

默认取值:不涉及

enterprise_project_id

String

参数解释:资源所属的企业项目ID。创建时不传则资源属于default企业项目,返回enterprise_project_id="0"。

约束限制:不能传入空字符串""、"0"或不存在的企业项目ID。

取值范围:不涉及

默认取值:"0"

tags

Array of Tag objects

参数解释:负载均衡的标签列表。示例:"tags":[{"key":"my_tag","value":"my_tag_value"}]

约束限制:不涉及

admin_state_up

Boolean

参数解释:负载均衡器的启用状态。

约束限制:不涉及

取值范围

  • true :启用。

  • false:停用。

默认取值:true。

billing_info

String

参数解释:资源账单信息。

约束限制:不涉及

取值范围

  • 空:按需计费。

  • 非空:包周期计费,格式为:order_id:product_id:region_id:project_id。如:CS2107161019CDJZZ:OFFI569702121789763584:az1:057ef081eb00d2732fd1c01a9be75e6f

默认取值:不涉及

ipv6_bandwidth

BandwidthRef object

参数解释:带宽对象ID。

约束限制

  • 仅在创建或更新公网负载均衡器时有效。

  • 若选择创建新EIP并指定共享带宽时,此EIP会被分进共享带宽里面。

bandwidth

BandwidthRef object

参数解释:带宽对象ID。

约束限制

  • 仅在创建或更新公网负载均衡器时有效。

  • 若选择创建新EIP并指定共享带宽时,此EIP会被分进共享带宽里面。

publicip_ids

Array of strings

参数解释:负载均衡器绑定的公网IP ID。只支持绑定数组中的第一个EIP,其他将被忽略。

当批量创建的number数量大于1时不支持传入该字段,返回400。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

publicip

CreateLoadBalancerPublicIpOption object

参数解释:创建ELB时,新建公网IP请求参数。

约束限制:不涉及

elb_virsubnet_ids

Array of strings

参数解释:下联面子网的网络ID列表。

可以通过GET https://{VPC_Endpoint}/v1/{project_id}/subnets 响应参数中的neutron_network_id得到。

若不指定该字段,则按如下规则选择下联面网络:

  1. 如果ELB实例开启ipv6,则选择ipv6_vip_virsubnet_id子网对应的网络ID。

  2. 如果ELB实例没有开启ipv6,开启ipv4,则选择vip_subnet_cidr_id子网对应的网络ID。

  3. 如果ELB实例没有选择私网,只开启公网,则会在当前负载均衡器所在的VPC中任意选一个子网,优选可用IP多的网络。

  4. 批量创建共享型实例的场景,该字段不允许指定。

若指定多个下联面子网,则按顺序优先使用第一个子网来为负载均衡器下联面端口分配ip地址。

约束限制:下联面子网必须属于该LB所在的VPC。

取值范围:不涉及

默认取值:不涉及

ip_target_enable

Boolean

参数解释:是否启用IP类型后端转发。

开启IP类型后端转发后,后端服务器组不仅支持添加云上VPC内的服务器,还支持添加其他VPC、其他公有云、云下数据中心的服务器。

约束限制

  • 开启后不能关闭。

  • 使用共享VPC的实例使用此特性时,需确保共享资源所有者已开通VPC对等连接,否则通信异常。

  • 仅独享型负载均衡器支持该特性。

取值范围

  • true:开启。

  • false:不开启。

默认取值:false

deletion_protection_enable

Boolean

参数解释:是否开启删除保护。

约束限制:批量创建共享型实例的场景,该字段不允许指定。

取值范围:false 不开启,true 开启。

默认取值:false

说明:
退场时需要先关闭所有资源的删除保护开关。

prepaid_options

PrepaidCreateOption object

参数解释:创建负载均衡器实例的预付费计费配置。若传入该结构体,则创建预付费类型的负载均衡器实例。

约束限制:不涉及

autoscaling

CreateLoadbalancerAutoscalingOption object

参数解释:弹性扩缩容配置信息。负载均衡器开启弹性扩缩容后,可根据负载情况自动调整负载均衡器的规格。

约束限制

  • 仅当项目白名单放开后该字段才有效

  • 开启弹性扩缩容后,l4_flavor_id和l7_flavor_id表示该LB实例弹性规格的上限。

说明:
该字段已经废弃,但仍然保留兼容性支持,建议不要使用该字段。如果传入该字段,创建的弹性实例将会有保底规格并产生对应保底规格的费用。

waf_failure_action

String

参数解释:WAF故障时的流量处理策略。

约束限制:只有绑定了waf的LB实例,该字段才会生效。

取值范围

  • discard:丢弃

  • forward: 转发到后端

默认取值:forward

protection_status

String

参数解释:修改保护状态。

约束限制:不涉及

取值范围

  • nonProtection: 不保护。

  • consoleProtection: 控制台修改保护。

默认取值:nonProtection

protection_reason

String

参数解释:设置保护的原因。作为protection_status的转态设置的原因。

约束限制:仅当protection_status为consoleProtection时有效。

取值范围:除<和>外通用Unicode字符集字符,最大255个字符。

默认取值:不涉及

charge_mode

String

参数解释:创建实例采用的计费模式。

约束限制:批量创建共享型实例时,该字段不允许指定。

取值范围

  • flavor:按实例规格收费。

  • lcu:按使用量收费。

默认取值:flavor

ipv6_vip_address

String

参数解释:双栈类型负载均衡器的IPv6地址。

约束限制

  • 当批量创建的number数量大于1时不支持传入该字段,返回400。

  • 批量创建共享型实例的场景,该字段不允许指定。

取值范围:不涉及

默认取值:不涉及

表5 Tag

参数

是否必选

参数类型

描述

key

String

参数解释:标签键。

取值范围:不涉及

value

String

参数解释:标签值。

取值范围:不涉及

表6 BandwidthRef

参数

是否必选

参数类型

描述

id

String

参数解释:共享带宽的ID。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

表7 CreateLoadBalancerPublicIpOption

参数

是否必选

参数类型

描述

ip_version

Integer

参数解释:IP版本。

约束限制:不涉及

取值范围

  • 4:表示IPv4。

  • 6:表示IPv6。

默认取值:4

network_type

String

参数解释:弹性公网IP的网络类型,默认5_bgp,更多请参考弹性公网ip创建。

约束限制:华南-深圳局点该参数取值只能为5_gray。

取值范围:5_bgp

默认取值:5_bgp

billing_info

String

参数解释:计费订单信息。

约束限制

  • 空:按需计费。

  • 非空:包周期计费。格式:order_id:product_id:region_id:project_id

取值范围:不涉及

默认取值:不涉及

description

String

参数解释:弹性公网IP的描述信息。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

bandwidth

CreateLoadBalancerBandwidthOption object

参数解释:带宽信息。

约束限制:不涉及

表8 CreateLoadBalancerBandwidthOption

参数

是否必选

参数类型

描述

name

String

参数解释:带宽名称。

约束限制

  • 如果share_type是PER,该字段是必选。

  • 如果bandwidth对象的id有值,该字段被忽略。

取值范围:1-64个字符,支持数字、字母、中文、_(下划线)、-(中划线)、.(点)

默认取值:不涉及

size

Integer

参数解释:带宽大小。

约束限制

  • 当id字段为null时,size是必须的。

  • 调整带宽时的最小单位会根据带宽范围不同存在差异。

    • 小于等于300Mbit/s: 默认最小单位为1Mbit/s。

    • 300Mbit/s~1000Mbit/s: 默认最小单位为50Mbit/s。

    • 大于1000Mbit/s: 默认最小单位为500Mbit/s。

取值范围:默认1Mbit/s~2000Mbit/s(具体范围以各区域配置为准,请参见控制台对应页面显示)。

默认取值:不涉及

charge_mode

String

参数解释:计费模式。

约束限制:当id字段为null时,charge_mode是必须的。

取值范围

  • bandwidth:按带宽计费。

  • traffic: 按流量计费。

默认取值:不涉及

share_type

String

参数解释:带宽类型。

约束限制

  • 当id字段为null时,share_type是必须的。当id不为null时,该字段被忽略。

  • 该字段为WHOLE时,必须指定带宽ID。

  • IPv6的EIP不支持WHOLE类型带宽。

取值范围

  • PER:独享带宽。

  • WHOLE:共享带宽。

默认取值:不涉及

billing_info

String

参数解释:资源计费信息。

约束限制

如果billing_info不为空,说明是包周期计费的带宽,否则为按需计费的带宽。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

id

String

参数解释:共享带宽ID。使用已存在的共享带宽。

约束限制:必须是已存在共享带宽ID。在预付费的情况下,不填该字段。该字段取空字符串时,会被忽略。

取值范围:不涉及

默认取值:不涉及

表9 PrepaidCreateOption

参数

是否必选

参数类型

描述

period_type

String

参数解释:预付费实例的订购周期类型,当前支持月和年。

约束限制:不涉及

取值范围

  • month:月

  • year:年

默认取值:不涉及

period_num

Integer

参数解释:预付费实例的订购周期数。

约束限制:不涉及

取值范围

  • period_type为month时,为[1,9]。

  • period_type为year时,为[1,3]。

默认取值:不涉及

auto_renew

Boolean

参数解释:自动续订开关。

约束限制:不涉及

取值范围

  • true:开启自动续订。

  • false:关闭自动续订。

默认取值:不涉及

auto_pay

Boolean

参数解释:自动支付开关。下单订购后,是否自动从客户的账户中支付。

约束限制:开启自动支付时,只能使用账户的现金支付;如果要使用代金券,请选择关闭自动支付,然后在用户费用中心,选择代金券支付。

取值范围

  • true:开启自动支付。

  • false:关闭自动支付。

默认取值:不涉及

表10 CreateLoadbalancerAutoscalingOption

参数

是否必选

参数类型

描述

enable

Boolean

参数解释:负载均衡器实例弹性扩缩容开关。

约束限制:不涉及

取值范围

  • true:开启。

  • false:关闭。

默认取值:不涉及

min_l7_flavor_id

String

参数解释:实例弹性扩缩容的最小七层规格ID。

约束限制:不涉及

取值范围:不涉及

默认取值:不涉及

响应参数

状态码:202

表11 响应Body参数

参数

参数类型

描述

loadbalancer_ids

Array of strings

参数解释:批创负载均衡器ID(UUID)的列表。

取值范围:不涉及

job_id

String

参数解释:批量创建负载均衡器的job ID。

取值范围:不涉及

order_id

String

参数解释:订单号(只有批量创建包周期实例的场景返回该字段)

取值范围:不涉及

request_id

String

参数解释:请求ID。

取值范围:由数字、小写字母和中划线(-)组成的字符串,自动生成。

请求示例

  • 示例1 : 批量创建3个独享型按需私网IPv4负载均衡器

    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
      }
    }
  • 示例2 : 批量创建2个独享型包周期公网IPv4负载均衡器

    POST https://{ELB_Endpoint}/v3/060576782980d5762f9ec014dd2f1148/elb/loadbalancers/batch-create
    
    {
      "loadbalancer" : {
        "vip_subnet_cidr_id" : "e6e9271d-aef4-48f0-a93a-ccc7b09032c1",
        "availability_zone_list" : [ "AZ1" ],
        "admin_state_up" : true,
        "publicip" : {
          "network_type" : "5_bgp",
          "bandwidth" : {
            "size" : 2,
            "share_type" : "PER",
            "charge_mode" : "bandwidth",
            "name" : "bandwidth_test"
          }
        },
        "name" : "elb_eip-test",
        "number" : 3,
        "prepaid_options" : {
          "period_type" : "month",
          "period_num" : 3,
          "auto_pay" : true,
          "auto_renew" : false
        }
      }
    }
  • 示例3 : 批量创建3个共享型私网IPv4负载均衡器

    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
      }
    }

响应示例

状态码:202

批量创建负载均衡器正常返回

{
  "job_id" : "060576798a80d5762fafc01a9b5eedc7",
  "loadbalancer_ids" : [ "de7946ba-3b77-4119-8338-acc25eb05611", "ba27f70b-b52f-4a77-9220-fd15726e50bd" ],
  "request_id" : "bf29597181cb81b30d19f1a0115a157d",
  "order_id" : "CS2209271603H7TW4"
}

SDK代码示例

SDK代码示例如下。

  • 示例1 : 批量创建3个独享型按需私网IPv4负载均衡器

     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());
            }
        }
    }
    
  • 示例2 : 批量创建2个独享型包周期公网IPv4负载均衡器

     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
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    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();
            PrepaidCreateOption prepaidOptionsLoadbalancer = new PrepaidCreateOption();
            prepaidOptionsLoadbalancer.withPeriodType(PrepaidCreateOption.PeriodTypeEnum.fromValue("month"))
                .withPeriodNum(3)
                .withAutoRenew(false)
                .withAutoPay(true);
            CreateLoadBalancerBandwidthOption bandwidthPublicip = new CreateLoadBalancerBandwidthOption();
            bandwidthPublicip.withName("bandwidth_test")
                .withSize(2)
                .withChargeMode(CreateLoadBalancerBandwidthOption.ChargeModeEnum.fromValue("bandwidth"))
                .withShareType(CreateLoadBalancerBandwidthOption.ShareTypeEnum.fromValue("PER"));
            CreateLoadBalancerPublicIpOption publicipLoadbalancer = new CreateLoadBalancerPublicIpOption();
            publicipLoadbalancer.withNetworkType("5_bgp")
                .withBandwidth(bandwidthPublicip);
            List<String> listLoadbalancerAvailabilityZoneList = new ArrayList<>();
            listLoadbalancerAvailabilityZoneList.add("AZ1");
            BatchCreateLoadBalancerOption loadbalancerbody = new BatchCreateLoadBalancerOption();
            loadbalancerbody.withNumber(3)
                .withName("elb_eip-test")
                .withVipSubnetCidrId("e6e9271d-aef4-48f0-a93a-ccc7b09032c1")
                .withAvailabilityZoneList(listLoadbalancerAvailabilityZoneList)
                .withAdminStateUp(true)
                .withPublicip(publicipLoadbalancer)
                .withPrepaidOptions(prepaidOptionsLoadbalancer);
            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());
            }
        }
    }
    
  • 示例3 : 批量创建3个共享型私网IPv4负载均衡器

     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());
            }
        }
    }
    
  • 示例1 : 批量创建3个独享型按需私网IPv4负载均衡器

     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)
    
  • 示例2 : 批量创建2个独享型包周期公网IPv4负载均衡器

     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
    # 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()
            prepaidOptionsLoadbalancer = PrepaidCreateOption(
                period_type="month",
                period_num=3,
                auto_renew=False,
                auto_pay=True
            )
            bandwidthPublicip = CreateLoadBalancerBandwidthOption(
                name="bandwidth_test",
                size=2,
                charge_mode="bandwidth",
                share_type="PER"
            )
            publicipLoadbalancer = CreateLoadBalancerPublicIpOption(
                network_type="5_bgp",
                bandwidth=bandwidthPublicip
            )
            listAvailabilityZoneListLoadbalancer = [
                "AZ1"
            ]
            loadbalancerbody = BatchCreateLoadBalancerOption(
                number=3,
                name="elb_eip-test",
                vip_subnet_cidr_id="e6e9271d-aef4-48f0-a93a-ccc7b09032c1",
                availability_zone_list=listAvailabilityZoneListLoadbalancer,
                admin_state_up=True,
                publicip=publicipLoadbalancer,
                prepaid_options=prepaidOptionsLoadbalancer
            )
            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)
    
  • 示例3 : 批量创建3个共享型私网IPv4负载均衡器

     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)
    
  • 示例1 : 批量创建3个独享型按需私网IPv4负载均衡器

     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)
        }
    }
    
  • 示例2 : 批量创建2个独享型包周期公网IPv4负载均衡器

     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
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    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{}
    	periodNumPrepaidOptions:= int32(3)
    	autoRenewPrepaidOptions:= false
    	autoPayPrepaidOptions:= true
    	prepaidOptionsLoadbalancer := &model.PrepaidCreateOption{
    		PeriodType: model.GetPrepaidCreateOptionPeriodTypeEnum().MONTH,
    		PeriodNum: &periodNumPrepaidOptions,
    		AutoRenew: &autoRenewPrepaidOptions,
    		AutoPay: &autoPayPrepaidOptions,
    	}
    	nameBandwidth:= "bandwidth_test"
    	sizeBandwidth:= int32(2)
    	chargeModeBandwidth:= model.GetCreateLoadBalancerBandwidthOptionChargeModeEnum().BANDWIDTH
    	shareTypeBandwidth:= model.GetCreateLoadBalancerBandwidthOptionShareTypeEnum().PER
    	bandwidthPublicip := &model.CreateLoadBalancerBandwidthOption{
    		Name: &nameBandwidth,
    		Size: &sizeBandwidth,
    		ChargeMode: &chargeModeBandwidth,
    		ShareType: &shareTypeBandwidth,
    	}
    	publicipLoadbalancer := &model.CreateLoadBalancerPublicIpOption{
    		NetworkType: "5_bgp",
    		Bandwidth: bandwidthPublicip,
    	}
    	var listAvailabilityZoneListLoadbalancer = []string{
            "AZ1",
        }
    	numberLoadbalancer:= int32(3)
    	nameLoadbalancer:= "elb_eip-test"
    	vipSubnetCidrIdLoadbalancer:= "e6e9271d-aef4-48f0-a93a-ccc7b09032c1"
    	adminStateUpLoadbalancer:= true
    	loadbalancerbody := &model.BatchCreateLoadBalancerOption{
    		Number: &numberLoadbalancer,
    		Name: &nameLoadbalancer,
    		VipSubnetCidrId: &vipSubnetCidrIdLoadbalancer,
    		AvailabilityZoneList: listAvailabilityZoneListLoadbalancer,
    		AdminStateUp: &adminStateUpLoadbalancer,
    		Publicip: publicipLoadbalancer,
    		PrepaidOptions: prepaidOptionsLoadbalancer,
    	}
    	request.Body = &model.BatchCreateLoadBalancersRequestBody{
    		Loadbalancer: loadbalancerbody,
    	}
    	response, err := client.BatchCreateLoadBalancers(request)
    	if err == nil {
            fmt.Printf("%+v\n", response)
        } else {
            fmt.Println(err)
        }
    }
    
  • 示例3 : 批量创建3个共享型私网IPv4负载均衡器

     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)
        }
    }
    

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

202

批量创建负载均衡器正常返回

错误码

请参见错误码

相关文档