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

查询后端服务器组列表

功能介绍

后端服务器组列表。

接口约束

  • 分页查询使用的参数为marker、limit、page_reverse。

  • marker和page_reverse只有和limit一起使用时才会生效,单独使用无效。

调用方法

请参见如何调用API

URI

GET /v3/{project_id}/elb/pools

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

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

约束限制:不涉及

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

默认取值:不涉及

表2 Query参数

参数

是否必选

参数类型

描述

marker

String

参数解释:上一页最后一条记录的ID。

约束限制

  • 必须与limit一起使用。

  • 不指定时表示查询第一页。

  • 该字段不允许为空或无效的ID。

取值范围:不涉及

默认取值:不涉及

limit

Integer

参数解释:每页返回的个数。

约束限制:不涉及

取值范围:0-2000

默认取值:2000

page_reverse

Boolean

参数解释:是否反向查询。

约束限制

  • 必须与limit一起使用。

  • 当page_reverse=true时,若要查询上一页,marker取值为当前页返回值的previous_marker。

取值范围

  • true:查询上一页。

  • false:查询下一页。

默认取值:false

description

Array of strings

后端服务器组的描述信息。

支持多值查询,查询条件格式:description=xxx&description=xxx

admin_state_up

Boolean

后端服务器组的管理状态。

healthmonitor_id

Array of strings

后端服务器组关联的健康检查的ID。

支持多值查询,查询条件格式:healthmonitor_id=xxx&healthmonitor_id=xxx

id

Array of strings

后端服务器组的ID。

支持多值查询,查询条件格式:id=xxx&id=xxx

name

Array of strings

后端服务器组的名称。

支持多值查询,查询条件格式:name=xxx&name=xxx

loadbalancer_id

Array of strings

后端服务器组绑定的负载均衡器ID。

支持多值查询,查询条件格式:loadbalancer_id=xxx&loadbalancer_id=xxx

protocol

Array of strings

后端服务器组的后端协议。

取值:TCP、UDP、TLS、HTTP、HTTPS、QUIC和GRPC。

支持多值查询,查询条件格式:protocol=xxx&protocol=xxx

lb_algorithm

Array of strings

后端服务器组的负载均衡算法。

取值:

  • ROUND_ROBIN:加权轮询算法。

  • LEAST_CONNECTIONS:加权最少连接算法。

  • SOURCE_IP:源IP算法。

  • QUIC_CID:连接ID算法。

支持多值查询,查询条件格式:lb_algorithm=xxx&lb_algorithm=xxx

enterprise_project_id

Array of strings

参数解释:资源所属的企业项目ID。

如果enterprise_project_id不传值,默认查询所有企业项目下的资源,鉴权按照细粒度权限鉴权,必须在用户组下分配elb:pools:list权限。

如果enterprise_project_id传值,鉴权按照企业项目权限鉴权,分为传入具体eps_id和all_granted_eps两种场景,前者查询指定eps_id的eps下的资源,后者查询的是所有有list权限的eps下的资源。

支持多值查询,查询条件格式:

enterprise_project_id=xxx&enterprise_project_id=xxx

ip_version

Array of strings

后端服务器组支持的IP版本。

支持多值查询,查询条件格式:ip_version=xxx&ip_version=xxx

member_address

Array of strings

后端服务器的IP地址。仅用于查询条件,不作为响应参数字段。

支持多值查询,查询条件格式:member_address=xxx&member_address=xxx

member_device_id

Array of strings

后端服务器对应的弹性云服务器的ID。仅用于查询条件,不作为响应参数字段。

支持多值查询,查询条件格式:member_device_id=xxx&member_device_id=xxx

member_deletion_protection_enable

Boolean

是否开启删除保护,false不开启,true开启,不传查询全部。

listener_id

Array of strings

关联的监听器ID,包括通过l7policy关联的。

支持多值查询,查询条件格式:listener_id=xxx&listener_id=xxx

member_instance_id

Array of strings

后端服务器ID。仅用于查询条件,不作为响应参数字段。

支持多值查询,查询条件格式:member_instance_id=xxx&member_instance_id=xxx

vpc_id

Array of strings

后端服务器组关联的虚拟私有云的ID。

type

Array of strings

后端服务器组的类型。

取值:

  • instance:允许任意类型的后端,type指定为该类型时,vpc_id是必选字段。

  • ip:只能添加跨VPC后端,type指定为该类型时,vpc_id不允许指定。

  • 空字符串(""):允许任意类型的后端

protection_status

Array of strings

修改保护状态, 取值:

  • nonProtection: 不保护,默认值为nonProtection

  • consoleProtection: 控制台修改保护

connection_drain

Boolean

查询是否开启延迟注销的功能,查询条件格式:connection_drain=true或者connection_drain=false

pool_health

String

查询是否开启后端全下线转发功能,查询条件格式:pool_health=minimum_healthy_member_count=0或者pool_health=minimum_healthy_member_count=1

any_port_enable

Boolean

后端是否开启端口透传。开启后,后端服务器端口与前端监听器端口保持一致。取值:false不开启,true开启。

public_border_group

String

参数解释:公网边界组。

支持多值查询,查询条件格式:public_border_group=xxx&public_border_group=xxx

约束限制:不涉及

取值范围

  • center:表示中心站点的公网边界组

  • 边缘站点名称:表示边缘站点的公网边界组

默认取值:不涉及

quic_cid_len

Integer

查询相同QUIC CID策略配置的后端服务器组,仅用于查询条件,不作为响应参数字段。

支持多值查询,查询条件格式:quic_cid_len=3&quic_cid_len=5

quic_cid_offset

Integer

查询相同QUIC CID策略配置的后端服务器组,仅用于查询条件,不作为响应参数字段。

支持多值查询,查询条件格式:quic_cid_offset=1&quic_cid_offset=3

az_affinity

Array of strings

查询后端服务器组可用区亲和性策略是否开启。示例如下:

"az_affinity": {

"enable": "true"

}

支持多值查询,查询条件格式:

az_affinity=enable=true&az_affinity=enable=false

请求参数

表3 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

参数解释:IAM鉴权Token

响应参数

状态码:200

表4 响应Body参数

参数

参数类型

描述

request_id

String

参数解释:请求ID。

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

page_info

PageInfo object

参数解释:分页信息。

默认取值:不涉及

pools

Array of Pool objects

后端服务器组列表。

表5 PageInfo

参数

参数类型

描述

previous_marker

String

参数解释:分页查询结果中第一条记录的ID。通常用于配合page_reverse=true查询上一页。

取值范围:不涉及

next_marker

String

参数解释:分页查询结果中最后一条记录的ID。通常用于查询下一页。

取值范围:不涉及

current_count

Integer

参数解释:当前页返回记录数。

取值范围:不涉及

表6 Pool

参数

参数类型

描述

admin_state_up

Boolean

参数解释:后端服务器组的管理状态。

az_affinity

AzAffinity object

参数解释:后端服务器组的可用区亲和策略。

description

String

参数解释:后端服务器组的描述信息。

healthmonitor_id

String

参数解释:后端服务器组关联的健康检查的ID。

id

String

参数解释:后端服务器组的ID。

lb_algorithm

String

参数解释:后端服务器组的负载均衡算法。

约束限制

  • 当该字段的取值为SOURCE_IP或QUIC_CID时,后端服务器组绑定的后端服务器的weight字段无效。

  • 只有pool的protocol为QUIC时,才支持QUIC_CID算法。

取值范围

  • ROUND_ROBIN:加权轮询算法。

  • LEAST_CONNECTIONS:加权最少连接算法。

  • SOURCE_IP:源IP算法。

  • QUIC_CID:连接ID算法。

listeners

Array of ListenerRef objects

参数解释:后端服务器组关联的监听器ID列表。

loadbalancers

Array of LoadBalancerRef objects

参数解释:后端服务器组关联的负载均衡器ID列表。

members

Array of MemberRef objects

参数解释:后端服务器组中的后端服务器ID列表。

name

String

参数解释:后端服务器组的名称。

project_id

String

参数解释:后端服务器组所在的项目ID。

protocol

String

参数解释:后端服务器组的后端协议。

约束限制

  • listener的protocol为UDP时,pool的protocol必须为UDP或QUIC。

  • listener的protocol为TCP时pool的protocol必须为TCP。

  • listener的protocol为HTTP时,pool的protocol必须为HTTP。

  • listener的protocol为HTTPS时,pool的protocol必须为HTTP、HTTPS或GRPC。

  • listener的protocol为TERMINATED_HTTPS时,pool的protocol必须为HTTP。

  • listener的protocol为QUIC时,pool的protocol必须为HTTP、HTTPS或GRPC。

  • listener的protocol为TLS时,pool的protocol必须为TLS或TCP。

  • 若pool的protocol为QUIC,则必须开启session_persistence且type为SOURCE_IP。

  • 若pool的protocol为GRPC,关联监听器必须开启HTTP2。

  • 若pool的protocol为TCP,则pool的ip_version字段取值必须是4。

取值范围:TCP、UDP、TLS、GRPC、HTTP、HTTPS和QUIC。

session_persistence

SessionPersistence object

参数解释:会话持久性对象。

约束限制:慢启动与会话保持不能同时开启。若都开启则会导致会话保持失效。

ip_version

String

参数解释:后端服务器组支持的IP版本。

取值范围

  • 共享型:固定为v4;

  • 独享型:取值dualstack、v4。当协议为TCP/UDP时,ip_version为dualstack,表示双栈。当协议为HTTP时,ip_version为v4。

slow_start

SlowStart object

参数解释:慢启动信息。开启慢启动后,将会在设定的时间段(duration)内对新添加到后端服务器组的后端服务器进行预热,转发到该服务器的请求数量线性增加。

约束限制

  • 当后端服务器组的协议为HTTP/HTTPS/GRPC时有效,其他协议传入该字段将报错。

  • 慢启动与会话保持不能同时开启。若都开启则会导致会话保持失效。

member_deletion_protection_enable

Boolean

参数解释:是否开启后端服务器移除保护。开关开启后,不允许从该ELB后端服务器组下移除后端服务器。

约束限制

  • 开关开启后,移除member会报错拦截,涉及如下API:

    • 级联删除负载均衡器(DELETE /v3/{project_id}/elb/loadbalancers/{loadbalancer_id}/force-elb)

    • 级联删除负载均衡器及关联EIP(POST /v3/{project_id}/elb/loadbalancers/{loadbalancer_id}/delete-cascade)

    • 级联删除监听器(DELETE /v3/{project_id}/elb/listeners/{listener_id}/force)

    • 级联删除后端服务器组(DELETE /v3/{project_id}/elb/pools/{pool_id}/delete-cascade)

    • 删除后端服务器(DELETE /v3/{project_id}/elb/pools/{pool_id}/members/{member_id})

    • 批量删除后端服务器(POST /v3/{project_id}/elb/pools/{pool_id}/members/batch-delete)

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

默认取值:false

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

created_at

String

参数解释:创建时间。

取值范围:格式:yyyy-MM-dd'T'HH:mm:ss'Z',UTC时区。

注意:独享型实例的历史数据以及共享型实例下的资源,不返回该字段。

updated_at

String

参数解释:更新时间。

取值范围:格式:yyyy-MM-dd'T'HH:mm:ss'Z',UTC时区。

注意:独享型实例的历史数据以及共享型实例下的资源,不返回该字段。

vpc_id

String

参数解释:后端服务器组关联的虚拟私有云的ID。

type

String

参数解释:后端服务器组的类型。

取值范围

  • instance:允许任意类型的后端,type指定为该类型时,vpc_id是必选字段。

  • ip:只能添加跨VPC后端,type指定为该类型时,vpc_id不允许指定。]

  • 空字符串(""):允许任意类型的后端

protection_status

String

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

取值范围

  • nonProtection: 不保护。

  • consoleProtection: 控制台修改保护。

默认取值:nonProtection

protection_reason

String

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

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

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

any_port_enable

Boolean

参数解释:后端是否开启端口透传。开启后,后端服务器端口与前端监听器端口保持一致。关闭后,请求会转发给后端服务器protocol_port字段指定端口。取值:false不开启,true开启。

约束限制

  • 仅QUIC,TCP,UDP的pool支持。

connection_drain

ConnectionDrain object

参数解释:后端服务器的延迟注销的功能配置(只针对TCP、UDP、QUIC协议类型的后端服务器组和TCP、UDP协议类的监听器)

以下场景会触发:

  • 后端服务器从后端服务器组中移除

  • 后端服务器健康检查状态异常

  • 后端服务器权重修改为0

enterprise_project_id

String

参数解释:资源所属的企业项目ID。

取值范围

  • "0":表示资源属于default企业项目。

  • UUID格式的字符串,表示非默认企业项目。

pool_health

PoolHealth object

参数解释:后端全下线转发配置。

public_border_group

String

参数解释:公网边界组。

取值范围

  • center:表示中心站点的公网边界组

  • 边缘站点名称:表示边缘站点的公网边界组

quic_cid_hash_strategy

QuicCidHashStrategy object

参数解释:后端服务器组基于部分DST CID的多径分发策略。

表7 AzAffinity

参数

参数类型

描述

enable

Boolean

参数解释:后端服务器组是否开启可用区亲和。开启后,负载均衡器会按照配置的亲和策略进行转发。

约束限制

  • 仅IP,TCP,UDP的pool支持。

  • TLS监听器绑定的pool不支持。

  • 开启后,原本的pool_health配置失效。

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

az_minimum_healthy_member_percentage

Integer

参数解释:后端服务器组单可用区百分比健康度最小阈值,当“后端服务器组单可用区百分比健康度”小于该阈值时,触发可用区异常退避策略。“后端服务器组单可用区百分比健康度”是指在一个后端服务器组中,同可用区中健康检查结果正常的服务器数量与该后端服务器组中属于该可用区的后端服务器总数量的比值,百分比结果向上取整。例如:后端服务器组中属于可用区A的后端服务器总数量为3,设置后端服务器组单可用区百分比健康度最小阈值为66时,3x0.66=1.98向上取整为数量阈值2台,即属于可用区A的健康后端数小于2台时触发退避策略;设置后端服务器组单可用区百分比健康度最小阈值为67时,3x0.67=2.01向上取整为数量阈值3台,即属于可用区A的健康后端数小于3台时触发退避策略。

约束限制

  • enable为true时,az_minimum_healthy_member_percentage与az_minimum_healthy_member_count不能同时为-1

  • enable为true时,az_minimum_healthy_member_percentage与az_minimum_healthy_member_count不能同时不为-1

取值范围:-1至100的整数,0-100为百分比范围,-1表示采用数量阈值。

az_minimum_healthy_member_count

Integer

参数解释:后端服务器组单可用区中数量健康度最小阈值,当“后端服务器组单可用区中数量健康度”小于该阈值时,触发可用区异常退避策略。“后端服务器组单可用区中数量健康度”是指在一个后端服务器组中,属于同一个可用区的健康检查结果正常的服务器数量。

约束限制

  • enable为true时,az_minimum_healthy_member_percentage与az_minimum_healthy_member_count不能同时为-1

  • enable为true时,az_minimum_healthy_member_percentage与az_minimum_healthy_member_count不能同时不为-1

取值范围:-1至10000的整数,0-10000为数量范围,-1表示采用百分比阈值。

az_unhealthy_fallback_strategy

String

参数解释:后端服务器组单可用区异常退避策略。后端服务器组的健康度小于所配置的最小阈值时,触发该退避策略。

forward_to_all_member_of_local_az:转发至同可用区的所有后端服务器,无论健康检查结果是否正常;forward_to_healthy_member_of_remote_az:转发至非同可用区中所有健康检查结果正常的后端服务器;forward_to_all_healthy_member:转发至所有可用区中健康检查结果正常的后端服务器;forward_to_all_member:转发至所有可用区中的所有后端服务器,无论健康检查结果是否正常

取值范围:forward_to_all_member_of_local_az,forward_to_healthy_member_of_remote_az,forward_to_all_healthy_member,forward_to_all_member。

默认值:forward_to_all_member_of_local_az

表8 ListenerRef

参数

参数类型

描述

id

String

参数解释:监听器ID。

取值范围:不涉及

表9 LoadBalancerRef

参数

参数类型

描述

id

String

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

表10 MemberRef

参数

参数类型

描述

id

String

参数解释:后端服务器ID。

表11 SessionPersistence

参数

参数类型

描述

cookie_name

String

参数解释:cookie名称。

取值范围:最大长度1024个字符。

type

String

参数解释:会话保持类型。

约束限制

  • 当pool的protocol为TCP、UDP,无论type取值如何,都会被忽略,会话保持只按SOURCE_IP生效。

  • 当pool的protocol为HTTP、HTTPS时。如果是独享型负载均衡器的pool,则type只能为HTTP_COOKIE,其他取值会话保持失效。如果是共享型负载均衡器的pool,则type可以为HTTP_COOKIE和APP_COOKIE,其他取值会话保持失效。

  • 若pool的protocol为QUIC,则必须开启session_persistence且type为SOURCE_IP。

取值范围:SOURCE_IP、HTTP_COOKIE、APP_COOKIE。

persistence_timeout

Integer

参数解释:会话保持的时间。当type为APP_COOKIE时不生效。

取值范围

  • 若pool的protocol为TCP、UDP和QUIC则范围为[1,60](分钟),默认值1;

  • 若pool的protocol为HTTP和HTTPS则范围为[1,1440](分钟),默认值1440。

表12 SlowStart

参数

参数类型

描述

enable

Boolean

参数解释:慢启动的开关。

取值范围

  • true:开启。

  • false:关闭。

默认取值:false

duration

Integer

参数解释:慢启动的持续时间。

取值范围:30-1200,单位:秒。

默认取值:30

表13 ConnectionDrain

参数

参数类型

描述

enable

Boolean

参数解释:延迟注销功能开关。

取值范围:true 开启,false 关闭。

timeout

Integer

参数解释:延迟注销时间。

取值范围:10~4000,单位:秒。

表14 PoolHealth

参数

参数类型

描述

minimum_healthy_member_count

Integer

参数解释:当健康检查在线的member个数小于该个数,判定pool的state为不健康。

取值范围

  • 0:默认值,不生效。

  • 1:全下线转发生效。

表15 QuicCidHashStrategy

参数

参数类型

描述

len

Integer

参数解释:仅当负载均衡算法为QUIC_CID的时候才生效,表示hash的时候取CID的长度。

取值范围:1-20

默认取值:3

offset

Integer

参数解释:仅当负载均衡算法为QUIC_CID的时候才生效,表示hash的时候取CID的偏移量。

取值范围:0-19

默认取值:1

请求示例

后端服务器组列表

GET https://{ELB_Endpoint}/v3/99a3fff0d03c428eac3678da6a7d0f24/elb/pools?limit=2

响应示例

状态码:200

操作正常返回。

{
  "pools" : [ {
    "lb_algorithm" : "ROUND_ROBIN",
    "protocol" : "HTTP",
    "type" : "",
    "vpc_id" : "",
    "description" : "",
    "admin_state_up" : true,
    "member_deletion_protection_enable" : false,
    "loadbalancers" : [ {
      "id" : "309a0f61-0b62-45f2-97d1-742f3434338e"
    } ],
    "project_id" : "99a3fff0d03c428eac3678da6a7d0f24",
    "session_persistence" : {
      "cookie_name" : "my_cookie",
      "type" : "APP_COOKIE",
      "persistence_timeout" : 1
    },
    "healthmonitor_id" : "",
    "listeners" : [ ],
    "members" : [ ],
    "id" : "73bd4fe0-ffbb-4b56-aab4-4f26ddf7a103",
    "name" : "",
    "ip_version" : "v4",
    "pool_health" : {
      "minimum_healthy_member_count" : 0
    }
  }, {
    "lb_algorithm" : "SOURCE_IP",
    "protocol" : "TCP",
    "description" : "",
    "admin_state_up" : true,
    "member_deletion_protection_enable" : false,
    "loadbalancers" : [ {
      "id" : "d9763e59-64b7-4e93-aec7-0ff7881ef9bc"
    } ],
    "project_id" : "99a3fff0d03c428eac3678da6a7d0f24",
    "session_persistence" : {
      "cookie_name" : "",
      "type" : "SOURCE_IP",
      "persistence_timeout" : 1
    },
    "healthmonitor_id" : "",
    "listeners" : [ {
      "id" : "8d21db6f-b475-429e-a9cb-90439b0413b2"
    } ],
    "members" : [ ],
    "id" : "74db02d1-5711-4c77-b383-a450e2b93142",
    "name" : "pool_tcp_001",
    "ip_version" : "dualstack",
    "pool_health" : {
      "minimum_healthy_member_count" : 0
    },
    "az_affinity" : {
      "enable" : true,
      "az_minimum_healthy_member_percentage" : -1,
      "az_minimum_healthy_member_count" : 10000,
      "az_unhealthy_fallback_strategy" : "forward_to_all_member_of_local_az"
    }
  } ],
  "page_info" : {
    "next_marker" : "74db02d1-5711-4c77-b383-a450e2b93142",
    "previous_marker" : "73bd4fe0-ffbb-4b56-aab4-4f26ddf7a103",
    "current_count" : 2
  },
  "request_id" : "a1a7e852-1928-48f7-bbc9-ca8469898713"
}

SDK代码示例

SDK代码示例如下。

 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
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.*;


public class ListPoolsSolution {

    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();
        ListPoolsRequest request = new ListPoolsRequest();
        try {
            ListPoolsResponse response = client.listPools(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
 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
# 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 = ListPoolsRequest()
        response = client.list_pools(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
 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
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.ListPoolsRequest{}
	response, err := client.ListPools(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

操作正常返回。

错误码

请参见错误码

相关文档

    提示

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