diff options
author | Lorin Hochstein <lorinh@gmail.com> | 2015-09-21 22:06:53 -0700 |
---|---|---|
committer | Lorin Hochstein <lorinh@gmail.com> | 2015-09-21 22:06:53 -0700 |
commit | c025034b942277852592d3d1c0b97ddbb8f172eb (patch) | |
tree | eff6cff3ca1520bc29a87a8f742820588562df24 | |
parent | 54b360a6eccfe955537c6d614b599a7c6f1a91c2 (diff) | |
parent | b1e60b3236190140c5b77eac0d179bdfec4782ee (diff) | |
download | openstack-ansible-modules-c025034b942277852592d3d1c0b97ddbb8f172eb.tar.gz |
Merge pull request #52 from pgraziano/bugfix/wrong-tenant
bugfix: was using the first available FIP regardless of tenant
-rw-r--r-- | neutron_floating_ip | 8 |
1 files changed, 7 insertions, 1 deletions
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) |