弹性云服务器挂载网卡
场景描述
当弹性云服务器需要多个网卡时,可以调用接口创建网卡,然后挂载至弹性云服务器。
您可以在创建云服务器时,通过设置“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 /v1/{project_id}/cloudservers/{server_id}/nics
详情请参见“批量添加云服务器网卡”。
- 请求示例
POST https://{endpoint}/v1/74610f3a5ad941998e91f076297ecf27/cloudservers/9f4d9281-95e7-4915-a126-1ee597101e2e/nics
{endpoint}信息请从地区和终端节点获取。
Body:
{ "nics": [ { "subnet_id": "877b5567-e8c6-4a0d-aabf-0f13da225fe5" } ] }
- 响应示例
{ "job_id": "ff80808288d41e1b018990260955686a" }
- 接口相关信息
- 查询任务执行状态。
- 接口相关信息
URI格式:GET /v1/{project_id}/jobs/{job_id}
详情请参见查询任务的执行状态。
- 请求示例
GET https://{endpoint}/v1/74610f3a5ad941998e91f076297ecf27/jobs/ff80808288d41e1b018990260955686a
{endpoint}信息请从地区和终端节点获取。
- 响应示例
{ "job_id": "ff80808288d41e1b018990260955686a", "job_type": "addNicsForServer", "begin_time": "2025-02-14T08:43:05.181Z", "end_time": "2025-02-14T08:43:17.075Z", "status": "SUCCESS", "error_code": null, "fail_reason": null, "entities": { "sub_jobs_total": 1, "sub_jobs": [ { "job_id": "ff80808288d41e1b018990260955686a", "job_type": "addNic", "begin_time": "2025-02-14T08:43:06.423Z", "end_time": "2025-02-14T08:43:12.380Z", "status": "SUCCESS", "error_code": null, "fail_reason": null, "entities": { "nic_id": "877b5567-e8c6-4a0d-aabf-0f13da225fe5" } } ] } }
- 接口相关信息