网络
虚拟私有云 VPC
弹性公网IP EIP
弹性负载均衡 ELB
NAT网关 NAT
云专线 DC
虚拟专用网络 VPN
云连接 CC
VPC终端节点 VPCEP
企业路由器 ER
企业交换机 ESW
全球加速 GA
企业连接 EC
云原生应用网络 ANC
安全与合规
安全技术与应用
Web应用防火墙 WAF
企业主机安全 HSS
云防火墙 CFW
安全云脑 SecMaster
DDoS防护 AAD
数据加密服务 DEW
数据库安全服务 DBSS
云堡垒机 CBH
数据安全中心 DSC
云证书管理服务 CCM
威胁检测服务 MTD
态势感知 SA
认证测试中心 CTC
边缘安全 EdgeSec
应用中间件
微服务引擎 CSE
分布式消息服务Kafka版
分布式消息服务RabbitMQ版
分布式消息服务RocketMQ版
API网关 APIG
分布式缓存服务 DCS
多活高可用服务 MAS
事件网格 EG
管理与监管
统一身份认证服务 IAM
消息通知服务 SMN
云监控服务 CES
应用运维管理 AOM
应用性能管理 APM
云日志服务 LTS
云审计服务 CTS
标签管理服务 TMS
配置审计 Config
应用身份管理服务 OneAccess
资源访问管理 RAM
组织 Organizations
资源编排服务 RFS
优化顾问 OA
IAM 身份中心
云运维中心 COC
资源治理中心 RGC
解决方案
高性能计算 HPC
SAP
混合云灾备
开天工业工作台 MIW
Haydn解决方案工厂
数字化诊断治理专家服务
云生态
云商店
合作伙伴中心
华为云开发者学堂
华为云慧通差旅
开发与运维
软件开发生产线 CodeArts
需求管理 CodeArts Req
流水线 CodeArts Pipeline
代码检查 CodeArts Check
编译构建 CodeArts Build
部署 CodeArts Deploy
测试计划 CodeArts TestPlan
制品仓库 CodeArts Artifact
移动应用测试 MobileAPPTest
CodeArts IDE Online
开源镜像站 Mirrors
性能测试 CodeArts PerfTest
应用管理与运维平台 ServiceStage
云应用引擎 CAE
开源治理服务 CodeArts Governance
华为云Astro轻应用
CodeArts IDE
Astro工作流 AstroFlow
代码托管 CodeArts Repo
漏洞管理服务 CodeArts Inspector
联接 CodeArtsLink
软件建模 CodeArts Modeling
Astro企业应用 AstroPro
CodeArts盘古助手
华为云Astro大屏应用
计算
弹性云服务器 ECS
Flexus云服务
裸金属服务器 BMS
云手机服务器 CPH
专属主机 DeH
弹性伸缩 AS
镜像服务 IMS
函数工作流 FunctionGraph
云耀云服务器(旧版)
VR云渲游平台 CVR
Huawei Cloud EulerOS
云化数据中心 CloudDC
网络
虚拟私有云 VPC
弹性公网IP EIP
弹性负载均衡 ELB
NAT网关 NAT
云专线 DC
虚拟专用网络 VPN
云连接 CC
VPC终端节点 VPCEP
企业路由器 ER
企业交换机 ESW
全球加速 GA
企业连接 EC
云原生应用网络 ANC
CDN与智能边缘
内容分发网络 CDN
智能边缘云 IEC
智能边缘平台 IEF
CloudPond云服务
安全与合规
安全技术与应用
Web应用防火墙 WAF
企业主机安全 HSS
云防火墙 CFW
安全云脑 SecMaster
DDoS防护 AAD
数据加密服务 DEW
数据库安全服务 DBSS
云堡垒机 CBH
数据安全中心 DSC
云证书管理服务 CCM
威胁检测服务 MTD
态势感知 SA
认证测试中心 CTC
边缘安全 EdgeSec
大数据
MapReduce服务 MRS
数据湖探索 DLI
表格存储服务 CloudTable
可信智能计算服务 TICS
推荐系统 RES
云搜索服务 CSS
数据可视化 DLV
数据接入服务 DIS
数据仓库服务 GaussDB(DWS)
数据治理中心 DataArts Studio
湖仓构建 LakeFormation
智能数据洞察 DataArts Insight
应用中间件
微服务引擎 CSE
分布式消息服务Kafka版
分布式消息服务RabbitMQ版
分布式消息服务RocketMQ版
API网关 APIG
分布式缓存服务 DCS
多活高可用服务 MAS
事件网格 EG
开天aPaaS
应用平台 AppStage
开天企业工作台 MSSE
开天集成工作台 MSSI
API中心 API Hub
云消息服务 KooMessage
交换数据空间 EDS
云地图服务 KooMap
云手机服务 KooPhone
组织成员账号 OrgID
云空间服务 KooDrive
管理与监管
统一身份认证服务 IAM
消息通知服务 SMN
云监控服务 CES
应用运维管理 AOM
应用性能管理 APM
云日志服务 LTS
云审计服务 CTS
标签管理服务 TMS
配置审计 Config
应用身份管理服务 OneAccess
资源访问管理 RAM
组织 Organizations
资源编排服务 RFS
优化顾问 OA
IAM 身份中心
云运维中心 COC
资源治理中心 RGC
区块链
区块链服务 BCS
数字资产链 DAC
华为云区块链引擎服务 HBS
解决方案
高性能计算 HPC
SAP
混合云灾备
开天工业工作台 MIW
Haydn解决方案工厂
数字化诊断治理专家服务
价格
成本优化最佳实践
专属云商业逻辑
云生态
云商店
合作伙伴中心
华为云开发者学堂
华为云慧通差旅
其他
管理控制台
消息中心
产品价格详情
系统权限
客户关联华为云合作伙伴须知
公共问题
宽限期保留期
奖励推广计划
活动
云服务信任体系能力说明
开发与运维
软件开发生产线 CodeArts
需求管理 CodeArts Req
流水线 CodeArts Pipeline
代码检查 CodeArts Check
编译构建 CodeArts Build
部署 CodeArts Deploy
测试计划 CodeArts TestPlan
制品仓库 CodeArts Artifact
移动应用测试 MobileAPPTest
CodeArts IDE Online
开源镜像站 Mirrors
性能测试 CodeArts PerfTest
应用管理与运维平台 ServiceStage
云应用引擎 CAE
开源治理服务 CodeArts Governance
华为云Astro轻应用
CodeArts IDE
Astro工作流 AstroFlow
代码托管 CodeArts Repo
漏洞管理服务 CodeArts Inspector
联接 CodeArtsLink
软件建模 CodeArts Modeling
Astro企业应用 AstroPro
CodeArts盘古助手
华为云Astro大屏应用
存储
对象存储服务 OBS
云硬盘 EVS
云备份 CBR
高性能弹性文件服务 SFS Turbo
弹性文件服务 SFS
存储容灾服务 SDRS
云硬盘备份 VBS
云服务器备份 CSBS
数据快递服务 DES
云存储网关 CSG
专属分布式存储服务 DSS
数据工坊 DWR
地图数据 MapDS
键值存储服务 KVS
容器
云容器引擎 CCE
云容器实例 CCI
容器镜像服务 SWR
云原生服务中心 OSC
应用服务网格 ASM
华为云UCS
数据库
云数据库 RDS
数据复制服务 DRS
文档数据库服务 DDS
分布式数据库中间件 DDM
云数据库 GaussDB
云数据库 GeminiDB
数据管理服务 DAS
数据库和应用迁移 UGO
云数据库 TaurusDB
人工智能
AI开发平台ModelArts
华为HiLens
图引擎服务 GES
图像识别 Image
文字识别 OCR
自然语言处理 NLP
内容审核 Moderation
图像搜索 ImageSearch
医疗智能体 EIHealth
企业级AI应用开发专业套件 ModelArts Pro
人脸识别服务 FRS
对话机器人服务 CBS
语音交互服务 SIS
人证核身服务 IVS
视频智能分析服务 VIAS
城市智能体
自动驾驶云服务 Octopus
盘古大模型 PanguLargeModels
IoT物联网
设备接入 IoTDA
全球SIM联接 GSL
IoT数据分析 IoTA
路网数字化服务 DRIS
IoT边缘 IoTEdge
设备发放 IoTDP
企业应用
域名注册服务 Domains
云解析服务 DNS
企业门户 EWP
ICP备案
商标注册
华为云WeLink
华为云会议 Meeting
隐私保护通话 PrivateNumber
语音通话 VoiceCall
消息&短信 MSGSMS
云管理网络
SD-WAN 云服务
边缘数据中心管理 EDCM
云桌面 Workspace
应用与数据集成平台 ROMA Connect
ROMA资产中心 ROMA Exchange
API全生命周期管理 ROMA API
政企自服务管理 ESM
视频
实时音视频 SparkRTC
视频直播 Live
视频点播 VOD
媒体处理 MPC
视频接入服务 VIS
数字内容生产线 MetaStudio
迁移
主机迁移服务 SMS
对象存储迁移服务 OMS
云数据迁移 CDM
迁移中心 MGC
专属云
专属计算集群 DCC
开发者工具
SDK开发指南
API签名指南
DevStar
华为云命令行工具服务 KooCLI
Huawei Cloud Toolkit
CodeArts API
云化转型
云架构中心
云采用框架
用户服务
账号中心
费用中心
成本中心
资源中心
企业管理
工单管理
客户运营能力
国际站常见问题
支持计划
专业服务
合作伙伴支持计划
我的凭证
华为云公共事业服务云平台
工业软件
工业数字模型驱动引擎
硬件开发工具链平台云服务
工业数据转换引擎云服务

批量创建负载均衡器

更新时间:2025-02-06 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参数表示是否启用跨VPC后端转发能力,

    启用跨VPC后端转发的负载均衡器关联的member和VIP可以在不同VPC下,

    未启用跨VPC后端转发的负载均衡器关联的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。

请求参数

表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。

number

Integer

批量创建负载均衡器的数量

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

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

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

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

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

l7_flavor_id

String

应用型规格ID。

使用说明:

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

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

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

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

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

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

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。创建时传入""、"0"或不存在的企业项目ID,或者不传则资源属于default企业项目,默认返回"0"。

tags

Array of Tag objects

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

admin_state_up

Boolean

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

取值范围:

  • true :启用。

  • false:停用。

默认取值:true。

ipv6_bandwidth

BandwidthRef object

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

bandwidth

BandwidthRef object

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

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

参数解释:是否启用跨VPC后端转发。

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

约束限制:

  • 开启后不能关闭。

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

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

取值范围:

  • true:开启。

  • false:不开启。

deletion_protection_enable

Boolean

是否开启删除保护。

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

取值:false不开启,true开启。默认false不开启。

说明:

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

autoscaling

CreateLoadbalancerAutoscalingOption object

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

约束限制:

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

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

说明:

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

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和6。4:IPv4, 6: IPv6。

取值范围:

  • 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

参数解释:计费模式。bandwidth 按带宽计费;traffic 按流量计费。

约束限制:当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 CreateLoadbalancerAutoscalingOption

参数

是否必选

参数类型

描述

enable

Boolean

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

取值范围:

  • true:开启。

  • false:关闭。

min_l7_flavor_id

String

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

约束限制: 该字段已经废弃,建议不要使用该字段。

响应参数

状态码:202

表10 响应Body参数

参数

参数类型

描述

loadbalancer_ids

Array of strings

批创负载均衡器ID(UUID)的列表。

job_id

String

批量创建负载均衡器的job ID。

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
        }
      }
    }
  • 示例1 : 批量创建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());
            }
        }
    }
    
  • 示例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
    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)
    
  • 示例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
    # 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)
        }
    }
    
  • 示例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
    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代码示例。

  • 示例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());
            }
        }
    }
    
  • 示例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
    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)
    
  • 示例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
    # 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)
        }
    }
    
  • 示例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
    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

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

错误码

请参见错误码

提示

您即将访问非华为云网站,请注意账号财产安全

文档反馈

文档反馈

意见反馈

0/500

标记内容

同时提交标记内容