Attaching network interfaces to virtual machines

POST /servers/{server_id}/os-interface

Create a network interface and attach it to the given virtual machine.

Source: https://docs.openstack.org/api-ref/compute/?expanded=create-interface-detail#create-interface

Request

Parameters

Name In Type Description
server_id path string The UUID of the server.
interfaceAttachmentEx body string Specify the interfaceAttachmentEx action in the request body.
port_id (Optional) body string The ID of the port for which you want to create an interface. The net_id and port_id parameters are mutually exclusive. If you do not specify the port_id parameter, the OpenStack Networking API v2.0 allocates a port and creates an interface for it on the network.
net_id (Optional) body string The ID of the network for which you want to create a port interface. The net_id and port_id parameters are mutually exclusive. If you do not specify the net_id parameter, the OpenStack Networking API v2.0 uses the network information cache that is associated with the instance.
fixed_ips (Optional) body array Fixed IP addresses. If you request a specific fixed IP address without a network’s uuid or net_id, the request returns a Bad Request (400) response code.
ip_address (Optional) body string The IP address.
ip_version (Optional) body integer The IP protocol version. Valid value is 4 or 6. Default is 4.
tag (Optional) body string

A device role tag that can be applied to a network interface when attaching it to the VM. The guest OS of a server that has devices tagged in this manner can access hardware metadata about the tagged devices from the metadata API and on the config drive, if enabled.

New in version 2.49

Example 1

Create a network interface in the specified network, assign the IP address automatically from the IPv4 subnet, and attach it to a VM with the specified ID.

# 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://<node_IP_addr>:8774/v2.1/b906404c55bb44729da99987536ac5bc/servers/0785ee80-1eca-426b-b8c4-5b499fc7f614/os-interface

Example 2

Create a network interface in the specified network, assign the IP address manually, and attach it to a VM with the specified ID.

# 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"}],
    "port_security_enabled": true,
    "security_groups": ["5e2db579-c3a0-468b-aecd-b7930bf1507e"]
  }
}' https://<node_IP_addr>:8774/v2.1/b906404c55bb44729da99987536ac5bc/servers/0785ee80-1eca-426b-b8c4-5b499fc7f614/os-interface

Response

Parameters

Name In Type Description
interfaceAttachment body object The interface attachment.
port_state body string The port state.
fixed_ips body array Fixed IP addresses with subnet IDs.
subnet_id body string The UUID of the subnet.
ip_address body string The IP address.
port_id body string The port ID.
net_id body string The network ID.
mac_addr body string The MAC address.
tag body string

The device tag applied to the virtual network interface or null.

New in version 2.70

Status codes

Success

Code Reason
200 - OK Request was successful.

Error

Code Reason
400 - Bad Request

Some content in the request was invalid.

401 - Unauthorized

User must authenticate before making a request.

403 - Forbidden

Policy does not allow current user to do this operation.

404 - Not Found

The requested resource could not be found.

409 - Conflict

This operation conflicted with another operation on this resource.

500 - Internal Server Error

Something went wrong inside the service. This should not happen usually. If it does happen, it means the server has experienced some serious problems.

501 - Not Implemented

The server either does not recognize the request method, or it lacks the ability to fulfill the request.

Example

{
  "interfaceAttachment": {
    "port_state": "ACTIVE",
    "fixed_ips": [
      {
        "subnet_id": "d52aa9f4-6a4b-4268-a71d-1a50f9b60aa9", 
        "ip_address": "10.136.18.138"
      }
    ],
    "port_id": "bfc3228d-384e-4864-a583-54157225a4ef",
    "net_id": "a1d8d6ae-c89d-4307-8a0c-3cc2ee55d7e3",
    "mac_addr": "fa:16:3e:3b:0b:c3"
  }
}