From 1cc057ca97d4afad171f18fd332e2915cbb15ed9 Mon Sep 17 00:00:00 2001 From: mcameron Date: Tue, 21 Apr 2015 13:11:54 +0100 Subject: [PATCH] Valodate fip is on the correct network --- .../cloud/openstack/quantum_floating_ip.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/cloud/openstack/quantum_floating_ip.py b/lib/ansible/modules/cloud/openstack/quantum_floating_ip.py index 29abc4b0f87..8f532bc0ad0 100644 --- a/lib/ansible/modules/cloud/openstack/quantum_floating_ip.py +++ b/lib/ansible/modules/cloud/openstack/quantum_floating_ip.py @@ -172,7 +172,7 @@ def _get_port_info(neutron, module, instance_id, internal_network_name=None): return None, None return fixed_ip_address, port_id -def _get_floating_ip(module, neutron, fixed_ip_address): +def _get_floating_ip(module, neutron, fixed_ip_address, network_name): kwargs = { 'fixed_ip_address': fixed_ip_address } @@ -182,7 +182,17 @@ def _get_floating_ip(module, neutron, fixed_ip_address): module.fail_json(msg = "error in fetching the floatingips's %s" % e.message) if not ips['floatingips']: return None, None - return ips['floatingips'][0]['id'], ips['floatingips'][0]['floating_ip_address'] + for address in ips['floatingips']: + if _check_ips_network(neutron, address['floating_network_id'], network_name): + return address['id'], address['floating_ip_address'] + return None, None + +def _check_ips_network(neutron, floating_id, network_name): + net_id = neutron.show_floatingip('3d479538-9f9c-417e-a313-0c99b13b050b')['floatingip']['floating_network_id'] + if neutron.show_network(net_id)['network']['name'] == network_name: + return True + else: + return False def _create_floating_ip(neutron, module, port_id, net_id, fixed_ip): kwargs = { @@ -245,7 +255,7 @@ def main(): if not port_id: module.fail_json(msg="Cannot find a port for this instance, maybe fixed ip is not assigned") - floating_id, floating_ip = _get_floating_ip(module, neutron, fixed_ip) + floating_id, floating_ip = _get_floating_ip(module, neutron, fixed_ip, module.params['network_name']) if module.params['state'] == 'present': if floating_ip: