Attaching interfaces to virtual routers

PUT /v2.0/routers/{router_id}/add_router_interface

Adds an internal interface to a virtual router. This means a specified subnet is attached to a router as an internal router interface.

You will need to specify the internal network ID and the ID of a subnet or port in the request body:

  • Subnet ID. The gateway IP address for the subnet is used as an IP address of the created router interface. You can also pass a custom IP address from the selected network in the ip_address parameter.
  • Port ID. The IP address associated with the port is used as an IP address of the created router interface.

When you specify an IPv6 subnet, this operation adds the subnet to an existing internal port with same network ID, on the router. If a port with the same network ID does not exist, this operation creates a port on the router for that subnet.

The limitation of one IPv4 subnet per router port remains, though a port can contain any number of IPv6 subnets that belong to the same network ID.

When you use the port-create command to add a port and then call router-interface-add with this port ID, this operation adds the port to the router if the following conditions are met:

  • The port has no more than one IPv4 subnet.
  • The IPv6 subnets, if any, on the port do not have same network ID as the network ID of IPv6 subnets on any other ports.

If you specify both subnet ID and port ID, this operation returns the Bad Request (400) response code.

If the port is already in use, this operation returns the Conflict (409) response code.

This operation returns a port ID that is either:

  • The same ID that is passed in the request body when a port is specified.
  • The ID of a port that this operation creates to attach the subnet to the router.

After you run this operation, the operation sets:

  • The device_id attribute of this port to the router ID
  • The device_owner attribute to network:router_interface

Source: https://docs.openstack.org/api-ref/network/v2/index.html?expanded=add-interface-to-router-detail#add-interface-to-router

Request

Parameters

Name In Type Description
router_id path string The ID of the router.
subnet_id (Optional) body string The ID of the subnet. One of subnet_id or port_id must be specified.
port_id (Optional) body string The ID of the port. One of subnet_id or port_id must be specified.

Example

# curl -ks -X PUT -H 'Content-Type: applicaltion/json' -H 'X-Auth-Token: gAAAAA<...>' -d '
{
    "subnet_id": "112f9b9c-7be2-41c9-8c31-903b263353e7"
}' https://<node_IP_addr>:9696/v2.0/routers/02542148-44cb-470d-a551-58f370c47b83/add_router_interface

Response

Parameters

Name In Type Description
id body string The ID of the resource.
subnet_id body string The ID of the subnet which the router interface belongs to.
subnet_ids body array A list of the ID of the subnet which the router interface belongs to. The list contains only one member.
network_id body string The ID of the attached network.
port_id body string The ID of the port which represents the router interface.
project_id body string The ID of the project.
tenant_id body string The ID of the project.
tags body array The list of tags on the resource.

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.

404 - Not Found

The requested resource could not be found.

409 - Conflict

This operation conflicted with another operation on this resource.

Example

{
  "network_id": "c4e2f31b-fe3b-402b-ac1b-b182693f72f7",
  "tenant_id": "f5d834d636c642c7bfe8af86139c6f26",
  "subnet_id": "112f9b9c-7be2-41c9-8c31-903b263353e7",
  "subnet_ids": [
    "112f9b9c-7be2-41c9-8c31-903b263353e7"
  ],
  "port_id": "fb40083e-e33f-4f75-adff-b76c3cfc5a42",
  "id": "02542148-44cb-470d-a551-58f370c47b83"
}