[openstack-dev] [Neutron][Client] How do I list interfaces on a router?
Jay Pipes
jaypipes at gmail.com
Mon Oct 7 16:11:57 UTC 2013
On 10/07/2013 12:00 PM, Jay Pipes wrote:
> Hi all,
>
> I've got code that is checking to see if a particular router has a
> public gateway set up, and if not, it wires up the gateway:
>
> print "Checking %s router setup ... " % zone.upper(),
> try:
> router = qc.list_routers(name="demorouter")['routers']
> router = router[0]
> print "OK"
> except IndexError:
> print "MISSING"
> print "--> Creating missing router ... ",
> router_data = dict(name="demorouter", admin_state_up=True)
> router = qc.create_router(dict(router=router_data))['router']
> print "OK"
>
> print "Checking %s router gateway ... " % zone.upper(),
> if router['external_gateway_info'] is None:
> print "NOT SET"
> print "--> Setting external gateway for router ... ",
> pub_net_id = qc.list_networks(name="public")['networks'][0]['id']
> net_dict = dict(network_id=pub_net_id)
> qc.add_gateway_router(router['id'], net_dict)
> print "OK"
> else:
> print "OK"
>
> The above code works just fine. The next thing I need to check is
> whether the private subnet is wired into the router. I cannot seem to
> determine how to list interfaces for a particular router.
>
> I checked Horizon and it doesn't seem to have any idea how to do this
> either [1]. Is this just something that is missing from the Neutron API?
> If so, how do you suggest I determine if the demo router has been
> connected to the private subnet?
>
> Thanks in advance for any help,
> -jay
>
> https://github.com/openstack/horizon/blob/master/openstack_dashboard/api/neutron.py
> lines 660-708
OK, I figured it out. For the benefit of folks looking for how to do
this, you need to use the neutronclient.list_ports() method passing in
the router ID as the "device_id" kwarg, like so:
router_ports = qc.list_ports(device_id=router['id'])['ports']
if len(router_ports) == 0:
print "NOT SET"
print "--> Adding interface to subnet 192.168.1.0/24 to router ... ",
iface_dict = dict(subnet_id=sn['id'])
qc.add_interface_router(router['id'], iface_dict)
print "OK"
else:
print "OK"
Where "sn" is the subnet dict that you've previously added or gotten.
Best,
-jay
More information about the OpenStack-dev
mailing list