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
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
project_id |
Yes |
String |
Definition: Specifies the project ID. For details about how to obtain a project ID, see Obtaining a Project ID. Constraints: N/A Range: The value can contain a maximum of 32 characters, including digits and lowercase letters. Default value: N/A |
Request Parameters
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
X-Auth-Token |
Yes |
String |
Definition: Specifies the token used for IAM authentication. Constraints: N/A Range: N/A Default value: N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
pool |
Yes |
CreateMasterSlavePoolOption object |
Definition: Specifies the request body for creating an active/standby backend server group. Constraints: N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
description |
No |
String |
Definition: Specifies the supplementary information about the backend server group. Constraints: N/A Range: N/A Default value: N/A |
lb_algorithm |
Yes |
String |
Definition: Specifies the load balancing algorithm used by the load balancer to route requests to backend servers in the associated backend server group. Constraints: N/A Range:
Default value: N/A |
loadbalancer_id |
No |
String |
Definition: Specifies the ID of the load balancer associated with the backend server group. Constraints: Specify at least one of listener_id, loadbalancer_id, or type. Range: N/A Default value: N/A |
listener_id |
No |
String |
Definition: Specifies the ID of the listener associated with the backend server group. Constraints: Specify at least one of listener_id, loadbalancer_id, or type. Range: N/A Default value: N/A |
name |
No |
String |
Definition: Specifies the backend server group name. Constraints: N/A Range: N/A Default value: N/A |
project_id |
No |
String |
Definition: Specifies the project ID. For details about how to obtain a project ID, see Obtaining a Project ID. Constraints: N/A Range: The value can contain a maximum of 32 characters, including digits and lowercase letters. Default value: N/A
NOTE:
This parameter is invalid. The project ID in the URL is used.
|
protocol |
Yes |
String |
Definition: Specifies the protocol used by the backend server group to receive requests. Constraints:
Range: The value can be TCP, UDP, QUIC, or TLS. Default value: N/A |
session_persistence |
No |
Definition: Specifies the sticky session. Constraints: Slow start and sticky session cannot be enabled at the same time. If both are enabled, sticky session will be invalid. |
|
vpc_id |
No |
String |
Definition: Specifies the ID of the VPC where the backend server group works. Constraints:
Range: N/A Default value: N/A |
type |
Yes |
String |
Definition: Specifies the type of the backend server group. Constraints: N/A Range:
Default value: N/A |
ip_version |
No |
String |
Definition: Specifies the IP address version supported by the backend server group. Constraints: N/A Range:
Default value: N/A |
members |
Yes |
Array of CreateMasterSlaveMemberOption objects |
Definition: Specifies the backend server of the active/standby server group. Constraints: Only two backend servers can be added, one serving as the active server and the other as the standby server. |
healthmonitor |
Yes |
Definition: Specifies the health check for active/standby backend server group. Health check is enabled by default and cannot be disabled. Constraints: N/A |
|
any_port_enable |
No |
Boolean |
Definition: 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. Constraints: This option is available only for TCP, UDP, and QUIC backend server groups. Range: false (disable this option) or true (enable this option). Constraints: N/A |
connection_drain |
No |
ConnectionDrain object |
Definition: Specifies the configurations of deregistration delay. This parameter takes effect when:
Constraints: This parameter is only available for TCP, UDP, and QUIC backend server groups and TCP and UDP listeners. |
quic_cid_hash_strategy |
No |
QuicCidHashStrategy object |
Definition: Specifies multi-path forwarding configuration based on destination connection IDs. Constraints: N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
cookie_name |
No |
String |
Definition: Specifies the cookie name. Constraints:
Range: The value can contain a maximum of 1,024 characters. Default value: N/A |
type |
Yes |
String |
Definition: Specifies the sticky session type. Constraints:
Range: SOURCE_IP, HTTP_COOKIE, or APP_COOKIE. Default value: N/A |
persistence_timeout |
No |
Integer |
Definition: Specifies the stickiness duration, in minutes. Constraints: This parameter will not take effect when type is set to APP_COOKIE. Range:
Default value: N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
address |
Yes |
String |
Definition: Specifies the IP address bound to the backend server. Constraints:
Range: N/A Default value: N/A |
admin_state_up |
No |
Boolean |
Definition: Specifies the administrative status of the backend server. Constraints: Although this parameter can be used in the APIs for creating and updating backend servers, its actual value depends on whether ECSs exist. Range: If ECSs exist, the value is true. Otherwise, the value is false. Default value: N/A |
name |
No |
String |
Definition: Specifies the backend server name. Constraints: N/A Range: N/A Default value: N/A |
protocol_port |
No |
Integer |
Definition: Specifies the port used by the backend server to receive requests. Constraints: N/A Range: N/A Default value: N/A
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 |
Definition: Specifies the ID of the IPv4 or IPv6 subnet where the backend server resides. Constraints:
Range: N/A Default value: N/A |
role |
Yes |
String |
Definition: Specifies the type of the backend server. Constraints: N/A Range:
Default value: N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
delay |
Yes |
Integer |
Definition: Specifies the interval between health checks, in seconds. Constraints: N/A Range: 1 to 50 Default value: N/A |
domain_name |
No |
String |
Definition: Specifies the domain name that HTTP requests are sent to during the health check. Constraints: This parameter is available only when type is set to HTTP or HTTPS. Range: The value can contain only digits, letters, hyphens (-), and periods (.) and must start with a digit or letter. Default value: null, indicating that the virtual IP address of the load balancer is used as the destination address of HTTP requests |
expected_codes |
No |
String |
Definition: Specifies the expected HTTP status code. Constraints: This parameter will take effect only when type is set to HTTP, HTTPS or GRPC. Range:
Default value: If type is set to GRPC, the default value is 0. If type is set to other values, the default value is 200. |
http_method |
No |
String |
Definition: Specifies the HTTP method. Constraints: This parameter is available when type is set to HTTP or HTTPS. Range: GET, HEAD, or POST Default value: GET |
max_retries |
Yes |
Integer |
Definition: Specifies the number of consecutive health checks when the health check result of a backend server changes from OFFLINE to ONLINE. Constraints: N/A Range: 1 to 10 Default value: N/A |
max_retries_down |
No |
Integer |
Definition: Specifies the number of consecutive health checks when the health check result of a backend server changes from ONLINE to OFFLINE. Constraints: N/A Range: 1 to 10 Default value: N/A |
monitor_port |
No |
Integer |
Specifies the port used for the health check. Constraints: N/A Range: 1 to 65535 Default value: null, indicating the port of a backend server will be used by default. |
name |
No |
String |
Definition: Specifies the health check name. Constraints: N/A Range: N/A Default value: N/A |
timeout |
Yes |
Integer |
Definition: 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. Constraints: N/A Range: N/A Default value: N/A |
type |
Yes |
String |
Definition: Specifies the health check protocol. Constraints:
Range: The value can be TCP, UDP_CONNECT, HTTP, or HTTPS. Default value: N/A |
url_path |
No |
String |
Definition: Specifies the HTTP request path for the health check. The value must start with a slash (/). Constraints: This parameter is available only when type is set to HTTP or HTTPS. Range: The value can contain letters, digits, hyphens (-), slashes (/), periods (.), percentage signs (%), question marks (?), pound signs (#), ampersand signs (&), and the extended character set: _;~!()*[]@$^:',+. Default value: / |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
enable |
No |
Boolean |
Definition: Specifies whether to enable connection_drain. Constraints: N/A Range: The value can be true (enable this option) or false (disable this option). Default value: N/A |
timeout |
No |
Integer |
Definition: Specifies the deregistration delay timeout, in seconds. Constraints: N/A Range: 10 to 4000, in seconds. Constraints: N/A |
Parameter |
Mandatory |
Type |
Description |
---|---|---|---|
len |
Yes |
Integer |
Definition: Specifies the length of the hash factor in the connection ID. Constraints: This parameter is valid only when the load balancing algorithm is QUIC_CID. Range: 1 to 20 Default value: 3 |
offset |
Yes |
Integer |
Definition: Specifies the start position in the connection ID as the hash factor. Constraints: This parameter is valid only when the load balancing algorithm is QUIC_CID. Range: 0 to 19 Default value: 1 |
Response Parameters
Status code: 201
Parameter |
Type |
Description |
---|---|---|
request_id |
String |
Definition: Specifies the request ID. Range: The value is automatically generated, and can contain characters including digits, lowercase letters, and hyphens (-). |
pool |
MasterSlavePool object |
Definition: Specifies the backend server group. |
Parameter |
Type |
Description |
---|---|---|
description |
String |
Definition: Specifies the supplementary information about the backend server group. Range: N/A |
id |
String |
Definition: Specifies the ID of the backend server group. Range: N/A |
lb_algorithm |
String |
Definition: Specifies the load balancing algorithm used by the load balancer to route requests to backend servers in the associated backend server group. Range:
|
listeners |
Array of ListenerRef objects |
Definition: Specifies the IDs of the listeners with which the backend server group is associated. |
loadbalancers |
Array of LoadBalancerRef objects |
Definition: Specifies the IDs of the load balancers with which the active/standby backend server group is associated. |
members |
Array of MasterSlaveMember objects |
Definition: Specifies the backend servers in the backend server group. |
name |
String |
Definition: Specifies the backend server group name. Range: N/A |
project_id |
String |
Definition: Specifies the ID of the project where the backend server group is used. Range: N/A |
protocol |
String |
Definition: Specifies the protocol used by the backend server group to receive requests. Range: The value can be TCP, UDP, QUIC, or TLS. |
session_persistence |
SessionPersistence object |
Definition: Specifies the sticky session. |
ip_version |
String |
Definition: Specifies the IP address version supported by the backend server group. Range:
|
created_at |
String |
Definition: Specifies the creation time. The value must be a UTC time in the format of yyyy-MM-dd'T'HH:mm:ss'Z'. Range: N/A Note: This parameter 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 |
Definition: Specifies the update time. The value must be a UTC time in the format of yyyy-MM-dd'T'HH:mm:ss'Z'. Range: N/A Note: This parameter 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 |
Definition: Specifies the ID of the VPC where the backend server group works. Range: N/A |
type |
String |
Definition: Specifies the backend server group type. Range:
|
enterprise_project_id |
String |
Definition: Specifies the ID of the enterprise project. Range:
|
healthmonitor |
MasterSlaveHealthMonitor object |
Definition: Specifies the health check configured for the active/standby backend server group. |
any_port_enable |
Boolean |
Definition: 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. Range: false (disable this option) or true (enable this option). |
connection_drain |
ConnectionDrain object |
Definition: Specifies the configurations of deregistration delay. This parameter takes effect when:
Range: N/A |
quic_cid_hash_strategy |
QuicCidHashStrategy object |
Definition: Specifies multi-path distribution configuration based on destination connection IDs. |
Parameter |
Type |
Description |
---|---|---|
id |
String |
Definition: Specifies the listener ID. Range: N/A |
Parameter |
Type |
Description |
---|---|---|
id |
String |
Definition: Specifies the load balancer ID. Range: N/A |
Parameter |
Type |
Description |
---|---|---|
id |
String |
Specifies the backend server ID. Range: N/A |
name |
String |
Definition: Specifies the backend server name. Range: N/A |
admin_state_up |
Boolean |
Definition: Specifies the administrative status of the backend server. 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. Range: true or false |
subnet_cidr_id |
String |
Specifies the ID of the IPv4 or IPv6 subnet where the backend server works. If ip_target_enable is set to true, this parameter can be left blank, indicating that an IP as backend server will be added. 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. Range: N/A |
protocol_port |
Integer |
Definition: 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 |
Definition: Specifies the IP address of the backend server Range: N/A |
ip_version |
String |
Definition: Specifies the IP address version supported by the backend server. The version depends on the value of address returned by the system. Range: v4 or v6 |
device_owner |
String |
Definition: Specifies whether the backend server is associated with an ECS. Range:
This parameter is unsupported. Please do not use it. |
device_id |
String |
Definition: 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. Range: N/A This parameter is unsupported. Please do not use it. |
operating_status |
String |
Definition: Specifies the operating status of the backend server if listener_id under status is not specified. Range:
|
reason |
Definition: Specifies why the health check fails. |
|
member_type |
String |
Definition: Specifies the type of the backend server. Range:
|
instance_id |
String |
Definition: 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. Range: N/A |
role |
String |
Definition: Specifies the type of the backend server. Range: N/A |
status |
Array of ListenerMemberInfo objects |
Definition: 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. Range: N/A |
Parameter |
Type |
Description |
---|---|---|
reason_code |
String |
Definition: Specifies the code of the health check failures. Range:
|
expected_response |
String |
Definition: 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. Range:
|
healthcheck_response |
String |
Definition: 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. Range:
|
Parameter |
Type |
Description |
---|---|---|
listener_id |
String |
Definition: Specifies the ID of the listener associated with the backend server. Range: N/A |
operating_status |
String |
Definition: Specifies the operating status of the backend server. Range:
|
Parameter |
Type |
Description |
---|---|---|
cookie_name |
String |
Definition: Specifies the cookie name. Range: The value can contain a maximum of 1,024 characters. |
type |
String |
Definition: Specifies the sticky session type. Range: SOURCE_IP, HTTP_COOKIE, or APP_COOKIE. |
persistence_timeout |
Integer |
Definition: Specifies the stickiness duration, in minutes. This parameter will not take effect when type is set to APP_COOKIE. Range:
|
Parameter |
Type |
Description |
---|---|---|
admin_state_up |
Boolean |
Definition: Specifies the administrative status of the health check. Range:
|
delay |
Integer |
Definition: Specifies the interval between health checks, in seconds. Range: 1 to 50 |
domain_name |
String |
Definition: Specifies the domain name that HTTP requests are sent to during the health check. Range: The value can contain only digits, letters, hyphens (-), and periods (.) and must start with a digit or letter. |
expected_codes |
String |
Definition: Specifies the expected HTTP status code. Range:
|
http_method |
String |
Definition: Specifies the HTTP method. Range: GET, HEAD, or POST |
id |
String |
Specifies the health check ID. Default value: N/A |
max_retries |
Integer |
Definition: Specifies the number of consecutive health checks when the health check result of a backend server changes from OFFLINE to ONLINE. Range: 1 to 10 |
max_retries_down |
Integer |
Definition: Specifies the number of consecutive health checks when the health check result of a backend server changes from ONLINE to OFFLINE. Range: 1 to 10 |
monitor_port |
Integer |
Specifies the port used for the health check. Range: 1 to 65535 |
name |
String |
Definition: Specifies the health check name. Range: N/A |
timeout |
Integer |
Definition: Specifies the maximum time required for waiting for a response from the health check, in seconds. Range: N/A |
type |
String |
Definition: Specifies the health check protocol. Range: The value can be TCP, UDP_CONNECT, HTTP, or HTTPS. |
url_path |
String |
Definition: Specifies the HTTP request path for the health check. The value must start with a slash (/), and the default value is /. Range: The value can contain letters, digits, hyphens (-), slashes (/), periods (.), percentage signs (%), question marks (?), pound signs (#), ampersand signs (&), and the extended character set: _;~!()*[]@$^:',+. |
Parameter |
Type |
Description |
---|---|---|
enable |
Boolean |
Definition: Specifies whether to enable connection_drain. Constraints: N/A Range: The value can be true (enable this option) or false (disable this option). Default value: N/A |
timeout |
Integer |
Definition: Specifies the deregistration delay timeout, in seconds. Constraints: N/A Range: 10 to 4000, in seconds. Constraints: N/A |
Parameter |
Type |
Description |
---|---|---|
len |
Integer |
Definition: Specifies the length of the hash factor in the connection ID. Constraints: This parameter is valid only when the load balancing algorithm is QUIC_CID. Range: 1 to 20 Default value: 3 |
offset |
Integer |
Definition: Specifies the start position in the connection ID as the hash factor. Constraints: This parameter is valid only when the load balancing algorithm is QUIC_CID. 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
Successful request.
{ "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.
Status Codes
Status Code |
Description |
---|---|
201 |
Successful request. |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot