Chuyển tới nội dung chính

Attach network interface vào VM

POST/v2.1/{project_id}/servers/{server_id}/os-interface

Tạo một port và gắn vào VM, hoặc gắn port có sẵn khi bạn truyền port_id. Dùng thao tác này để đưa VM đang chạy vào network thứ hai mà không cần rebuild.

info

Request​

Tham số​

project_idstringbắt buộcpath

UUID của project.

server_idstringbắt buộcpath

UUID của VM.

interfaceAttachmentobjectbắt buộcbody

Object bọc interface attachment.

6 trường
port_idstringbody

ID của port có sẵn cần attach. Loại trừ lẫn nhau với net_id.

net_idstringbody

ID của network để tạo port. Loại trừ lẫn nhau với port_id. Nếu bỏ trống cả hai, service dùng network đã gắn với VM.

fixed_ipsarraybody

Các địa chỉ fixed IP muốn yêu cầu. Nếu yêu cầu một địa chỉ cụ thể mà không có net_id, lệnh gọi trả 400.

port_security_enabledbooleanbody

Bật port security (anti-spoofing và security group) trên port mới.

security_groupsarraybody

Danh sách ID security group cho port mới.

tagstringbody

Tag vai trò device mà guest đọc được qua metadata API hoặc config drive.

Request mẫu — IP tự động​

curl -ks -H 'Content-Type: application/json' -H 'X-OpenStack-Nova-API-Version: 2.67' \
-H 'X-Auth-Token: gAAAAA<...>' -d '{
"interfaceAttachment": {
"net_id": "a1d8d6ae-c89d-4307-8a0c-3cc2ee55d7e3",
"fixed_ips": [{"ip_version": 4}],
"port_security_enabled": true,
"security_groups": ["5e2db579-c3a0-468b-aecd-b7930bf1507e"]
}
}' https://api.vietnix.cloud:8774/v2.1/{project_id}/servers/{server_id}/os-interface

Request mẫu — IP cụ thể​

curl -ks -H 'Content-Type: application/json' -H 'X-OpenStack-Nova-API-Version: 2.67' \
-H 'X-Auth-Token: gAAAAA<...>' -d '{
"interfaceAttachment": {
"net_id": "0bb6b7a7-da8d-432c-b8d5-12139f7924d1",
"fixed_ips": [{"ip_address": "192.168.128.20"}]
}
}' https://api.vietnix.cloud:8774/v2.1/{project_id}/servers/{server_id}/os-interface

Response​

Response mẫu​

Response body
{
"interfaceAttachment": {
"port_state": "ACTIVE",
"fixed_ips": [
{
"subnet_id": "d52aa9f4-6a4b-4268-a71d-1a50f9b60aa9",
"ip_address": "192.168.128.20"
}
],
"port_id": "ff9edb95-611f-4969-b98a-498f77c0326a",
"net_id": "0bb6b7a7-da8d-432c-b8d5-12139f7924d1",
"mac_addr": "fa:16:3e:8d:73:9f"
}
}

Mã trạng thái​

Thành công​

MãMô tả
200 - OKInterface đã được attach.

Lỗi​

MãMô tả
400 - Bad Requestport_id và net_id cùng được đặt, hoặc yêu cầu fixed IP mà không có network.
401 - UnauthorizedUser phải xác thực trước khi gửi request.
403 - ForbiddenPolicy không cho phép user hiện tại thực hiện thao tác này.
404 - Not FoundVM, network hoặc port không tồn tại.
409 - ConflictPort đã được attach, hoặc VM đang ở trạng thái không cho phép attach.
501 - Not ImplementedNetwork interface không được hỗ trợ trong deployment này.
note

Gắn interface thứ hai vào VM đã có default route không thay đổi default route bên trong guest. Cấu hình routing hoặc policy trong guest nếu network mới cần chở traffic ra ngoài.