简体   繁体   中英

Filter Floating IPs with Neutron Python API

I'm utilizing the Neutron Python API for OpenStack to attempt to filter for a specific Floating IP using the neutron.list_floatingips() method. In essence, I'm attempting to mimic this behavior:

$ neutron floatingip-list --tenant-id xxx | grep 15.xxx.xx.xx
| 4ec7639a-47ca-40a8-8cd9-7bc5272f666f | 10.0.0.15 | 15.xxx.xx.xx | 64994354-4921-48ce-b819-d34d194c631c |

The issue is when performing the call to the API as such:

>>> neutron.list_floatingips().get('floatingips')

It will return a dictionary object with ALL of the Floating IPs under the tenant, when only a specific IP needs to be returned. I've attempted (in a few different ways) to filter the results, similar to below:

>>> neutron.list_floatingips(filter_value={'floating_ip_address': '15.xxx.xx.xx'}).get('floatingips')

It still returns the same results as when not including an argument. So my question is, what is the argument to be expected in order to filter for this specific value?

I'm aware I could potentially filter through the resulting dictionary values; however, I'm trying to avoid having the API return more results than necessary.

You would need to use list_floatingips(floating_ip_address="ip-address")

>>> n_h.list_floatingips()
{'floatingips': [{u'router_id': None, u'status': u'ACTIVE', u'tenant_id': u'8537ba5eb1d74d42ac22dcf840c4081a', u'floating_network_id': u'd06e2261-e3c7-4753-afaa-de3efe371f1f', u'fixed_ip_address': None, u'floating_ip_address': u'10.1.1.5', u'port_id': None, u'id': u'ca22da1f-cce0-4d73-98d2-21522313b15f'}, {u'router_id': None, u'status': u'ACTIVE', u'tenant_id': u'8537ba5eb1d74d42ac22dcf840c4081a', u'floating_network_id': u'd06e2261-e3c7-4753-afaa-de3efe371f1f', u'fixed_ip_address': None, u'floating_ip_address': u'10.1.1.3', u'port_id': None, u'id': u'6965571a-2cc8-4a81-b083-c29c690eab8d'}]}
>>> n_h.list_floatingips(floating_ip_address='10.1.1.5')
{'floatingips': [{u'router_id': None, u'status': u'ACTIVE', u'tenant_id': u'8537ba5eb1d74d42ac22dcf840c4081a', u'floating_network_id': u'd06e2261-e3c7-4753-afaa-de3efe371f1f', u'fixed_ip_address': None, u'floating_ip_address': u'10.1.1.5', u'port_id': None, u'id': u'ca22da1f-cce0-4d73-98d2-21522313b15f'}]}
>>>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM