هذه الصفحة غير متوفرة حاليًا بلغتك المحلية. نحن نعمل جاهدين على إضافة المزيد من اللغات. شاكرين تفهمك ودعمك المستمر لنا.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Elastic Load Balance/ API Reference/ APIs (V3)/ Active/Standby Backend Server Group/ Creating an Active/Standby Backend Server Group

Creating an Active/Standby Backend Server Group

Function

This API is used to create an active/standby backend server group.

Constraints

Note the following when you create a backend server group:

  • If session-persistence is specified, cookie_name is available only when type is set to APP_COOKIE.

  • If listener_id is specified, the listener must have no backend server group associated.

Calling Method

For details, see Calling APIs.

URI

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

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Specifies the project ID.

Request Parameters

Table 2 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Specifies the token used for IAM authentication.

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

pool

Yes

CreateMasterSlavePoolOption object

Specifies the request body for creating a backend server group.

Table 4 CreateMasterSlavePoolOption

Parameter

Mandatory

Type

Description

description

No

String

Specifies supplementary information about the active/standby backend server group.

lb_algorithm

Yes

String

Specifies the load balancing algorithm used by the load balancer to route requests to backend servers in the associated backend server group.

Value options:

  • ROUND_ROBIN: weighted round robin

  • LEAST_CONNECTIONS: weighted least connections

  • SOURCE_IP: source IP hash

  • QUIC_CID: connection ID

loadbalancer_id

No

String

Specifies the ID of the load balancer associated with the backend server group.

Note: Specify at least one of listener_id, loadbalancer_id, or type.

listener_id

No

String

Specifies the ID of the listener associated with the backend server group.

Note: Specify at least one of listener_id, loadbalancer_id, or type.

name

No

String

Specifies the backend server group name.

project_id

No

String

Specifies the project ID of the backend server group.

protocol

Yes

String

Specifies the protocol used by the backend server group to receive requests.

The value can be TCP, UDP, QUIC, or TLS.

Note:

  • If the listener's protocol is UDP, the protocol of the backend server group must be UDP or QUIC.

  • If the listener's protocol is TCP, the protocol of the backend server group must be TCP.

  • If the listener's protocol is QUIC, the protocol of the backend server group can be HTTP, HTTPS, or GRPC.

  • If the listener's protocol is TLS, the protocol of the backend server group can be TLS or TCP. If protocol of the backend server group is TCP, the ip_version must be set to v4.

session_persistence

No

CreatePoolSessionPersistenceOption object

Specifies the sticky session.

vpc_id

No

String

Specifies the ID of the VPC where the backend server group works.

Note:

  • If vpc_id is not specified:

    • The backend server active/standby group must be associated with the VPC.

    • Only backend servers in the VPC or IP as backend servers can be added.

    • type must be set to instance.

  • If vpc_id is not specified:

    • vpc_id is determined by the VPC where the backend server works.

type

Yes

String

Specifies the type of the backend server group.

Value options:

  • instance: Any type of backend servers can be added. vpc_id is mandatory.

  • ip: Only IP as backend servers can be added. vpc_id cannot be specified.

ip_version

No

String

Specifies the IP address version supported by the backend server group.

  • Shared load balancers: The value is fixed at v4.

  • Dedicated load balancers: The value can be dualstack, v6, or v4. If the protocol of the backend server group is TCP, UDP, or QUIC, the value is dualstack. If the protocol of the backend server group is HTTP, the value is v4.

members

Yes

Array of CreateMasterSlaveMemberOption objects

Specifies the backend servers in the active/standby server group.

Only two backend servers can be added, one serving as the active server and the other as the standby server.

healthmonitor

Yes

CreateMasterSlaveHealthMonitorOption object

Specifies the health check for active/standby backend server group. Health check is enabled by default and cannot be disabled.

any_port_enable

No

Boolean

Specifies whether to enable any_port_enable for a backend server group. If this option is enabled, the listener routes the requests to the backend server over the same port as the frontend port. If this option is disabled, the listener routes the requests over the port specified by protocol_port.

Value options:

  • false: Disable this option.

  • true: Enable this option.

Note: This option is available only for TCP, UDP, or QUIC backend server groups.

connection_drain

No

ConnectionDrain object

Specifies the configurations of deregistration delay. This parameter is only available for TCP, UDP, and QUIC backend server groups and TCP and UDP listeners.

This parameter takes effect when:

  • A backend server is removed from a backend server group.

  • A backend server is detected unhealthy or health checks fail.

  • The weight of a backend server is 0.

quic_cid_hash_strategy

No

QuicCidHashStrategy object

Specifies multi-path distribution configuration based on destination connection IDs.

Table 5 CreatePoolSessionPersistenceOption

Parameter

Mandatory

Type

Description

cookie_name

No

String

Specifies the cookie name.

Note:

  • This parameter will take effect only when type is set to APP_COOKIE. Otherwise, an error will be returned.

Value ranges:

  • For shared load balancers, the name can contain a maximum of 64 characters, including letters, digits, underscores (_), and hyphens (-).

  • For dedicated load balancers, the name can contain a maximum of 255 characters, including letters, digits, underscores (_), hyphens (-), and periods (.).

type

Yes

String

Specifies the sticky session type.

The value can be SOURCE_IP, HTTP_COOKIE, or APP_COOKIE.

Note:

  • If the protocol of the backend server group is TCP or UDP, only SOURCE_IP takes effect.

  • If the protocol of the backend server group is HTTP or HTTPS, the value can be HTTP_COOKIE or APP_COOKIE.

  • If the backend server group protocol is QUIC, sticky session must be enabled with type set to SOURCE_IP.

persistence_timeout

No

Integer

Specifies the stickiness duration, in minutes. This parameter will not take effect when type is set to APP_COOKIE.

Value ranges:

  • If the protocol of the backend server group is TCP or UDP, the value ranges from 1 to 60, and the default value is 1.

  • If the protocol of the backend server group is HTTP or HTTPS, the value ranges from 1 to 1440, and the default value is 1440.

Table 6 CreateMasterSlaveMemberOption

Parameter

Mandatory

Type

Description

address

Yes

String

Specifies the private IP address bound to the backend server.

Note:

  • If subnet_cidr_id is left blank, IP as a Backend is enabled. In this case, the IP address must be an IPv4 address.

  • If subnet_cidr_id is not left blank, the IP address can be IPv4 or IPv6. It must be in the subnet specified by subnet_cidr_id.

admin_state_up

No

Boolean

Specifies the administrative status of the backend server.

The value can only be true.

Although this parameter can be used in the APIs for creating and updating backend servers, its actual value depends on whether cloud servers exist. If cloud servers exist, the value is true. Otherwise, the value is false.

name

No

String

Specifies the backend server name.

protocol_port

No

Integer

Specifies the port used by the backend server to receive requests.

NOTE:

This parameter can be left blank because it does not take effect if any_port_enable is set to true for a backend server group.

subnet_cidr_id

No

String

Specifies the ID of the IPv4 or IPv6 subnet where the backend server resides.

Note:

  • The IPv4 or IPv6 subnet must be in the same VPC as the subnet of the load balancer.

  • If this parameter is not passed, IP as a Backend has been enabled for the load balancer. In this case, IP as backend servers must use private IPv4 addresses, and the protocol of the backend server group must be TCP, UDP, TLS, HTTP, HTTPS, QUIC, or GRPC.

role

Yes

String

Specifies the type of the backend server.

Value options:

  • master: active backend server

  • slave: standby backend server

Table 7 CreateMasterSlaveHealthMonitorOption

Parameter

Mandatory

Type

Description

delay

Yes

Integer

Specifies the interval between health checks, in seconds. The value ranges from 1 to 50.

domain_name

No

String

Specifies the domain name that HTTP requests are sent to during the health check.

The value can contain only digits, letters, hyphens (-), and periods (.) and must start with a digit or letter.

The value is left blank by default, indicating that the virtual IP address of the load balancer is used as the destination address of HTTP requests.

This parameter is available only when type is set to HTTP or HTTPS.

expected_codes

No

String

Specifies the expected HTTP status code. This parameter will take effect only when type is set to HTTP, HTTPS, or GRPC.

The value options are as follows:

  • A specific value, for example, 200

  • A list of values that are separated with commas (,), for example, 200, 202

  • A value range, for example, 200-204

The default value is 200.

http_method

No

String

Specifies the HTTP method. The value can be GET, HEAD, or POST. The default value is GET.

This parameter is available when type is set to HTTP or HTTPS.

max_retries

Yes

Integer

Specifies the number of consecutive health checks when the health check result of a backend server changes from OFFLINE to ONLINE. The value ranges from 1 to 10.

max_retries_down

No

Integer

Specifies the number of consecutive health checks when the health check result of a backend server changes from ONLINE to OFFLINE.

The value ranges from 1 to 10, and the default value is 3.

monitor_port

No

Integer

Specifies the port used for the health check. If this parameter is left blank, the port of the backend server will be used by default. The port number ranges from 1 to 65535.

name

No

String

Specifies the health check name.

timeout

Yes

Integer

Specifies the maximum time required for waiting for a response from the health check, in seconds.

It is recommended that you set the value less than that of parameter delay.

type

Yes

String

Specifies the health check protocol. The value can be TCP, UDP_CONNECT, HTTP, or HTTPS.

Note:

  • If the protocol of the backend server is QUIC, the value can only be UDP_CONNECT.

  • If the protocol of the backend server is UDP, the value can only be UDP_CONNECT.

  • If the protocol of the backend server is TCP, the value can only be TCP, HTTP, or HTTPS.

  • If the protocol of the backend server is HTTP, the value can only be TCP, HTTP, or HTTPS.

  • If the protocol of the backend server is HTTPS, the value can only be TCP, HTTP, or HTTPS.

url_path

No

String

Specifies the HTTP request path for the health check. The value must start with a slash (/), and the default value is /.

The value can contain letters, digits, hyphens (-), slashes (/), periods (.), percentage signs (%), question marks (?), pound signs (#), ampersand signs (&), and the extended character set: _;~!()*[]@$^:',+.

Note: This parameter is available only when type is set to HTTP or HTTPS.

Table 8 ConnectionDrain

Parameter

Mandatory

Type

Description

enable

No

Boolean

Specifies whether to enable connection_drain.

Value options:

  • true: Enable this option.

  • false: Disable this option.

    Default value: true

timeout

No

Integer

Specifies the deregistration delay timeout, in seconds. The value ranges from 10 to 4000.

Table 9 QuicCidHashStrategy

Parameter

Mandatory

Type

Description

len

Yes

Integer

Specifies the length of the hash factor in the connection ID, in byte. This parameter is valid only when the load balancing algorithm is QUIC_CID.

Value range: 1 to 20

Default value: 3

offset

Yes

Integer

Specifies the start position in the connection ID as the hash factor, in byte. This parameter is valid only when the load balancing algorithm is QUIC_CID.

Value range: 0 to 19

Default value: 1

Response Parameters

Status code: 201

Table 10 Response body parameters

Parameter

Type

Description

request_id

String

Specifies the request ID.

Note: The value is automatically generated.

pool

MasterSlavePool object

Specifies the active/standby backend server group.

Table 11 MasterSlavePool

Parameter

Type

Description

description

String

Specifies supplementary information about the active/standby backend server group.

id

String

Specifies the ID of the active/standby backend server group.

lb_algorithm

String

Specifies the load balancing algorithm used by the load balancer to route requests to backend servers in the associated backend server group.

Value options:

  • ROUND_ROBIN: weighted round robin

  • LEAST_CONNECTIONS: weighted least connections

  • SOURCE_IP: source IP hash

  • QUIC_CID: connection ID

Note:

  • If the value is SOURCE_IP, the weight parameter will not take effect for backend servers.

  • QUIC_CID is supported only when the protocol of the backend server group is QUIC.

listeners

Array of ListenerRef objects

Specifies the IDs of the listeners with which the backend server group is associated.

loadbalancers

Array of LoadBalancerRef objects

Specifies the IDs of the load balancers with which the backend server group is associated.

members

Array of MasterSlaveMember objects

Specifies the backend servers in the active/standby backend server group.

name

String

Specifies the backend server group name.

project_id

String

Specifies the project ID.

protocol

String

Specifies the protocol used by the backend server group to receive requests.

The value can be TCP, UDP, QUIC, or TLS.

Note:

  • If the listener's protocol is UDP, the protocol of the backend server group must be UDP or QUIC.

  • If the listener's protocol is TCP, the protocol of the backend server group must be TCP.

  • If the listener's is QUIC, the protocol of the backend server group can be HTTP, HTTPS, or GRPC.

  • If the listener's protocol is TLS, the protocol of the backend server group can be TLS or TCP. If protocol of the backend server group is TCP, the ip_version must be set to v4.

session_persistence

SessionPersistence object

Specifies the sticky session.

ip_version

String

Specifies the IP address version supported by the backend server group.

  • Shared load balancers: The value is fixed at v4.

  • Dedicated load balancers: The value can be dualstack or v4. If the protocol of the backend server group is TCP, UDP, or QUIC, the value is dualstack. If the protocol of the backend server group is HTTP or HTTPS, the value is v4.

created_at

String

Specifies the time when the backend server group was created. The format is yyyy-MM-dd'T'HH:mm:ss'Z' (UTC time).

This is a new field in this version, and it will not be returned for resources associated with existing dedicated load balancers and for resources associated with existing and new shared load balancers.

updated_at

String

Specifies the time when the backend server group was updated. The format is yyyy-MM-dd'T'HH:mm:ss'Z' (UTC time).

This is a new field in this version, and it will not be returned for resources associated with existing dedicated load balancers and for resources associated with existing and new shared load balancers.

vpc_id

String

Specifies the ID of the VPC where the active/standby backend server group works.

type

String

Specifies the type of the active/standby backend server group.

Value options:

  • instance: Any type of backend servers can be added. vpc_id is mandatory.

  • ip: Only IP as backend servers can be added. vpc_id cannot be specified.

  • "": Any type of backend servers can be added.

enterprise_project_id

String

Specifies the enterprise project ID of the backend server group. All created projects belong to the default enterprise project.

healthmonitor

MasterSlaveHealthMonitor object

Specifies the health check configured for the active/standby backend server group.

any_port_enable

Boolean

Specifies whether to enable any_port_enable for a backend server group. If this option is enabled, the listener routes the requests to the backend server over the same port as the frontend port. If this option is disabled, the listener routes the requests over the port specified by protocol_port.

Value options:

  • false: Disable this option.

  • true: Enable this option.

Note: This option is available only for TCP, UDP, or QUIC backend server groups.

connection_drain

ConnectionDrain object

Specifies the configurations of deregistration delay. This parameter is only available for TCP, UDP, and QUIC backend server groups and TCP and UDP listeners.

This parameter takes effect when:

  • A backend server is removed from a backend server group.

  • A backend server is detected unhealthy or health checks fail.

  • The weight of a backend server is 0.

quic_cid_hash_strategy

QuicCidHashStrategy object

Specifies multi-path distribution configuration based on destination connection IDs.

Table 12 ListenerRef

Parameter

Type

Description

id

String

Specifies the listener ID.

Table 13 LoadBalancerRef

Parameter

Type

Description

id

String

Specifies the load balancer ID.

Table 14 MasterSlaveMember

Parameter

Type

Description

id

String

Specifies the backend server ID.

name

String

Specifies the backend server name.

admin_state_up

Boolean

Specifies the administrative status of the backend server.

The value can be true or false.

Although this parameter can be used in the APIs for creating and updating backend servers, its actual value depends on whether ECSs exist. If ECSs exist, the value is true. Otherwise, the value is false.

subnet_cidr_id

String

Specifies the ID of the IPv4 or IPv6 subnet where the backend server resides.

This parameter can be left blank, indicating that IP as a Backend has been enabled for the load balancer. In this case, IP addresses of these servers must be IPv4 addresses, and the protocol of the backend server group must be UDP, TCP, TLS, HTTP, HTTPS, QUIC, or GRPC.

The IPv4 or IPv6 subnet must be in the same VPC as the subnet of the load balancer.

protocol_port

Integer

Specifies the port used by the backend server to receive requests.

NOTE:

This parameter can be left blank because it does not take effect if any_port_enable is set to true for a backend server group.

address

String

Specifies the private IP address bound to the backend server.

Note:

  • If subnet_cidr_id is left blank, IP as a Backend is enabled. In this case, the IP address must be an IPv4 address.

  • If subnet_cidr_id is not left blank, the IP address can be IPv4 or IPv6. It must be in the subnet specified by subnet_cidr_id.

ip_version

String

Specifies the IP version supported by the backend server. The value can be v4 (IPv4) or v6 (IPv6), depending on the value of address returned by the system.

device_owner

String

Specifies whether the backend server is associated with an ECS.

  • If this parameter is left blank, the backend server is not associated with an ECS.

  • If the value is compute:{az_name}, the backend server is associated with an ECS. {az_name} indicates the AZ where the ECS resides.

This parameter is unsupported. Please do not use it.

device_id

String

Specifies the ID of the ECS with which the backend server is associated. If this parameter is left blank, the backend server is not associated with an ECS.

This parameter is unsupported. Please do not use it.

operating_status

String

Specifies the health status of the backend server if listener_id under status is not specified.

Value options:

  • ONLINE: The backend server is running normally.

  • NO_MONITOR: No health check is configured for the backend server group to which the backend server belongs.

  • OFFLINE: The cloud server used as the backend server is stopped or does not exist.

reason

MemberHealthCheckFailedReason object

Specifies why health check fails.

member_type

String

Specifies the type of the backend server.

Value options:

  • ip: IP as backend servers

  • instance: ECSs used as backend servers

instance_id

String

Specifies the ID of the instance associated with the backend server. If this parameter is left blank, the backend server is not a real device. It may be an IP address.

role

String

Specifies the type of the backend server.

status

Array of ListenerMemberInfo objects

Specifies the health status of the backend server if listener_id under status is specified. If listener_id under status is not specified, operating_status of member takes precedence.

Table 15 MemberHealthCheckFailedReason

Parameter

Type

Description

reason_code

String

Specifies the code of the health check failures.

Value options:

  • CONNECT_TIMEOUT: The connection with the backend server times out during a health check.

  • CONNECT_REFUSED: The load balancer rejects connections with the backend server during a health check.

  • CONNECT_FAILED: The load balancer fails to establish connections with the backend server during a health check.

  • CONNECT_INTERRUPT: The load balancer is disconnected from the backend server during a health check.

  • SSL_HANDSHAKE_ERROR: The SSL handshakes with the backend server fail during a health check.

  • RECV_RESPONSE_FAILED: The load balancer fails to receive responses from the backend server during a health check.

  • RECV_RESPONSE_TIMEOUT: The load balancer does not receive responses from the backend server within the timeout duration during a health check.

  • SEND_REQUEST_FAILED: The load balancer fails to send a health check request to the backend server during a health check.

  • SEND_REQUEST_TIMEOUT: The load balancer fails to send a health check request to the backend server within the timeout duration.

  • RESPONSE_FORMAT_ERROR: The load balancer receives invalid responses from the backend server during a health check.

  • RESPONSE_MISMATCH: The response code received from the backend server is different from the preset code.

expected_response

String

Specifies the expected HTTP status code.

This parameter will take effect only when type is set to HTTP, HTTPS, or GRPC.

The status code cannot be null if reason_code is RESPONSE_MISMATCH.

Value ranges:

  • A specific status code. If type is set to GRPC, the status code ranges from 0 to 99. If type is set to other values, the status code ranges from 200 to 599. For example, the status code can be 0 or 200.

  • A list of status codes that are separated with commas (,), for example, 200,202 or 0,1. A maximum of five status codes are supported.

  • A status code range. Different ranges are separated with commas (,), for example, 200-204,300-399 or 0-5,10-12,20-30. A maximum of five ranges are supported.

healthcheck_response

String

Specifies the returned HTTP status code in the response.

This parameter will take effect only when type is set to HTTP, HTTPS, or GRPC.

The status code cannot be null if reason_code is RESPONSE_MISMATCH.

Value range: A specific status code. If type is set to GRPC, the status code ranges from 0 to 99. If type is set to other values, the status code ranges from 200 to 599. For example, the status code can be 0 or 200.

Table 16 ListenerMemberInfo

Parameter

Type

Description

listener_id

String

Specifies the ID of the listener associated with the backend server.

operating_status

String

Specifies the health status of the backend server.

Value options:

  • ONLINE: The backend server is running normally.

  • NO_MONITOR: No health check is configured for the backend server group to which the backend server belongs.

  • OFFLINE: The cloud server used as the backend server is stopped or does not exist.

Table 17 SessionPersistence

Parameter

Type

Description

cookie_name

String

Specifies the cookie name.

Note:

  • This parameter will take effect only when type is set to APP_COOKIE. Otherwise, an error will be returned.

Value ranges:

  • For shared load balancers, the name can contain a maximum of 64 characters, including letters, digits, underscores (_), and hyphens (-).

  • For dedicated load balancers, the name can contain a maximum of 255 characters, including letters, digits, underscores (_), hyphens (-), and periods (.).

type

String

Specifies the sticky session type.

The value can be SOURCE_IP, HTTP_COOKIE, or APP_COOKIE.

Note:

  • If the protocol of the backend server group is TCP or UDP, only SOURCE_IP takes effect.

  • If the protocol of the backend server group is HTTP or HTTPS, the value can be HTTP_COOKIE or APP_COOKIE.

  • If the backend server group protocol is QUIC, sticky session must be enabled with type set to SOURCE_IP.

persistence_timeout

Integer

Specifies the stickiness duration, in minutes. This parameter will not take effect when type is set to APP_COOKIE.

  • If the protocol of the backend server group is TCP, UDP, or QUIC, the value ranges from 1 to 60, and the default value is 1.

  • If the protocol of the backend server group is HTTP or HTTPS, the value ranges from 1 to 1440, and the default value is 1440.

Table 18 MasterSlaveHealthMonitor

Parameter

Type

Description

admin_state_up

Boolean

Specifies the administrative status of the health check.

  • true (default) indicates that the health check is enabled.

  • false indicates that the health check is disabled.

delay

Integer

Specifies the interval between health checks, in seconds. The value ranges from 1 to 50.

domain_name

String

Specifies the domain name that HTTP requests are sent to during the health check.

The value can contain only digits, letters, hyphens (-), and periods (.) and must start with a digit or letter.

The value is left blank by default, indicating that the virtual IP address of the load balancer is used as the destination address of HTTP requests.

This parameter is available only when type is set to HTTP or HTTPS.

expected_codes

String

Specifies the expected HTTP status code. This parameter will take effect only when type is set to HTTP, HTTPS or GRPC.

The value options are as follows:

  • A specific value, for example, 200

  • A list of values that are separated with commas (,), for example, 200, 202

  • A value range, for example, 200-204

The default value is 200.

http_method

String

Specifies the HTTP method. The value can be GET, HEAD, or POST. The default value is GET.

This parameter is available when type is set to HTTP or HTTPS.

id

String

Specifies the health check ID.

max_retries

Integer

Specifies the number of consecutive health checks when the health check result of a backend server changes from OFFLINE to ONLINE. The value ranges from 1 to 10.

max_retries_down

Integer

Specifies the number of consecutive health checks when the health check result of a backend server changes from ONLINE to OFFLINE.

The value ranges from 1 to 10, and the default value is 3.

monitor_port

Integer

Specifies the port used for the health check. If this parameter is left blank, the port of the backend server will be used by default. The port number ranges from 1 to 65535.

name

String

Specifies the health check name.

timeout

Integer

Specifies the maximum time required for waiting for a response from the health check, in seconds.

It is recommended that you set the value less than that of parameter delay.

type

String

Specifies the health check protocol. The value can be TCP, UDP_CONNECT, HTTP, or HTTPS.

Note:

  • If the protocol of the backend server is QUIC, the value can only be UDP_CONNECT.

  • If the protocol of the backend server is UDP, the value can only be UDP_CONNECT.

  • If the protocol of the backend server is TCP, the value can only be TCP, HTTP, or HTTPS.

  • If the protocol of the backend server is HTTP, the value can only be TCP, HTTP, or HTTPS.

  • If the protocol of the backend server is HTTPS, the value can only be TCP, HTTP, or HTTPS.

url_path

String

Specifies the HTTP request path for the health check. The value must start with a slash (/), and the default value is /.

The value can contain letters, digits, hyphens (-), slashes (/), periods (.), percentage signs (%), question marks (?), pound signs (#), ampersand signs (&), and the extended character set: _;~!()*[]@$^:',+.

Note: This parameter is available only when type is set to HTTP or HTTPS.

Table 19 ConnectionDrain

Parameter

Type

Description

enable

Boolean

Specifies whether to enable connection_drain.

Value options:

  • true: Enable this option.

  • false: Disable this option.

    Default value: true

timeout

Integer

Specifies the deregistration delay timeout, in seconds. The value ranges from 10 to 4000.

Table 20 QuicCidHashStrategy

Parameter

Type

Description

len

Integer

Specifies the length of the hash factor in the connection ID, in byte. This parameter is valid only when the load balancing algorithm is QUIC_CID.

Value range: 1 to 20

Default value: 3

offset

Integer

Specifies the start position in the connection ID as the hash factor, in byte. This parameter is valid only when the load balancing algorithm is QUIC_CID.

Value range: 0 to 19

Default value: 1

Example Requests

POST https://{ELB_Endpoint}/v3/99a3fff0d03c428eac3678da6a7d0f24/elb/master-slave-pools

{
  "pool" : {
    "name" : "My pool",
    "lb_algorithm" : "LEAST_CONNECTIONS",
    "listener_id" : "0b11747a-b139-492f-9692-2df0b1c87193",
    "protocol" : "TCP",
    "type" : "ip",
    "members" : [ {
      "protocol_port" : 89,
      "name" : "My member",
      "address" : "120.10.10.16",
      "role" : "master"
    }, {
      "protocol_port" : 89,
      "address" : "110.4.10.16",
      "role" : "slave"
    } ],
    "healthmonitor" : {
      "name" : "My Healthmonitor",
      "max_retries" : 3,
      "type" : "HTTP",
      "timeout" : 30,
      "delay" : 1
    }
  }
}

Example Responses

Status code: 201

Normal response to POST requests.

{
  "pool" : {
    "lb_algorithm" : "LEAST_CONNECTIONS",
    "type" : "ip",
    "vpc_id" : "3sae7086-a416-4666-9064-5b340e6840125",
    "protocol" : "TCP",
    "description" : "",
    "loadbalancers" : [ {
      "id" : "098b2f68-af1c-41a9-8efd-69958722af62"
    } ],
    "project_id" : "99a3fff0d03c428eac3678da6a7d0f24",
    "session_persistence" : null,
    "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" : "0b11747a-b139-492f-9692-2df0b1c87193"
    } ],
    "members" : [ {
      "admin_state_up" : true,
      "address" : "172.16.0.210",
      "protocol_port" : 80,
      "id" : "2e7b36d2-66c8-4825-bcd2-211d99978680",
      "operating_status" : "OFFLINE",
      "status" : [ {
        "listener_id" : "0b11747a-b139-492f-9692-2df0b1c87193",
        "operating_status" : "OFFLINE"
      } ],
      "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",
      "instance_id" : "",
      "device_id" : "",
      "device_owner" : "",
      "member_type" : "ip",
      "role" : "slave",
      "ip_version" : "v4",
      "name" : "cx-test-slave",
      "subnet_cidr_id" : "",
      "status" : [ {
        "listener_id" : "0b11747a-b139-492f-9692-2df0b1c87193",
        "operating_status" : "OFFLINE"
      } ]
    } ],
    "id" : "36ce7086-a496-4666-9064-5ba0e6840c75",
    "name" : "My pool",
    "ip_version" : "dualstack",
    "created_at" : "2021-03-26T01:33:12Z",
    "updated_at" : "2021-03-26T01:33:12Z"
  },
  "request_id" : "2d974978-0733-404d-a21a-b29204f4803a"
}

SDK Sample Code

The SDK sample code is as follows.

 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
80
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 CreateMasterSlavePoolSolution {

    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();
        CreateMasterSlavePoolRequest request = new CreateMasterSlavePoolRequest();
        CreateMasterSlavePoolRequestBody body = new CreateMasterSlavePoolRequestBody();
        CreateMasterSlaveHealthMonitorOption healthmonitorPool = new CreateMasterSlaveHealthMonitorOption();
        healthmonitorPool.withDelay(1)
            .withMaxRetries(3)
            .withName("My Healthmonitor")
            .withTimeout(30)
            .withType("HTTP");
        List<CreateMasterSlaveMemberOption> listPoolMembers = new ArrayList<>();
        listPoolMembers.add(
            new CreateMasterSlaveMemberOption()
                .withAddress("120.10.10.16")
                .withName("My member")
                .withProtocolPort(89)
                .withRole(CreateMasterSlaveMemberOption.RoleEnum.fromValue("master"))
        );
        listPoolMembers.add(
            new CreateMasterSlaveMemberOption()
                .withAddress("110.4.10.16")
                .withProtocolPort(89)
                .withRole(CreateMasterSlaveMemberOption.RoleEnum.fromValue("slave"))
        );
        CreateMasterSlavePoolOption poolbody = new CreateMasterSlavePoolOption();
        poolbody.withLbAlgorithm("LEAST_CONNECTIONS")
            .withListenerId("0b11747a-b139-492f-9692-2df0b1c87193")
            .withName("My pool")
            .withProtocol("TCP")
            .withType("ip")
            .withMembers(listPoolMembers)
            .withHealthmonitor(healthmonitorPool);
        body.withPool(poolbody);
        request.withBody(body);
        try {
            CreateMasterSlavePoolResponse response = client.createMasterSlavePool(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
58
59
60
61
62
63
# 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 = CreateMasterSlavePoolRequest()
        healthmonitorPool = CreateMasterSlaveHealthMonitorOption(
            delay=1,
            max_retries=3,
            name="My Healthmonitor",
            timeout=30,
            type="HTTP"
        )
        listMembersPool = [
            CreateMasterSlaveMemberOption(
                address="120.10.10.16",
                name="My member",
                protocol_port=89,
                role="master"
            ),
            CreateMasterSlaveMemberOption(
                address="110.4.10.16",
                protocol_port=89,
                role="slave"
            )
        ]
        poolbody = CreateMasterSlavePoolOption(
            lb_algorithm="LEAST_CONNECTIONS",
            listener_id="0b11747a-b139-492f-9692-2df0b1c87193",
            name="My pool",
            protocol="TCP",
            type="ip",
            members=listMembersPool,
            healthmonitor=healthmonitorPool
        )
        request.body = CreateMasterSlavePoolRequestBody(
            pool=poolbody
        )
        response = client.create_master_slave_pool(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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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.CreateMasterSlavePoolRequest{}
	nameHealthmonitor:= "My Healthmonitor"
	healthmonitorPool := &model.CreateMasterSlaveHealthMonitorOption{
		Delay: int32(1),
		MaxRetries: int32(3),
		Name: &nameHealthmonitor,
		Timeout: int32(30),
		Type: "HTTP",
	}
	nameMembers:= "My member"
	protocolPortMembers:= int32(89)
	protocolPortMembers1:= int32(89)
	var listMembersPool = []model.CreateMasterSlaveMemberOption{
        {
            Address: "120.10.10.16",
            Name: &nameMembers,
            ProtocolPort: &protocolPortMembers,
            Role: model.GetCreateMasterSlaveMemberOptionRoleEnum().MASTER,
        },
        {
            Address: "110.4.10.16",
            ProtocolPort: &protocolPortMembers1,
            Role: model.GetCreateMasterSlaveMemberOptionRoleEnum().SLAVE,
        },
    }
	listenerIdPool:= "0b11747a-b139-492f-9692-2df0b1c87193"
	namePool:= "My pool"
	poolbody := &model.CreateMasterSlavePoolOption{
		LbAlgorithm: "LEAST_CONNECTIONS",
		ListenerId: &listenerIdPool,
		Name: &namePool,
		Protocol: "TCP",
		Type: "ip",
		Members: listMembersPool,
		Healthmonitor: healthmonitorPool,
	}
	request.Body = &model.CreateMasterSlavePoolRequestBody{
		Pool: poolbody,
	}
	response, err := client.CreateMasterSlavePool(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

 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
80
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 CreateMasterSlavePoolSolution {

    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();
        CreateMasterSlavePoolRequest request = new CreateMasterSlavePoolRequest();
        CreateMasterSlavePoolRequestBody body = new CreateMasterSlavePoolRequestBody();
        CreateMasterSlaveHealthMonitorOption healthmonitorPool = new CreateMasterSlaveHealthMonitorOption();
        healthmonitorPool.withDelay(1)
            .withMaxRetries(3)
            .withName("My Healthmonitor")
            .withTimeout(30)
            .withType("HTTP");
        List<CreateMasterSlaveMemberOption> listPoolMembers = new ArrayList<>();
        listPoolMembers.add(
            new CreateMasterSlaveMemberOption()
                .withAddress("120.10.10.16")
                .withName("My member")
                .withProtocolPort(89)
                .withRole(CreateMasterSlaveMemberOption.RoleEnum.fromValue("master"))
        );
        listPoolMembers.add(
            new CreateMasterSlaveMemberOption()
                .withAddress("110.4.10.16")
                .withProtocolPort(89)
                .withRole(CreateMasterSlaveMemberOption.RoleEnum.fromValue("slave"))
        );
        CreateMasterSlavePoolOption poolbody = new CreateMasterSlavePoolOption();
        poolbody.withLbAlgorithm("LEAST_CONNECTIONS")
            .withListenerId("0b11747a-b139-492f-9692-2df0b1c87193")
            .withName("My pool")
            .withProtocol("TCP")
            .withType("ip")
            .withMembers(listPoolMembers)
            .withHealthmonitor(healthmonitorPool);
        body.withPool(poolbody);
        request.withBody(body);
        try {
            CreateMasterSlavePoolResponse response = client.createMasterSlavePool(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
58
59
60
61
62
63
# 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 = CreateMasterSlavePoolRequest()
        healthmonitorPool = CreateMasterSlaveHealthMonitorOption(
            delay=1,
            max_retries=3,
            name="My Healthmonitor",
            timeout=30,
            type="HTTP"
        )
        listMembersPool = [
            CreateMasterSlaveMemberOption(
                address="120.10.10.16",
                name="My member",
                protocol_port=89,
                role="master"
            ),
            CreateMasterSlaveMemberOption(
                address="110.4.10.16",
                protocol_port=89,
                role="slave"
            )
        ]
        poolbody = CreateMasterSlavePoolOption(
            lb_algorithm="LEAST_CONNECTIONS",
            listener_id="0b11747a-b139-492f-9692-2df0b1c87193",
            name="My pool",
            protocol="TCP",
            type="ip",
            members=listMembersPool,
            healthmonitor=healthmonitorPool
        )
        request.body = CreateMasterSlavePoolRequestBody(
            pool=poolbody
        )
        response = client.create_master_slave_pool(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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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.CreateMasterSlavePoolRequest{}
	nameHealthmonitor:= "My Healthmonitor"
	healthmonitorPool := &model.CreateMasterSlaveHealthMonitorOption{
		Delay: int32(1),
		MaxRetries: int32(3),
		Name: &nameHealthmonitor,
		Timeout: int32(30),
		Type: "HTTP",
	}
	nameMembers:= "My member"
	protocolPortMembers:= int32(89)
	protocolPortMembers1:= int32(89)
	var listMembersPool = []model.CreateMasterSlaveMemberOption{
        {
            Address: "120.10.10.16",
            Name: &nameMembers,
            ProtocolPort: &protocolPortMembers,
            Role: model.GetCreateMasterSlaveMemberOptionRoleEnum().MASTER,
        },
        {
            Address: "110.4.10.16",
            ProtocolPort: &protocolPortMembers1,
            Role: model.GetCreateMasterSlaveMemberOptionRoleEnum().SLAVE,
        },
    }
	listenerIdPool:= "0b11747a-b139-492f-9692-2df0b1c87193"
	namePool:= "My pool"
	poolbody := &model.CreateMasterSlavePoolOption{
		LbAlgorithm: "LEAST_CONNECTIONS",
		ListenerId: &listenerIdPool,
		Name: &namePool,
		Protocol: "TCP",
		Type: "ip",
		Members: listMembersPool,
		Healthmonitor: healthmonitorPool,
	}
	request.Body = &model.CreateMasterSlavePoolRequestBody{
		Pool: poolbody,
	}
	response, err := client.CreateMasterSlavePool(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

For SDK sample code of more programming languages, see the Sample Code tab in API Explorer. SDK sample code can be automatically generated.

Status Codes

Status Code

Description

201

Normal response to POST requests.

Error Codes

See Error Codes.

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback