创建后端服务器组
功能介绍
创建后端服务器组。
接口约束
指定session-persistence参数时,只有当type是APP_COOKIE时,才可以设置cookie_name。
若指定listener_id参数,则对应的监听器必须未绑定后端服务器组。
调用方法
请参见如何调用API。
URI
POST /v3/{project_id}/elb/pools
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
项目ID。 |
请求参数
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
X-Auth-Token |
是 |
String |
参数解释: IAM鉴权Token。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
pool |
是 |
CreatePoolOption object |
创建pool的请求体。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
admin_state_up |
否 |
Boolean |
后端云服务器组的管理状态,只支持设置为true。 |
description |
否 |
String |
后端云服务器组的描述信息。 最小长度:0 最大长度:255 |
lb_algorithm |
是 |
String |
后端云服务器组的负载均衡算法。 取值:
使用说明:
|
listener_id |
否 |
String |
后端云服务器组关联的监听器的ID。 使用说明:
最小长度:1 最大长度:36 |
loadbalancer_id |
否 |
String |
后端云服务器组关联的负载均衡器ID。 使用说明:
最小长度:1 最大长度:36 |
name |
否 |
String |
后端云服务器组的名称。 最小长度:0 最大长度:255 |
project_id |
否 |
String |
后端云服务器组所属的项目ID。 最小长度:1 最大长度:32 |
protocol |
是 |
String |
后端云服务器组的后端协议。 取值:TCP、UDP、HTTP、HTTPS、GRPC、QUIC和TLS。 使用说明:
最小长度:1 最大长度:255 |
session_persistence |
否 |
会话持久性对象。 |
|
slow_start |
否 |
CreatePoolSlowStartOption object |
慢启动信息。开启慢启动后,将会在设定的时间段(duration)内对新添加到后端服务器组的后端服务器进行预热,转发到该服务器的请求数量线性增加。 当后端服务器组的协议为HTTP/HTTPS时有效,其他协议传入该字段将报错。 |
member_deletion_protection_enable |
否 |
Boolean |
是否开启删除保护。 取值:false不开启,true开启,默认false。 说明:
退场时需要先关闭所有资源的删除保护开关。 |
vpc_id |
否 |
String |
后端云服务器组关联的虚拟私有云的ID。 使用说明:
没有指定vpc_id的约束:
最小长度:0 最大长度:36 |
type |
否 |
String |
后端服务器组的类型。 取值:
使用说明:
最小长度:0 最大长度:36 |
ip_version |
否 |
String |
后端云服务器组支持的IP版本。 取值:
当协议为HTTP时,ip_version为v4。 最小长度:1 最大长度:20 |
protection_status |
否 |
String |
修改保护状态, 取值:
|
protection_reason |
否 |
String |
设置保护的原因 说明:
仅当protection_status为consoleProtection时有效。 最小长度:0 最大长度:255 |
any_port_enable |
否 |
Boolean |
后端是否开启端口透传。开启后,后端服务器端口与前端监听器端口保持一致。关闭后,请求会转发给后端服务器protocol_port字段指定端口。取值:false不开启,true开启。 使用说明:
|
connection_drain |
否 |
ConnectionDrain object |
后端服务器的延迟注销的功能配置(只针对TCP、UDP、QUIC协议类型的后端服务器组和TCP、UDP协议类的监听器) 以下场景会触发:
|
pool_health |
否 |
PoolHealth object |
后端全下线转发配置 |
public_border_group |
否 |
String |
可用区组,如:center |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
cookie_name |
否 |
String |
cookie名称。 共享型LB,支持字母、数字、中划线(-)和下划线(),最大长度64个字符。 独享型LB,支持字母、数字、中划线(-)、下划线()和点号(.),最大长度255个字符。 使用说明:
|
type |
是 |
String |
会话保持类型。 取值范围:SOURCE_IP、HTTP_COOKIE、APP_COOKIE。 使用说明:
|
persistence_timeout |
否 |
Integer |
会话保持的时间。当type为APP_COOKIE时不生效。 适用范围:如果pool的protocol为TCP、UDP则范围为[1,60](分钟),默认值1; 如果pool的protocol为HTTP和HTTPS则范围为[1,1440](分钟),默认值1440。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
enable |
否 |
Boolean |
慢启动的开关,默认值:false; true:开启; false:关闭 缺省值:false |
duration |
否 |
Integer |
慢启动的持续时间,单位:s。默认:30; 取值范围:30~1200 最小值:30 最大值:1200 缺省值:30 |
响应参数
状态码: 201
参数 |
参数类型 |
描述 |
---|---|---|
request_id |
String |
请求ID。 注:自动生成 。 |
pool |
Pool object |
后端服务器组对象。 |
参数 |
参数类型 |
描述 |
---|---|---|
admin_state_up |
Boolean |
后端云服务器组的管理状态。 |
description |
String |
后端云服务器组的描述信息。 |
healthmonitor_id |
String |
后端云服务器组关联的健康检查的ID。 |
id |
String |
后端云服务器组的ID。 |
lb_algorithm |
String |
后端云服务器组的负载均衡算法。 取值:
使用说明:
|
listeners |
Array of ListenerRef objects |
后端云服务器组关联的监听器ID列表。 |
loadbalancers |
Array of LoadBalancerRef objects |
后端云服务器组关联的负载均衡器ID列表。 |
members |
Array of MemberRef objects |
后端云服务器组中的后端云服务器ID列表。 |
name |
String |
后端云服务器组的名称。 |
project_id |
String |
后端云服务器组所在的项目ID。 |
protocol |
String |
后端云服务器组的后端协议。 取值:TCP、UDP、HTTP、HTTPS、QUIC、GRPC和TLS。 使用说明:
|
session_persistence |
SessionPersistence object |
会话持久性对象。 |
ip_version |
String |
后端云服务器组支持的IP版本。 取值:
当协议为HTTP时,ip_version为v4。 |
slow_start |
SlowStart object |
慢启动信息。开启慢启动后,将会在设定的时间段(duration)内对新添加到后端服务器组的后端服务器进行预热,转发到该服务器的请求数量线性增加。 当后端服务器组的协议为HTTP/HTTPS时有效,其他协议传入该字段将报错。 |
member_deletion_protection_enable |
Boolean |
是否开启误删保护。 取值:false不开启,true开启。 说明:
退场时需要先关闭所有资源的删除保护开关。 |
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 |
后端服务器组的类型。 取值:
|
protection_status |
String |
修改保护状态, 取值:
|
protection_reason |
String |
设置保护的原因 说明:
仅当protection_status为consoleProtection时有效。 最小长度:0 最大长度:255 |
any_port_enable |
Boolean |
后端是否开启端口透传。开启后,后端服务器端口与前端监听器端口保持一致。关闭后,请求会转发给后端服务器protocol_port字段指定端口。取值:false不开启,true开启。 使用说明:
|
connection_drain |
ConnectionDrain object |
后端服务器的延迟注销的功能配置(只针对TCP、UDP、QUIC协议类型的后端服务器组和TCP、UDP协议类的监听器) 以下场景会触发:
|
enterprise_project_id |
String |
IP地址组所在的企业项目ID。 |
pool_health |
PoolHealth object |
后端全下线转发配置 |
public_border_group |
String |
可用区组,如:center |
参数 |
参数类型 |
描述 |
---|---|---|
cookie_name |
String |
cookie名称。 共享型LB,支持字母、数字、中划线(-)和下划线(),最大长度64个字符。 独享型LB,支持字母、数字、中划线(-)、下划线()和点号(.),最大长度255个字符。 使用说明:
|
type |
String |
会话保持类型。 取值范围:SOURCE_IP、HTTP_COOKIE、APP_COOKIE。 使用说明:
|
persistence_timeout |
Integer |
会话保持的时间。当type为APP_COOKIE时不生效。 适用范围:如果pool的protocol为TCP、UDP和QUIC则范围为[1,60](分钟),默认值1; 如果pool的protocol为HTTP和HTTPS则范围为[1,1440](分钟),默认值1440。 |
参数 |
参数类型 |
描述 |
---|---|---|
enable |
Boolean |
慢启动的开关,默认值:false; true:开启; false:关闭 缺省值:false |
duration |
Integer |
慢启动的持续时间。取值:30~1200s,默认30s; 最小值:30 最大值:1200 缺省值:30 |
请求示例
创建一个后端服务器组,并指定协议为TCP协议
POST https://{ELB_Endpoint}/v3/99a3fff0d03c428eac3678da6a7d0f24/elb/pools { "pool" : { "name" : "My pool", "lb_algorithm" : "LEAST_CONNECTIONS", "listener_id" : "0b11747a-b139-492f-9692-2df0b1c87193", "protocol" : "TCP", "member_deletion_protection_enable" : false } }
创建一个后端服务器组,并指定协议为HTTP协议
POST https://{ELB_Endpoint}/v3/99a3fff0d03c428eac3678da6a7d0f24/elb/pools { "pool" : { "name" : "My pool", "lb_algorithm" : "LEAST_CONNECTIONS", "listener_id" : "0b11747a-b139-492f-9692-2df0b1c87193", "protocol" : "HTTP", "slow_start" : { "enable" : true, "duration" : 50 }, "member_deletion_protection_enable" : false } }
响应示例
状态码: 201
POST操作正常返回。
{ "pool" : { "type" : "", "vpc_id" : "", "lb_algorithm" : "LEAST_CONNECTIONS", "protocol" : "TCP", "description" : "", "admin_state_up" : true, "member_deletion_protection_enable" : false, "loadbalancers" : [ { "id" : "098b2f68-af1c-41a9-8efd-69958722af62" } ], "project_id" : "99a3fff0d03c428eac3678da6a7d0f24", "session_persistence" : null, "healthmonitor_id" : null, "listeners" : [ { "id" : "0b11747a-b139-492f-9692-2df0b1c87193" } ], "members" : [ ], "id" : "36ce7086-a496-4666-9064-5ba0e6840c75", "name" : "My pool", "ip_version" : "v4", "slow_start" : null }, "request_id" : "2d974978-0733-404d-a21a-b29204f4803a" }
SDK代码示例
SDK代码示例如下。
创建一个后端服务器组,并指定协议为TCP协议
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
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.elb.v3.region.ElbRegion; import com.huaweicloud.sdk.elb.v3.*; import com.huaweicloud.sdk.elb.v3.model.*; public class CreatePoolSolution { 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(); CreatePoolRequest request = new CreatePoolRequest(); CreatePoolRequestBody body = new CreatePoolRequestBody(); CreatePoolOption poolbody = new CreatePoolOption(); poolbody.withLbAlgorithm("LEAST_CONNECTIONS") .withListenerId("0b11747a-b139-492f-9692-2df0b1c87193") .withName("My pool") .withProtocol("TCP") .withMemberDeletionProtectionEnable(false); body.withPool(poolbody); request.withBody(body); try { CreatePoolResponse response = client.createPool(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()); } } }
创建一个后端服务器组,并指定协议为HTTP协议
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
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.elb.v3.region.ElbRegion; import com.huaweicloud.sdk.elb.v3.*; import com.huaweicloud.sdk.elb.v3.model.*; public class CreatePoolSolution { 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(); CreatePoolRequest request = new CreatePoolRequest(); CreatePoolRequestBody body = new CreatePoolRequestBody(); CreatePoolSlowStartOption slowStartPool = new CreatePoolSlowStartOption(); slowStartPool.withEnable(true) .withDuration(50); CreatePoolOption poolbody = new CreatePoolOption(); poolbody.withLbAlgorithm("LEAST_CONNECTIONS") .withListenerId("0b11747a-b139-492f-9692-2df0b1c87193") .withName("My pool") .withProtocol("HTTP") .withSlowStart(slowStartPool) .withMemberDeletionProtectionEnable(false); body.withPool(poolbody); request.withBody(body); try { CreatePoolResponse response = client.createPool(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()); } } }
创建一个后端服务器组,并指定协议为TCP协议
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
# 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"] credentials = BasicCredentials(ak, sk) client = ElbClient.new_builder() \ .with_credentials(credentials) \ .with_region(ElbRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreatePoolRequest() poolbody = CreatePoolOption( lb_algorithm="LEAST_CONNECTIONS", listener_id="0b11747a-b139-492f-9692-2df0b1c87193", name="My pool", protocol="TCP", member_deletion_protection_enable=False ) request.body = CreatePoolRequestBody( pool=poolbody ) response = client.create_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)
创建一个后端服务器组,并指定协议为HTTP协议
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
# 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"] credentials = BasicCredentials(ak, sk) client = ElbClient.new_builder() \ .with_credentials(credentials) \ .with_region(ElbRegion.value_of("<YOUR REGION>")) \ .build() try: request = CreatePoolRequest() slowStartPool = CreatePoolSlowStartOption( enable=True, duration=50 ) poolbody = CreatePoolOption( lb_algorithm="LEAST_CONNECTIONS", listener_id="0b11747a-b139-492f-9692-2df0b1c87193", name="My pool", protocol="HTTP", slow_start=slowStartPool, member_deletion_protection_enable=False ) request.body = CreatePoolRequestBody( pool=poolbody ) response = client.create_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)
创建一个后端服务器组,并指定协议为TCP协议
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
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.CreatePoolRequest{} listenerIdPool:= "0b11747a-b139-492f-9692-2df0b1c87193" namePool:= "My pool" memberDeletionProtectionEnablePool:= false poolbody := &model.CreatePoolOption{ LbAlgorithm: "LEAST_CONNECTIONS", ListenerId: &listenerIdPool, Name: &namePool, Protocol: "TCP", MemberDeletionProtectionEnable: &memberDeletionProtectionEnablePool, } request.Body = &model.CreatePoolRequestBody{ Pool: poolbody, } response, err := client.CreatePool(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
创建一个后端服务器组,并指定协议为HTTP协议
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
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.CreatePoolRequest{} enableSlowStart:= true durationSlowStart:= int32(50) slowStartPool := &model.CreatePoolSlowStartOption{ Enable: &enableSlowStart, Duration: &durationSlowStart, } listenerIdPool:= "0b11747a-b139-492f-9692-2df0b1c87193" namePool:= "My pool" memberDeletionProtectionEnablePool:= false poolbody := &model.CreatePoolOption{ LbAlgorithm: "LEAST_CONNECTIONS", ListenerId: &listenerIdPool, Name: &namePool, Protocol: "HTTP", SlowStart: slowStartPool, MemberDeletionProtectionEnable: &memberDeletionProtectionEnablePool, } request.Body = &model.CreatePoolRequestBody{ Pool: poolbody, } response, err := client.CreatePool(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } }
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
201 |
POST操作正常返回。 |
错误码
请参见错误码。