更新时间:2023-12-18 GMT+08:00
添加后端云服务器
接口格式
方法 |
URI |
说明 |
---|---|---|
POST |
/v2.0/lbaas/pools/{pool_id}/members |
添加属于某个后端云服务器组的后端云服务器。 |
接口约束
- 属于一个pool的两个member不能有相同的address和port。
- 创建member时指定的子网必须和VIP所在子网处在同一个VPC下。
- admin_state_up参数必须是true。
具体步骤
- 设置请求消息头。Postman中设置好头部信息,将获取到的Token放入头部,如下图:
图1 设置请求消息头-添加后端云服务器组
- 在Body标签中填写请求消息体。
图2 填写请求消息体-添加后端云服务器组
- 查询虚拟机的subnet_id和主网卡IP。
填写URL。
GET https://{VPCEndpoint}/v2.0/ports?device_id={ecs_id}
在响应体中获取primary_interface为true的port的subnet_id和ip_address。响应体示例如下:
{ "ports": [ { "id": "4813697b-62ba-4f4b-90e5-13bbbdec7198", "name": "", "status": "ACTIVE", "admin_state_up": true, "fixed_ips": [ { "subnet_id": "d97b6b89-6aa2-4636-a86b-132eb4eb566e", "ip_address": "10.1.1.89" } ], "mac_address": "fa:16:3e:cb:8d:0a", "network_id": "1b76b9c2-9b7e-4ced-81bd-d13f7389d7c9", "tenant_id": "04dd36f978800fe22f9bc00bea090736", "project_id": "04dd36f978800fe22f9bc00bea090736", "device_id": "f738c464-b5c2-45df-86c0-7f436620cd54", "device_owner": "compute:cn-north-4a", "security_groups": [ "7a233393-5be2-4dff-8360-1558dd950f6e" ], "extra_dhcp_opts": [], "allowed_address_pairs": [], "binding:vnic_type": "normal", "binding:vif_details": {}, "binding:profile": {}, "port_security_enabled": true, "created_at": "2019-11-19T09:28:38", "updated_at": "2019-11-19T09:28:39" }, { "id": "94971c39-46f0-443a-85e8-31cb7497c78e", "name": "", "status": "ACTIVE", "admin_state_up": true, "fixed_ips": [ { "subnet_id": "8d944cda-1f29-4035-9681-ad8c5117fbc5", "ip_address": "192.168.0.11" } ], "mac_address": "fa:16:3e:5c:d2:57", "network_id": "1b76b9c2-9b7e-4ced-81bd-d13f7389d7c9", "tenant_id": "04dd36f978800fe22f9bc00bea090736", "project_id": "04dd36f978800fe22f9bc00bea090736", "device_id": "f738c464-b5c2-45df-86c0-7f436620cd54", "device_owner": "compute:cn-north-4a", "security_groups": [ "a10dfc31-0055-4b84-b36e-1291b918125c", "7a233393-5be2-4dff-8360-1558dd950f6e" ], "extra_dhcp_opts": [], "allowed_address_pairs": [], "binding:vnic_type": "normal", "binding:vif_details": { "primary_interface": true }, "binding:profile": {}, "port_security_enabled": true, "created_at": "2019-11-12T17:17:51", "updated_at": "2019-11-12T17:17:51" } ] }
- 填写URL。
https://{ELBEndpoint}/v2.0/lbaas/pools/{pool_id}/members
- 发送请求。body体中的subnet_id和address为步骤3中获取的值,选择请求方法为POST,点击Send按钮,得到服务端响应。
{ "member": { "name": "member4j", "weight": 1, "admin_state_up": false, "subnet_id": "8d944cda-1f29-4035-9681-ad8c5117fbc5", "tenant_id": "0d0bf0e8fb564cc9abbe526dbdca9248", "address": "192.168.0.11", "protocol_port": 8080, "id": "97f18d73-e97d-434c-8cb7-3274a83dda73", "operating_status": "ONLINE" } }
示例代码
2中消息体内容
{ "member": { "subnet_id": "8d944cda-1f29-4035-9681-ad8c5117fbc5", "protocol_port": "8080", "name": "member4j", "address": "192.168.0.11" } }