更新时间:2024-04-18 GMT+08:00

查询监听器列表

功能介绍

查询监听器列表。

接口约束

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

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

调用方法

请参见如何调用API

URI

GET /v3/{project_id}/elb/listeners

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID。

表2 Query参数

参数

是否必选

参数类型

描述

limit

Integer

每页返回的个数。

最小值:0

最大值:2000

缺省值:2000

marker

String

上一页最后一条记录的ID。

使用说明:

  • 必须与limit一起使用。

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

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

page_reverse

Boolean

是否反向查询。

取值:

  • true:查询上一页。

  • false:查询下一页,默认。

使用说明:

  • 必须与limit一起使用。

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

protocol_port

Array

监听器的前端监听端口。

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

protocol

Array

监听器的监听协议。

取值:TCP、UDP、HTTP、HTTPS、TERMINATED_HTTPS、QUIC。

说明:TERMINATED_HTTPS为共享型LB上的监听器独有的协议。

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

description

Array

监听器的描述信息。

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

default_tls_container_ref

Array

监听器的服务器证书ID。

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

client_ca_tls_container_ref

Array

监听器的CA证书ID。

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

admin_state_up

Boolean

监听器的管理状态,只能设置为true。

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

connection_limit

Array

​监听器的最大连接数。

取值:-1表示不限制连接数。

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

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

default_pool_id

Array

监听器的默认后端云服务器组ID。当请求没有匹配的转发策略时,转发到默认后端云服务器上处理。

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

id

Array

监听器ID。

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

name

Array

监听器名称。

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

http2_enable

Boolean

客户端与LB之间的HTTPS请求的HTTP2功能的开启状态。 开启后,可提升客户端与LB间的访问性能,但LB与后端服务器间仍采用HTTP1.X协议。

使用说明:

  • 仅HTTPS协议监听器有效。

  • QUIC监听器不能设置该字段,固定返回为true。

  • 其他协议的监听器可设置该字段但无效,无论取值如何都不影响监听器正常运行。

loadbalancer_id

Array

监听器所属的负载均衡器ID。

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

tls_ciphers_policy

Array

监听器使用的安全策略。

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

member_address

Array

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

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

member_device_id

Array

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

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

enterprise_project_id

Array

企业项目ID。不传时查询default企业项目"0"下的资源,鉴权按照default企业项目鉴权; 如果传值,则传已存在的企业项目ID或all_granted_eps(表示查询所有企业项目)进行查询。

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

enable_member_retry

Boolean

是否开启后端服务器的重试。

取值:true 开启重试,false 不开启重试。

member_timeout

Array

等待后端服务器响应超时时间。请求转发后端服务器后,在等待超时member_timeout时长没有响应,负载均衡将终止等待,并返回 HTTP504错误码。

取值:1-300s。

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

client_timeout

Array

等待客户端请求超时时间,包括两种情况:

  • 读取整个客户端请求头的超时时长:如果客户端未在超时时长内发送完整个请求头,则请求将被中断

  • 两个连续body体的数据包到达LB的时间间隔,超出client_timeout将会断开连接。

取值:1-300s。

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

keepalive_timeout

Array

客户端连接空闲超时时间。在超过keepalive_timeout时长一直没有请求, 负载均衡会暂时中断当前连接,直到下一次请求时重新建立新的连接。

取值:

  • TCP监听器:10-4000s。

  • HTTP/HTTPS/TERMINATED_HTTPS监听器:0-4000s。

  • 共享型实例的UDP监听器不支持此字段。

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

transparent_client_ip_enable

Boolean

是否透传客户端IP地址。开启后客户端IP地址将透传到后端服务器。

仅作用于共享型LB的TCP/UDP监听器。取值:true开启,false不开启。

proxy_protocol_enable

Boolean

是否开启proxy_protocol。仅tcpssl监听器可指定,其他协议的监听器该字段不生效,proxy_protocol不开启。

enhance_l7policy_enable

Boolean

是否开启高级转发策略功能。开启高级转发策略后,支持更灵活的转发策略和转发规则设置。

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

member_instance_id

Array

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

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

请求参数

表3 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

IAM鉴权Token

响应参数

状态码: 200

表4 响应Body参数

参数

参数类型

描述

request_id

String

请求ID。

注:自动生成 。

page_info

PageInfo object

监听器分页信息。

listeners

Array of Listener objects

Listener的列表。

表5 PageInfo

参数

参数类型

描述

previous_marker

String

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

next_marker

String

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

current_count

Integer

当前的记录数。

表6 Listener

参数

参数类型

描述

admin_state_up

Boolean

监听器的管理状态。只能设置为true。

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

client_ca_tls_container_ref

String

监听器使用的CA证书ID。当且仅当type=client时,才会使用该字段对应的证书。

connection_limit

Integer

监听器的最大连接数。

取值:-1表示不限制,默认为-1。

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

created_at

String

监听器的创建时间。格式:yyyy-MM-dd'T'HH:mm:ss'Z',如:2021-07-30T12:03:44Z

default_pool_id

String

监听器的默认后端云服务器组ID。当请求没有匹配的转发策略时,转发到默认后端云服务器上处理。

default_tls_container_ref

String

监听器使用的服务器证书ID。

description

String

监听器的描述信息。

http2_enable

Boolean

客户端与LB之间的HTTPS请求的HTTP2功能的开启状态。 开启后,可提升客户端与LB间的访问性能,但LB与后端服务器间仍采用HTTP1.X协议。

使用说明:

  • 仅HTTPS协议监听器有效。

  • QUIC监听器不能设置该字段,固定返回为true。

  • 其他协议的监听器可设置该字段但无效,无论取值如何都不影响监听器正常运行。

id

String

监听器ID。

insert_headers

ListenerInsertHeaders object

可选的HTTP头插入,可以将从负载均衡器到后端云服务器的路径中需要被后端云服务器用到的信息写入HTTP中,随报文传递到后端云服务器使。例如可通过X-Forwarded-ELB-IP开关,将负载均衡器的弹性公网IP传到后端云服务器。

loadbalancers

Array of LoadBalancerRef objects

监听器所属的负载均衡器的ID列表。一个监听器只支持关联到一个LB。

name

String

监听器的名称。

注意:若名称为空,则在控制台的监听器列表无法选择并查看监听器详情。

project_id

String

监听器所在的项目ID。

protocol

String

监听器的监听协议。

取值:TCP、UDP、HTTP、HTTPS、TERMINATED_HTTPS、QUIC、TCPSSL。

使用说明:

  • 共享型LB上的HTTPS监听器只支持设置为TERMINATED_HTTPS, 创建时传入HTTPS将会自动转为TERMINATED_HTTPS。

  • 独享型LB上的HTTPS监听器只支持设置为HTTPS,创建时传入TERMINATED_HTTPS将会自动转为HTTPS。

protocol_port

Integer

监听器的监听端口。QUIC监听器端口不能是4789,且不能和UDP监听器端口重复。传0时表示开启监听端口范围的能力,此时port_ranges为必填字段。

最小值:0

最大值:65535

sni_container_refs

Array of strings

监听器使用的SNI证书(带域名的服务器证书)ID列表。

使用说明:

  • 列表对应的所有SNI证书的域名不允许存在重复。

  • 列表对应的所有SNI证书的域名总数不超过50。

sni_match_algo

String

监听器使用的SNI证书泛域名匹配方式。 longest_suffix表示最长尾缀匹配,wildcard表示标准域名分级匹配。 默认为wildcard。

tags

Array of Tag objects

标签列表。

updated_at

String

监听器的更新时间。格式:yyyy-MM-dd'T'HH:mm:ss'Z',如:2021-07-30T12:03:44Z

tls_ciphers_policy

String

监听器使用的安全策略。

取值:tls-1-0-inherit,tls-1-0, tls-1-1, tls-1-2,tls-1-2-strict,tls-1-2-fs,tls-1-0-with-1-3, tls-1-2-fs-with-1-3, hybrid-policy-1-0,默认:tls-1-0。

使用说明:

  • 仅对HTTPS协议类型的监听器且关联LB为独享型时有效。

  • QUIC监听器不支持该字段。

  • 若同时设置了security_policy_id和tls_ciphers_policy,则仅security_policy_id生效。

  • 加密套件的优先顺序为ecc套件、rsa套件、tls1.3协议的套件(即支持ecc又支持rsa)

security_policy_id

String

自定义安全策略的ID。

使用说明:

  • 仅对HTTPS协议类型的监听器且关联LB为独享型时有效。

  • 若同时设置了security_policy_id和tls_ciphers_policy,则仅security_policy_id生效。

  • 加密套件的优先顺序为ecc套件、rsa套件、tls1.3协议的套件(即支持ecc又支持rsa)

enable_member_retry

Boolean

是否开启后端服务器的重试。

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

使用说明:

  • 若关联是共享型LB,仅在protocol为HTTP、TERMINATED_HTTPS时才能传入该字段。

  • 若关联是独享型LB,仅在protocol为HTTP、HTTPS和QUIC时才能传入该字段。

keepalive_timeout

Integer

客户端连接空闲超时时间。在超过keepalive_timeout时长一直没有请求, 负载均衡会暂时中断当前连接,直到下一次请求时重新建立新的连接。

取值:

  • 若为TCP监听器,取值范围为(10-4000s)默认值为300s。

  • 若为HTTP/HTTPS/TERMINATED_HTTPS监听器,取值范围为(0-4000s)默认值为60s。

共享型实例的UDP监听器不支持此字段。

client_timeout

Integer

等待客户端请求超时时间,包括两种情况:

  • 读取整个客户端请求头的超时时长:如果客户端未在超时时长内发送完整个请求头,则请求将被中断

  • 两个连续body体的数据包到达LB的时间间隔,超出client_timeout将会断开连接。

取值范围为1-300s,默认值为60s。

使用说明:仅协议为HTTP/HTTPS的监听器支持该字段。

member_timeout

Integer

等待后端服务器响应超时时间。请求转发后端服务器后,在等待超时member_timeout时长没有响应,负载均衡将终止等待,并返回 HTTP504错误码。

取值:1-300s,默认为60s。

使用说明:仅支持协议为HTTP/HTTPS的监听器。

ipgroup

ListenerIpGroup object

listener对象中的ipgroup信息

transparent_client_ip_enable

Boolean

是否透传客户端IP地址。开启后客户端IP地址将透传到后端服务器。 仅作用于共享型LB的TCP/UDP监听器。

取值:

  • 共享型LB的TCP/UDP监听器可设置为true或false,不传默认为false。

  • 共享型LB的HTTP/HTTPS监听器只支持设置为true,不传默认为true。

  • 独享型负载均衡器所有协议的监听器只支持设置为true,不传默认为true。

使用说明:

  • 开启特性后,ELB和后端服务器之间直接使用真实的IP访问,需要确保已正确设置服务器的安全组以及访问控制策略。

  • 开启特性后,不支持同一台服务器既作为后端服务器又作为客户端的场景。

  • 开启特性后,不支持变更后端服务器规格。

proxy_protocol_enable

Boolean

是否开启proxy_protocol。仅tcpssl监听器可指定,其他协议的监听器该字段不生效,proxy_protocol不开启。

enhance_l7policy_enable

Boolean

是否开启高级转发策略功能。开启高级转发策略后,支持更灵活的转发策略和转发规则设置。

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

开启后支持如下场景:

  • 转发策略的action字段支持指定为REDIRECT_TO_URL, FIXED_RESPONSE,即支持URL重定向和响应固定的内容给客户端。

  • 转发策略支持指定priority、redirect_url_config、fixed_response_config字段。

  • 转发规则rule的type可以指定METHOD, HEADER, QUERY_STRING, SOURCE_IP这几种取值。

  • 转发规则rule的type为HOST_NAME时,转发规则rule的value支持通配符*。

  • 转发规则支持指定conditions字段。

缺省值:false

quic_config

ListenerQuicConfig object

当前监听器关联的QUIC监听器配置信息,仅protocol为HTTPS时有效。

对于TCP/UDP/HTTP/QUIC监听器,若该字段非空则报错。

说明:

客户端向服务端发送正常的HTTP协议请求并携带了支持QUIC协议的信息。 如果服务端监听器开启了升级QUIC,那么就会在响应头中加入服务端支持的QUIC端口和版本信息。 客户端再次请求时会同时发送TCP(HTTPS)和UDP(QUIC)请求,若QUIC请求成功,则后续继续使用QUIC交互。

protection_status

String

修改保护状态, 取值:

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

  • consoleProtection: 控制台修改保护

protection_reason

String

设置保护的原因

说明:

仅当protection_status为consoleProtection时有效。

最小长度:0

最大长度:255

gzip_enable

Boolean

ELB是否开启gzip压缩,缺省值:false,非必选

仅HTTP/HTTPS/QUIC类型监听器支持配置。

表7 ListenerInsertHeaders

参数

参数类型

描述

X-Forwarded-ELB-IP

Boolean

X-Forwarded-ELB-IP设为true可以将ELB实例的eip地址从报文的http头中带到后端云服务器。

X-Forwarded-Port

Boolean

X-Forwarded-Port设为true可以将ELB实例的监听端口从报文的http头中带到后端云服务器。

X-Forwarded-For-Port

Boolean

X-Forwarded-For-Port设为true可以将客户端的源端口从报文的http头中带到后端云服务器。

X-Forwarded-Host

Boolean

X-Forwarded-Host设为true可以将客户请求头的X-Forwarded-Host设置为请求头的Host带到后端云服务器。

X-Forwarded-Proto

Boolean

X-Forwarded-Proto设为true可以将负载均衡器实例的监听协议通过报文的http头带到后端云服务器。

X-Real-IP

Boolean

X-Real-IP设为true可以将客户端的IP通过报文的http头带到后端云服务器。

X-Forwarded-ELB-ID

Boolean

X-Forwarded-ELB-ID设为true可以将负载均衡器实例的ID通过报文的http头带到后端云服务器。

X-Forwarded-TLS-Certificate-ID

Boolean

X-Forwarded-TLS-Certificate-ID设为true可以将负载均衡器实例的证书ID通过报文的http头带到后端云服务器。

X-Forwarded-TLS-Protocol

Boolean

X-Forwarded-TLS-Protocol设为true可以将负载均衡器实例的算法协议通过报文的http头带到后端云服务器。

X-Forwarded-TLS-Cipher

Boolean

X-Forwarded-TLS-Cipher设为true可以将负载均衡器实例的算法套件通过报文的http头带到后端云服务器。

表8 LoadBalancerRef

参数

参数类型

描述

id

String

负载均衡器ID。

表9 Tag

参数

参数类型

描述

key

String

标签键

最小长度:1

最大长度:36

value

String

标签值

最小长度:0

最大长度:43

表10 ListenerIpGroup

参数

参数类型

描述

ipgroup_id

String

监听器关联的访问控制组的id。 创建时必选,更新时非必选。 指定的ipgroup必须已存在,不能指定为null,否则与enable_ipgroup冲突。

enable_ipgroup

Boolean

访问控制组的状态。 True:开启访问控制; Flase:关闭访问控制; 开启访问控制的监听器,允许直接删除。

type

String

访问控制组的类型。 white:白名单,只允许指定ip访问; black:黑名单,不允许指定ip访问;

表11 ListenerQuicConfig

参数

参数类型

描述

quic_listener_id

String

监听器关联的QUIC监听器ID。 创建时必选,更新时非必选。 指定的listener id必须已存在,且协议类型为QUIC,不能指定为null,否则与enable_quic_upgrade冲突。

enable_quic_upgrade

Boolean

QUIC升级的开启状态。 True:开启QUIC升级; Flase:关闭QUIC升级; 开启HTTPS监听器升级QUIC监听器能力

表12 PortRange

参数

参数类型

描述

start_port

Integer

起始端口

最小值:1

最大值:65535

end_port

Integer

结束端口,需大于等于起始端口

最小值:1

最大值:65535

请求示例

分页查询监听器列表

GET https://{ELB_Endpoint}/v3/99a3fff0d03c428eac3678da6a7d0f24/elb/listeners?limit=2&marker=0r31747a-b139-492f-2749-2df0b1c87193

响应示例

状态码: 200

操作正常返回。

{
  "listeners" : [ {
    "id" : "0b11747a-b139-492f-9692-2df0b1c87193",
    "name" : "My listener",
    "protocol_port" : 80,
    "protocol" : "TCP",
    "ipgroup" : null,
    "description" : "My listener update.",
    "default_tls_container_ref" : null,
    "admin_state_up" : true,
    "loadbalancers" : [ {
      "id" : "098b2f68-af1c-41a9-8efd-69958722af62"
    } ],
    "member_timeout" : null,
    "client_timeout" : null,
    "keepalive_timeout" : 300,
    "client_ca_tls_container_ref" : null,
    "project_id" : "99a3fff0d03c428eac3678da6a7d0f24",
    "sni_container_refs" : [ ],
    "connection_limit" : -1,
    "default_pool_id" : null,
    "tls_ciphers_policy" : "tls-1-0",
    "tags" : [ ],
    "created_at" : "2019-04-02T00:12:32Z",
    "updated_at" : "2019-04-02T17:43:46Z",
    "http2_enable" : true,
    "insert_headers" : {
      "X-Forwarded-ELB-IP" : true
    },
    "transparent_client_ip_enable" : false,
    "quic_config" : null
  }, {
    "id" : "0b455839-3ea7-4bac-ad26-35bf22f96ea4",
    "name" : "listener-test",
    "protocol_port" : 86,
    "protocol" : "TERMINATED_HTTPS",
    "description" : null,
    "default_tls_container_ref" : "ad9b123e858d4652b80e89b9941e49a4",
    "admin_state_up" : true,
    "loadbalancers" : [ {
      "id" : "309a0f61-0b62-45f2-97d1-742f3434338e"
    } ],
    "member_timeout" : 60,
    "client_timeout" : 60,
    "keepalive_timeout" : 15,
    "client_ca_tls_container_ref" : "7875ccb4c6b44cdb90ab2ab89892ab71",
    "project_id" : "99a3fff0d03c428eac3678da6a7d0f24",
    "sni_container_refs" : [ "7f41c96223d34ebaa3c8e836b6625ec0" ],
    "connection_limit" : -1,
    "default_pool_id" : "5e7e0175-d5d5-4f37-bfba-88a9524ad20b",
    "tls_ciphers_policy" : "tls-1-0",
    "tags" : [ ],
    "created_at" : "2019-03-22T23:37:14Z",
    "updated_at" : "2019-03-22T23:37:14Z",
    "http2_enable" : false,
    "ipgroup" : null,
    "insert_headers" : {
      "X-Forwarded-ELB-IP" : true
    },
    "transparent_client_ip_enable" : false,
    "quic_config" : null
  } ],
  "page_info" : {
    "next_marker" : "0b455839-3ea7-4bac-ad26-35bf22f96ea4",
    "previous_marker" : "0b11747a-b139-492f-9692-2df0b1c87193",
    "current_count" : 2
  },
  "request_id" : "774640ee-6863-4de3-8156-aff16f51a087"
}

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
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 ListListenersSolution {

    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");

        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);

        ElbClient client = ElbClient.newBuilder()
                .withCredential(auth)
                .withRegion(ElbRegion.valueOf("<YOUR REGION>"))
                .build();
        ListListenersRequest request = new ListListenersRequest();
        request.withLimit(<limit>);
        request.withMarker("<marker>");
        request.withPageReverse(<page_reverse>);
        request.withProtocolPort();
        request.withProtocol();
        request.withDescription();
        request.withDefaultTlsContainerRef();
        request.withClientCaTlsContainerRef();
        request.withAdminStateUp(<admin_state_up>);
        request.withConnectionLimit();
        request.withDefaultPoolId();
        request.withId();
        request.withName();
        request.withHttp2Enable(<http2_enable>);
        request.withLoadbalancerId();
        request.withTlsCiphersPolicy();
        request.withMemberAddress();
        request.withMemberDeviceId();
        request.withEnterpriseProjectId();
        request.withEnableMemberRetry(<enable_member_retry>);
        request.withMemberTimeout();
        request.withClientTimeout();
        request.withKeepaliveTimeout();
        request.withTransparentClientIpEnable(<transparent_client_ip_enable>);
        request.withProxyProtocolEnable(<proxy_protocol_enable>);
        request.withEnhanceL7policyEnable(<enhance_l7policy_enable>);
        request.withMemberInstanceId();
        request.withProtectionStatus();
        try {
            ListListenersResponse response = client.listListeners(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
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
# coding: utf-8

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 = __import__('os').getenv("CLOUD_SDK_AK")
    sk = __import__('os').getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

    client = ElbClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(ElbRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ListListenersRequest()
        request.limit = <limit>
        request.marker = "<marker>"
        request.page_reverse = <PageReverse>
        request.protocol_port = 
        request.protocol = 
        request.description = 
        request.default_tls_container_ref = 
        request.client_ca_tls_container_ref = 
        request.admin_state_up = <AdminStateUp>
        request.connection_limit = 
        request.default_pool_id = 
        request.id = 
        request.name = 
        request.http2_enable = <Http2Enable>
        request.loadbalancer_id = 
        request.tls_ciphers_policy = 
        request.member_address = 
        request.member_device_id = 
        request.enterprise_project_id = 
        request.enable_member_retry = <EnableMemberRetry>
        request.member_timeout = 
        request.client_timeout = 
        request.keepalive_timeout = 
        request.transparent_client_ip_enable = <TransparentClientIpEnable>
        request.proxy_protocol_enable = <ProxyProtocolEnable>
        request.enhance_l7policy_enable = <EnhanceL7policyEnable>
        request.member_instance_id = 
        request.protection_status = 
        response = client.list_listeners(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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := elb.NewElbClient(
        elb.ElbClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListListenersRequest{}
	limitRequest:= int32(<limit>)
	request.Limit = &limitRequest
	markerRequest:= "<marker>"
	request.Marker = &markerRequest
	pageReverseRequest:= <page_reverse>
	request.PageReverse = &pageReverseRequest
	adminStateUpRequest:= <admin_state_up>
	request.AdminStateUp = &adminStateUpRequest
	http2EnableRequest:= <http2_enable>
	request.Http2Enable = &http2EnableRequest
	enableMemberRetryRequest:= <enable_member_retry>
	request.EnableMemberRetry = &enableMemberRetryRequest
	transparentClientIpEnableRequest:= <transparent_client_ip_enable>
	request.TransparentClientIpEnable = &transparentClientIpEnableRequest
	proxyProtocolEnableRequest:= <proxy_protocol_enable>
	request.ProxyProtocolEnable = &proxyProtocolEnableRequest
	enhanceL7policyEnableRequest:= <enhance_l7policy_enable>
	request.EnhanceL7policyEnable = &enhanceL7policyEnableRequest
	response, err := client.ListListeners(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

操作正常返回。

错误码

请参见错误码