Attaching a NIC to an ECS
Scenarios
If an ECS requires multiple NICs, you can call the API for creating NICs and attach them to the ECS.
A NIC can be attached by setting the nics parameter during ECS creation or after the ECS is created. This section describes how to attach a NIC to a created ECS.
Involved APIs
Attaching a NIC involves the following APIs:
Procedure
- Create a NIC.
- Create a network.
- API
URI format: POST /v1/{project_id}/vpcs
For details, see Creating a VPC.
- Example request
POST https://{Endpoint}/v1/{project_id}/vpcs
Obtain {endpoint} from Regions and Endpoints.
Body:
{ "vpc": { "name": "vpc", "description": "test", "cidr": "192.168.0.0/16" } }
- Example response
{ "vpc": { "id": "99d9d709-8478-4b46-9f3f-2206b1023fd3", "name": "vpc", "description": "test", "cidr": "192.168.0.0/16", "status": "CREATING", "routes": [] } }
- API
- Record the vpc ID in the response.
- Create a subnet.
- API
URI format: POST /v2.0/subnets
For details, see Creating a Subnet.
- Example request
POST https://{endpoint}/v2.0/subnets
Obtain {endpoint} from Regions and Endpoints.
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" } }
- Example response
{ "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" } }
- API
- Record the subnet ID in the response.
- Create a port.
- API
For details, see Creating a Port.
- Example request
POST https://{endpoint}/v2.0/ports
Obtain {endpoint} from Regions and Endpoints.
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" } }
- Example response
{ "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": {} } }
- API
- Record the port ID in the response.
- Create a network.
- Attach the NIC to the ECS.
- API
URI format: POST /v1/{project_id}/cloudservers/{server_id}/nics
For details, see Adding NICs to an ECS in a Batch.
- Example request
POST https://{endpoint}/v1/74610f3a5ad941998e91f076297ecf27/cloudservers/9f4d9281-95e7-4915-a126-1ee597101e2e/nics
Obtain {endpoint} from Regions and Endpoints.
Body:
{ "nics": [ { "subnet_id": "877b5567-e8c6-4a0d-aabf-0f13da225fe5" } ] }
- Example response
{ "job_id": "ff80808288d41e1b018990260955686a" }
- API
- Query task status.
- API
URI format: GET /v1/{project_id}/jobs/{job_id}
For details, see Querying Job Execution Status.
- Example request
GET https://{endpoint}/v1/74610f3a5ad941998e91f076297ecf27/jobs/ff80808288d41e1b018990260955686a
Obtain {endpoint} from Regions and Endpoints.
- Example response
{ "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" } } ] } }
- API
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