Ask Your Question
1

Neutron API: function for listing router interfaces?

asked 2015-05-19 05:04:13 -0500

fhussain gravatar image

Hi,

I am writing a small plugin for OpenStack for which I need to have the information of the interfaces of each router in a given network topology. I first thought I can fetch it from the router object returned by this function:

routers = api.neutron.router_list(self.request,params={})

<Router: {u'status': u'ACTIVE', u'external_gateway_info': {u'network_id': u'0473ea49-473e-4678-a48a-a123d64f3e12', u'enable_snat': True}, u'name': u'router1', u'admin_state_up': True, u'tenant_id': u'1e7fc802925c4f1295018cd85448455b', 'admin_state': 'UP', u'routes': [], u'id': u'28239316-61e8-4c26-a502-866f7fdb1492'}>

But the router object returned has no field for interfaces.

I have also looked into the /horizon/openstack_dashboard/api/neutron.py file. It has functions defined for adding or deleting router interfaces, but I cannot see a function to list router interfaces.

Please suggest where can I look for the function to list router interfaces which I can use in my python code?

Thanks.

edit retag flag offensive close merge delete

Comments

1

Router interfaces are just ports. So you can use list_port(). For router ports, the port device_id is the router id. So list_ports(device_id="the router id") to filter.

darragh-oreilly gravatar imagedarragh-oreilly ( 2015-05-19 12:48:16 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
3

answered 2015-05-19 13:32:59 -0500

hardik italia gravatar image

updated 2015-05-19 13:34:58 -0500

Neutron API "/v2.0/ports" with device_id (router's id) filter will give you router's all the interfaces.

Example:

$ curl -H "X-Auth-Token: f09a6b6acabf409f8cc6607c6e269030" http://10.10.10.2:9696/v2.0/ports?device_id=a040c47f-9188-4eea-a014-a8d44161bd7b | python -mjson.tool

{
    "ports": [
        {
            "admin_state_up": true,
            "allowed_address_pairs": [],
            "binding:host_id": "",
            "binding:profile": {},
            "binding:vif_details": {},
            "binding:vif_type": "distributed",
            "binding:vnic_type": "normal",
            "device_id": "a040c47f-9188-4eea-a014-a8d44161bd7b",
            "device_owner": "network:router_interface_distributed",
            "extra_dhcp_opts": [],
            "fixed_ips": [
                {
                    "ip_address": "fded:ebf0:2346::1",
                    "subnet_id": "507285b9-6a79-40bf-a8e9-4d8069df9ed6"
                }
            ],
            "id": "3d4e4736-e9b6-4994-b4b4-1c3a68e3f06d",
            "mac_address": "fa:16:3e:e6:47:0f",
            "name": "",
            "network_id": "f6c1bd07-c3bf-4870-bf76-f043675219f0",
            "security_groups": [],
            "status": "ACTIVE",
            "tenant_id": "827806e5f31a45f2829cbb1fffdc2017"
        },
        {
            "admin_state_up": true,
            "allowed_address_pairs": [],
            "binding:host_id": "ctl",
            "binding:profile": {},
            "binding:vif_details": {
                "ovs_hybrid_plug": true,
                "port_filter": true
            },
            "binding:vif_type": "ovs",
            "binding:vnic_type": "normal",
            "device_id": "a040c47f-9188-4eea-a014-a8d44161bd7b",
            "device_owner": "network:router_centralized_snat",
            "extra_dhcp_opts": [],
            "fixed_ips": [
                {
                    "ip_address": "192.168.1.3",
                    "subnet_id": "ed4fb27c-ab64-44d7-9e2b-f298007a6249"
                }
            ],
            "id": "95f4751b-a75b-476c-8142-74e6c81c11a4",
            "mac_address": "fa:16:3e:60:be:87",
            "name": "",
            "network_id": "f6c1bd07-c3bf-4870-bf76-f043675219f0",
            "security_groups": [],
            "status": "ACTIVE",
            "tenant_id": ""
        },
        {
            "admin_state_up": true,
            "allowed_address_pairs": [],
            "binding:host_id": "",
            "binding:profile": {},
            "binding:vif_details": {},
            "binding:vif_type": "distributed",
            "binding:vnic_type": "normal",
            "device_id": "a040c47f-9188-4eea-a014-a8d44161bd7b",
            "device_owner": "network:router_interface_distributed",
            "extra_dhcp_opts": [],
            "fixed_ips": [
                {
                    "ip_address": "192.168.1.1",
                    "subnet_id": "ed4fb27c-ab64-44d7-9e2b-f298007a6249"
                }
            ],
            "id": "ae48e5e9-3aef-41ef-bf5b-8f2bd0805dbc",
            "mac_address": "fa:16:3e:a6:c5:7e",
            "name": "",
            "network_id": "f6c1bd07-c3bf-4870-bf76-f043675219f0",
            "security_groups": [],
            "status": "ACTIVE",
            "tenant_id": "827806e5f31a45f2829cbb1fffdc2017"
        },
        {
            "admin_state_up": true,
            "allowed_address_pairs": [],
            "binding:host_id": "ctl",
            "binding:profile": {},
            "binding:vif_details": {
                "ovs_hybrid_plug": true,
                "port_filter": true
            },
            "binding:vif_type": "ovs",
            "binding:vnic_type": "normal",
            "device_id": "a040c47f-9188-4eea-a014-a8d44161bd7b",
            "device_owner": "network:router_gateway",
            "extra_dhcp_opts": [],
            "fixed_ips": [
                {
                    "ip_address": "10.10.20.101",
                    "subnet_id": "4a8c6aac-c3f6-4ba2-8e46-a55cd9a8c99b"
                },
                {
                    "ip_address": "2001:db8::1",
                    "subnet_id": "fa0c1d68-1bee-42fd-8b20-43b8c31106e1"
                }
            ],
            "id": "bf77f6c5-7685-4d37-ad7e-07728b368bdd",
            "mac_address": "fa:16:3e:f1:fd:69",
            "name": "",
            "network_id": "51902849-1fb0-43e6-ad3c-63c9c232ee8e",
            "security_groups": [],
            "status": "DOWN",
            "tenant_id": ""
        },
        {
            "admin_state_up": true,
            "allowed_address_pairs": [],
            "binding:host_id": "ctl",
            "binding:profile": {},
            "binding:vif_details": {
                "ovs_hybrid_plug": true,
                "port_filter": true
            },
            "binding:vif_type": "ovs",
            "binding:vnic_type": "normal",
            "device_id": "a040c47f-9188-4eea-a014-a8d44161bd7b",
            "device_owner": "network:router_centralized_snat",
            "extra_dhcp_opts": [],
            "fixed_ips": [
                {
                    "ip_address": "fded:ebf0:2346:0:f816:3eff:fe19:4203",
                    "subnet_id": "507285b9-6a79-40bf-a8e9-4d8069df9ed6"
                }
            ],
            "id": "f200e71a-9933-4e9e-a4cc-3b49df923962",
            "mac_address": "fa:16:3e:19:42:03",
            "name": "",
            "network_id": "f6c1bd07-c3bf-4870-bf76-f043675219f0",
            "security_groups": [],
            "status": "ACTIVE",
            "tenant_id": ""
        }
    ] }
edit flag offensive delete link more
0

answered 2015-05-19 12:28:44 -0500

GLaupre gravatar image

Maybe it is a wrong direction but you can use namespace? Each router will be in a particular namespace, you can use the id using the api.neutron.router that you use afterwards for the namespace. You can check the compatibility and find it using

ip netns

With that you can take the qrouter id and list all its interfaces using

ip netns exec qrouter-xxxx ip link show

With some regex work and parsing I guess you can do something, no?

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

2 followers

Stats

Asked: 2015-05-19 05:04:13 -0500

Seen: 1,948 times

Last updated: May 19 '15