弹性云服务器挂载网卡
场景描述
当弹性云服务器需要多个网卡时,可以调用接口创建网卡,然后挂载至弹性云服务器。
您可以在创建云服务器时,通过设置“nics”参数值挂载网卡,也可以在创建云服务器成功后挂载网卡。本节主要介绍云服务器创建成功后挂载网卡的场景。
操作步骤
- 创建网卡。
- 创建网络。
- 接口相关信息
URI格式:POST /v1/{project_id}/vpcs
详情请参见创建网络。
- 请求示例
POST https://{Endpoint}/v1/{project_id}/vpcs
{endpoint}信息请从地区和终端节点获取。
Body:
{ "vpc": { "name": "vpc", "description": "test", "cidr": "192.168.0.0/16" } }
- 响应示例
{ "vpc": { "id": "99d9d709-8478-4b46-9f3f-2206b1023fd3", "name": "vpc", "description": "test", "cidr": "192.168.0.0/16", "status": "CREATING", "routes": [] } }
- 接口相关信息
- 记录响应中“vpc”的ID。
- 创建子网。
- 接口相关信息
详情请参见创建子网。
- 请求示例
POST https://{endpoint}/v2.0/subnets
{endpoint}信息请从地区和终端节点获取。
Body:
{ "subnet": { "name": "testsubnet", "enable_dhcp": true, "network_id": "c4a3019d-1ac0-4cfb-a838-2342eb992e6b", "tenant_id": "74610f3a5ad941998e91f076297ecf27", "dns_nameservers": [ "8.8.8.8", "8.8.8.7" ], "allocation_pools": [ { "start": "10.0.10.2", "end": "10.0.10.254" } ], "host_routes": [], "ip_version": 4, "gateway_ip": "10.0.10.1", "cidr": "10.0.10.0/24" } }
- 响应示例
{ "subnet": { "name": "testsubnet", "cidr": "10.0.10.0/24", "id": "877b5567-e8c6-4a0d-aabf-0f13da225fe5", "enable_dhcp": true, "network_id": "c4a3019d-1ac0-4cfb-a838-2342eb992e6b", "tenant_id": "74610f3a5ad941998e91f076297ecf27", "dns_nameservers": [ "8.8.8.8", "8.8.8.7" ], "allocation_pools": [ { "start": "10.0.10.2", "end": "10.0.10.254" } ], "host_routes": [], "ip_version": 4, "gateway_ip": "10.0.10.1" } }
- 接口相关信息
- 记录响应中“subnet”的ID。
- 创建端口。
- 接口相关信息
详情请参见创建端口。
- 请求示例
POST https://{endpoint}/v2.0/ports
{endpoint}信息请从地区和终端节点获取。
Body:
{ "port": { "admin_state_up": true, "fixed_ips": [ { "subnet_id": "877b5567-e8c6-4a0d-aabf-0f13da225fe5" } ], "name": "test", "network_id": "c4a3019d-1ac0-4cfb-a838-2342eb992e6b", "tenant_id": "74610f3a5ad941998e91f076297ecf27" } }
- 响应示例
{ "port": { "id": "7bf1c36f-e7f8-478a-be3d-674b486abbc4", "name": "test", "status": "DOWN", "admin_state_up": true, "fixed_ips": [ { "subnet_id": "877b5567-e8c6-4a0d-aabf-0f13da225fe5", "ip_address": "10.0.10.233" } ], "mac_address": "fa:16:3e:db:91:f6", "network_id": "c4a3019d-1ac0-4cfb-a838-2342eb992e6b", "tenant_id": "74610f3a5ad941998e91f076297ecf27", "device_id": "", "device_owner": "", "security_groups": [ "93031677-2895-4b83-855a-637e309aa9e6" ], "extra_dhcp_opts": [], "allowed_address_pairs": [], "binding:vnic_type": "normal", "binding:vif_details": {}, "binding:profile": {} } }
- 接口相关信息
- 记录响应中“port”的ID。
- 创建网络。
- 挂载网卡。
- 接口相关信息
URI格式:POST /v2.1/{tenant_id}/servers/{server_id}/os-interface
详情请参见“添加云服务器网卡”。
- 请求示例
POST https://{endpoint}/v2.1/74610f3a5ad941998e91f076297ecf27/servers/9f4d9281-95e7-4915-a126-1ee597101e2e/os-interface
{endpoint}信息请从地区和终端节点获取。
Body:
{ "interfaceAttachment": { "port_id": "7bf1c36f-e7f8-478a-be3d-674b486abbc4" } }
- 响应示例
{ "interfaceAttachment": { "port_state": "ACTIVE", "fixed_ips": [ { "subnet_id": "877b5567-e8c6-4a0d-aabf-0f13da225fe5", "ip_address": "10.0.10.233" } ], "port_id": "7bf1c36f-e7f8-478a-be3d-674b486abbc4", "net_id": "c4a3019d-1ac0-4cfb-a838-2342eb992e6b", "mac_addr": "fa:16:3e:db:91:f6" } }
- 接口相关信息
- 确认挂载结果。
- 接口相关信息
URI格式:GET /v2.1/{tenant_id}/servers/{server_id}/os-interface
详情请参见查询云服务器网卡信息。
- 请求示例
GET https://{endpoint}/v2.1/74610f3a5ad941998e91f076297ecf27/servers/9f4d9281-95e7-4915-a126-1ee597101e2e/os-interface
{endpoint}信息请从地区和终端节点获取。
- 响应示例
{ "interfaceAttachments": [ { "port_state": "ACTIVE", "fixed_ips": [ { "subnet_id": "46712fe4-25bd-4eae-874b-a528abfb76be", "ip_address": "192.168.0.50" } ], "port_id": "dd706739-b696-40be-a9f4-477ce478cb18", "net_id": "17251a8f-a671-4d7c-85d9-af5415962994", "mac_addr": "fa:16:3e:a5:e0:3c" }, { "port_state": "ACTIVE", "fixed_ips": [ { "subnet_id": "877b5567-e8c6-4a0d-aabf-0f13da225fe5", "ip_address": "10.0.10.233" } ], "port_id": "7bf1c36f-e7f8-478a-be3d-674b486abbc4", "net_id": "c4a3019d-1ac0-4cfb-a838-2342eb992e6b", "mac_addr": "fa:16:3e:db:91:f6" } ] }
- 接口相关信息