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

查询主备后端服务器组列表

功能介绍

主备后端服务器组列表。

接口约束

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

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

调用方法

请参见如何调用API

URI

GET /v3/{project_id}/elb/master-slave-pools

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID。

表2 Query参数

参数

是否必选

参数类型

描述

marker

String

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

使用说明:

  • 必须与limit一起使用。

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

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

limit

Integer

每页返回的个数。

最小值:0

最大值:2000

缺省值:2000

page_reverse

Boolean

是否反向查询。

取值:

  • true:查询上一页。

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

使用说明:

  • 必须与limit一起使用。

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

description

Array

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

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

healthmonitor_id

Array

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

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

id

Array

后端云服务器组的ID。

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

name

Array

后端云服务器组的名称。

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

loadbalancer_id

Array

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

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

protocol

Array

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

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

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

lb_algorithm

Array

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

取值: 1、ROUND_ROBIN:加权轮询算法。 2、LEAST_CONNECTIONS:加权最少连接算法。 3、SOURCE_IP:源IP算法。 4、QUIC_CID:连接ID算法。

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

enterprise_project_id

Array

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

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

ip_version

Array

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

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

member_address

Array

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

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

member_device_id

Array

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

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

listener_id

Array

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

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

member_instance_id

Array

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

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

vpc_id

Array

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

type

Array

后端服务器组的类型。

取值:

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

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

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

请求参数

表3 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

IAM鉴权Token

响应参数

状态码: 200

表4 响应Body参数

参数

参数类型

描述

request_id

String

请求ID。

注:自动生成 。

page_info

PageInfo object

分页信息。

pools

Array of MasterSlavePool objects

后端服务器组列表。

表5 PageInfo

参数

参数类型

描述

previous_marker

String

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

next_marker

String

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

current_count

Integer

当前的记录数。

表6 MasterSlavePool

参数

参数类型

描述

description

String

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

id

String

后端云服务器组的ID。

lb_algorithm

String

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

取值:

  • ROUND_ROBIN:加权轮询算法。

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

  • SOURCE_IP:源IP算法。

  • QUIC_CID:连接ID算法。

使用说明:

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

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

listeners

Array of ListenerRef objects

后端云服务器组关联的监听器ID列表。

loadbalancers

Array of LoadBalancerRef objects

后端云服务器组关联的负载均衡器ID列表。

members

Array of MasterSlaveMember objects

后端云服务器组中的后端云服务器列表。

name

String

后端云服务器组的名称。

project_id

String

后端云服务器组所在的项目ID。

protocol

String

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

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

使用说明:

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

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

session_persistence

SessionPersistence object

会话持久性对象。

ip_version

String

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

取值:

  • 共享型:固定为v4;

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

当协议为HTTP时,ip_version为v4。

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不允许指定。

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

enterprise_project_id

String

后端服务器组的企业项目ID。无论创建什么企业项目,都在默认企业项目下。

healthmonitor

MasterSlaveHealthMonitor object

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

any_port_enable

Boolean

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

说明:

关闭端口透传后,请求会转发给后端服务器protocol_port字段指定端口。

表7 ListenerRef

参数

参数类型

描述

id

String

监听器ID。

表8 LoadBalancerRef

参数

参数类型

描述

id

String

负载均衡器ID。

表9 MasterSlaveMember

参数

参数类型

描述

id

String

后端服务器ID。

name

String

后端服务器名称。

admin_state_up

Boolean

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

取值:true、false。

虽然创建、更新请求支持该字段,但实际取值决定于后端云服务器对应的弹性云服务器是否存在。若存在,该值为true,否则,该值为false。

subnet_cidr_id

String

后端云服务器所在子网的IPv4子网ID或IPv6子网ID。

若所属的LB的跨VPC后端转发特性已开启,则该字段可以不传,表示添加跨VPC的后端服务器。 此时address必须为IPv4地址,所在的pool的协议必须为TCP/HTTP/HTTPS。

使用说明:该子网和关联的负载均衡器的子网必须在同一VPC下。

protocol_port

Integer

后端服务器业务端口。

说明:

在开启端口透传的pool下创建member传该字段不生效,可不传该字段。

最小值:1

最大值:65535

address

String

后端服务器对应的IP地址。

使用说明:

  • 若subnet_cidr_id为空,表示添加跨VPC后端,此时address必须为IPv4地址。

  • 若subnet_cidr_id不为空,表示是一个关联到ECS的后端服务器。该IP地址可以是IPv4或IPv6。 但必须在subnet_cidr_id对应的子网网段中。且只能指定为关联ECS的主网卡内网IP。

ip_version

String

当前后端服务器的IP地址版本,由后端系统自动根据传入的address字段确定。取值:v4、v6。

device_owner

String

设备所有者。

取值:

  • 空,表示后端服务器未关联到ECS。

  • compute:{az_name},表示关联到ECS,其中{az_name}表示ECS所在可用区名。

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

device_id

String

关联的ECS ID,为空表示后端服务器未关联到ECS。

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

operating_status

String

后端云服务器的健康状态。

取值:

  • ONLINE:后端云服务器正常。

  • NO_MONITOR:后端云服务器所在的服务器组没有健康检查器。

  • OFFLINE:后端云服务器关联的ECS服务器不存在或已关机。

member_type

String

后端云服务器的类型。

取值:

  • ip:跨VPC的member。

  • instance:关联到ECS的member。

instance_id

String

member关联的实例ID。空表示member关联的实例为非真实设备 (如:跨VPC场景)

role

String

后端服务器的主备状态。

status

Array of ListenerMemberInfo objects

后端云服务器监听器粒度的的健康状态。 若绑定的监听器在该字段中,则以该字段中监听器对应的operating_status为准。 若绑定的监听器不在该字段中,则以外层的operating_status为准。

表10 ListenerMemberInfo

参数

参数类型

描述

listener_id

String

后端服务器关联的监听器id。

operating_status

String

后端云服务器的健康状态。

取值:

  • ONLINE:后端云服务器正常。

  • NO_MONITOR:后端云服务器所在的服务器组没有健康检查器。

  • OFFLINE:后端云服务器关联的ECS服务器不存在或已关机或服务异常。

表11 SessionPersistence

参数

参数类型

描述

cookie_name

String

cookie名称。

共享型LB,支持字母、数字、中划线(-)和下划线(),最大长度64个字符。 独享型LB,支持字母、数字、中划线(-)、下划线()和点号(.),最大长度255个字符。

使用说明:

  • 只有当type为APP_COOKIE时才有效。其他情况下传该字段会报错。

type

String

会话保持类型。

取值范围:SOURCE_IP、HTTP_COOKIE、APP_COOKIE。

使用说明:

  • 当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。

persistence_timeout

Integer

会话保持的时间。当type为APP_COOKIE时不生效。

适用范围:如果pool的protocol为TCP、UDP和QUIC则范围为[1,60](分钟),默认值1; 如果pool的protocol为HTTP和HTTPS则范围为[1,1440](分钟),默认值1440。

表12 MasterSlaveHealthMonitor

参数

参数类型

描述

admin_state_up

Boolean

健康检查的管理状态。

取值:

  • true:表示开启健康检查,默认为true。

  • false表示关闭健康检查。

delay

Integer

健康检查间隔。取值:1-50s。

最小值:1

最大值:50

domain_name

String

发送健康检查请求的域名。

取值:以数字或字母开头,只能包含数字、字母、’-’、’.’。 默认为空,表示使用负载均衡器的vip作为http请求的目的地址。

使用说明:当type为HTTP/HTTPS时生效。

expected_codes

String

期望响应状态码。

取值:

  • 单值:单个返回码,例如200。

  • 列表:多个特定返回码,例如200,202。

  • 区间:一个返回码区间,例如200-204。

默认值:200。

仅支持HTTP/HTTPS设置该字段,其他协议设置不会生效。

http_method

String

HTTP请求方法。

取值:GET、HEAD、POST、PUT、DELETE、TRACE、OPTIONS、CONNECT、PATCH,默认GET。

使用说明:当type为HTTP/HTTPS时生效。

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

id

String

健康检查ID

max_retries

Integer

健康检查连续成功多少次后,将后端服务器的健康检查状态由OFFLINE判定为ONLINE。取值范围:1-10。

最小值:1

最大值:10

max_retries_down

Integer

健康检查连续失败多少次后,将后端服务器的健康检查状态由ONLINE判定为OFFLINE。取值范围:1-10,默认3。

最小值:1

最大值:10

monitor_port

Integer

健康检查端口号。取值:1-65535,默认为空,表示使用后端云服务器端口号。

最小值:1

最大值:65535

name

String

健康检查名称。

timeout

Integer

一次健康检查请求的超时时间。

建议该值小于delay的值。

最小值:1

最大值:50

type

String

健康检查请求协议。

取值:TCP、UDP_CONNECT、HTTP、HTTPS。

使用说明:

  • 若pool的protocol为QUIC,则type只能是UDP_CONNECT。

  • 若pool的protocol为UDP,则type只能UDP_CONNECT。

  • 若pool的protocol为TCP,则type可以是TCP、HTTP、HTTPS。

  • 若pool的protocol为HTTP,则type可以是TCP、HTTP、HTTPS。

  • 若pool的protocol为HTTPS,则type可以是TCP、HTTP、HTTPS。

url_path

String

健康检查请求的请求路径。以"/"开头,默认为"/"。

支持使用字母、数字和短划线(-)、正斜线(/)、半角句号(.)、百分号(%)、半角问号(?)、井号(#)和and(&)以及扩展字符集_;~!()*[]@$^:',+

使用说明:当type为HTTP/HTTPS时生效。

请求示例

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

响应示例

状态码: 200

操作正常返回。

{
  "pools" : [ {
    "lb_algorithm" : "ROUND_ROBIN",
    "protocol" : "HTTP",
    "description" : "",
    "loadbalancers" : [ {
      "id" : "309a0f61-0b62-45f2-97d1-742f3434338e"
    } ],
    "project_id" : "99a3fff0d03c428eac3678da6a7d0f24",
    "session_persistence" : {
      "cookie_name" : "my_cookie",
      "type" : "APP_COOKIE",
      "persistence_timeout" : 1
    },
    "healthmonitor" : {
      "monitor_port" : null,
      "id" : "36ce7086-a496-4666-9064-5ba0e6840c75",
      "domain_name" : "",
      "name" : "My Healthmonitor",
      "max_retries" : 3,
      "max_retries_down" : 3,
      "admin_state_up" : true,
      "type" : "HTTP",
      "timeout" : 30,
      "delay" : 1,
      "http_method" : "get",
      "url_path" : "/",
      "expected_codes" : "200"
    },
    "listeners" : [ ],
    "members" : [ {
      "admin_state_up" : true,
      "address" : "172.16.0.210",
      "protocol_port" : 80,
      "id" : "2e7b36d2-66c8-4825-bcd2-211d99978680",
      "operating_status" : "OFFLINE",
      "status" : [ ],
      "instance_id" : "",
      "device_id" : "",
      "device_owner" : "",
      "member_type" : "ip",
      "role" : "master",
      "ip_version" : "v4",
      "name" : "cx-test-master",
      "subnet_cidr_id" : ""
    }, {
      "admin_state_up" : true,
      "address" : "172.16.0.211",
      "protocol_port" : 81,
      "id" : "2e7b36d2-66c8-4823-bsd2-21sa199978681",
      "operating_status" : "OFFLINE",
      "status" : [ ],
      "instance_id" : "",
      "device_id" : "",
      "device_owner" : "",
      "member_type" : "ip",
      "role" : "slave",
      "ip_version" : "v4",
      "name" : "cx-test-slave",
      "subnet_cidr_id" : ""
    } ],
    "id" : "73bd4fe0-ffbb-4b56-aab4-4f26ddf7a103",
    "name" : "",
    "ip_version" : "v4",
    "type" : "ip",
    "vpc_id" : "",
    "created_at" : "2021-03-26T01:33:12Z",
    "updated_at" : "2021-03-26T01:33:12Z"
  }, {
    "lb_algorithm" : "SOURCE_IP",
    "protocol" : "TCP",
    "description" : "",
    "loadbalancers" : [ {
      "id" : "d9763e59-64b7-4e93-aec7-0ff7881ef9bc"
    } ],
    "project_id" : "99a3fff0d03c428eac3678da6a7d0f24",
    "session_persistence" : {
      "cookie_name" : "",
      "type" : "SOURCE_IP",
      "persistence_timeout" : 1
    },
    "healthmonitor" : {
      "monitor_port" : null,
      "id" : "36ce7086-a496-4666-9064-5ba0e6840c75",
      "domain_name" : "",
      "name" : "My Healthmonitor",
      "max_retries" : 3,
      "max_retries_down" : 3,
      "admin_state_up" : true,
      "type" : "HTTP",
      "timeout" : 30,
      "delay" : 1,
      "http_method" : "get",
      "url_path" : "/",
      "expected_codes" : "200"
    },
    "listeners" : [ {
      "id" : "8d21db6f-b475-429e-a9cb-90439b0413b2"
    } ],
    "members" : [ {
      "admin_state_up" : true,
      "address" : "172.16.1.210",
      "protocol_port" : 83,
      "id" : "2e7b36d2-9997-4825-bcd2-211d9990439b",
      "operating_status" : "OFFLINE",
      "status" : [ ],
      "instance_id" : "",
      "device_id" : "",
      "device_owner" : "",
      "member_type" : "ip",
      "role" : "master",
      "ip_version" : "v4",
      "name" : "cx-test-master",
      "subnet_cidr_id" : ""
    }, {
      "admin_state_up" : true,
      "address" : "172.16.1.212",
      "protocol_port" : 82,
      "id" : "227b31d2-66c1-4823-bsd2-21sa199978213",
      "operating_status" : "OFFLINE",
      "status" : [ ],
      "instance_id" : "",
      "device_id" : "",
      "device_owner" : "",
      "member_type" : "ip",
      "role" : "slave",
      "ip_version" : "v4",
      "name" : "cx-test-slave",
      "subnet_cidr_id" : ""
    } ],
    "id" : "74db02d1-5711-4c77-b383-a450e2b93142",
    "name" : "pool_tcp_001",
    "ip_version" : "dualstack",
    "type" : "ip",
    "vpc_id" : "",
    "created_at" : "2021-03-26T01:33:12Z",
    "updated_at" : "2021-03-26T01:33:12Z"
  } ],
  "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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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 ListMasterSlavePoolsSolution {

    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();
        ListMasterSlavePoolsRequest request = new ListMasterSlavePoolsRequest();
        request.withMarker("<marker>");
        request.withLimit(<limit>);
        request.withPageReverse(<page_reverse>);
        request.withDescription();
        request.withHealthmonitorId();
        request.withId();
        request.withName();
        request.withLoadbalancerId();
        request.withProtocol();
        request.withLbAlgorithm();
        request.withEnterpriseProjectId();
        request.withIpVersion();
        request.withMemberAddress();
        request.withMemberDeviceId();
        request.withListenerId();
        request.withMemberInstanceId();
        request.withVpcId();
        request.withType();
        try {
            ListMasterSlavePoolsResponse response = client.listMasterSlavePools(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
# 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 = ListMasterSlavePoolsRequest()
        request.marker = "<marker>"
        request.limit = <limit>
        request.page_reverse = <PageReverse>
        request.description = 
        request.healthmonitor_id = 
        request.id = 
        request.name = 
        request.loadbalancer_id = 
        request.protocol = 
        request.lb_algorithm = 
        request.enterprise_project_id = 
        request.ip_version = 
        request.member_address = 
        request.member_device_id = 
        request.listener_id = 
        request.member_instance_id = 
        request.vpc_id = 
        request.type = 
        response = client.list_master_slave_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
38
39
40
41
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.ListMasterSlavePoolsRequest{}
	markerRequest:= "<marker>"
	request.Marker = &markerRequest
	limitRequest:= int32(<limit>)
	request.Limit = &limitRequest
	pageReverseRequest:= <page_reverse>
	request.PageReverse = &pageReverseRequest
	response, err := client.ListMasterSlavePools(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

操作正常返回。

错误码

请参见错误码