From b1e60b3236190140c5b77eac0d179bdfec4782ee Mon Sep 17 00:00:00 2001 From: Pablo Date: Thu, 17 Sep 2015 17:06:23 -0700 Subject: bugfix: was using the first available FIP regardless of tenant --- neutron_floating_ip | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/neutron_floating_ip b/neutron_floating_ip index 544b723..9c27f10 100644 --- a/neutron_floating_ip +++ b/neutron_floating_ip @@ -178,6 +178,11 @@ def _get_floating_ip(module, neutron, fixed_ip_address): return None, None return ips['floatingips'][0]['id'], ips['floatingips'][0]['floating_ip_address'] +def _get_tenant_id(module): + tenants = _get_ksclient(module, {}).tenants.list() + tenant = next((t for t in tenants if t.name == module.params.get('login_tenant_name')), None) + return tenant.id + def _assign_floating_ip(neutron, module, port_id, net_id): kwargs = { 'floating_network_id': net_id @@ -187,7 +192,8 @@ def _assign_floating_ip(neutron, module, port_id, net_id): except Exception as e: module.fail_json(msg = "error in fetching the floatingips's %s" % e.message) - fip = next((fip for fip in ips['floatingips'] if fip['port_id'] is None), None) + tenant_id = _get_tenant_id(module) + fip = next((fip for fip in ips['floatingips'] if fip['port_id'] is None and fip['tenant_id'] == tenant_id), None) if fip is None: _create_floating_ip(neutron, module, port_id, net_id) -- cgit v1.2.1