From 3fedd88a9fd38bd734a1a594000e339c4d316fdd Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Tue, 14 Nov 2017 18:42:20 +0000 Subject: [PATCH] Avoid AttributeError: internal_network on os_floating_ip (#32887) Fixes #32884 Change-Id: I3be1dc81266b32dd8f545b743365c2bbc02dfdeb Signed-off-by: Sorin Sbarnea --- .../modules/cloud/openstack/os_floating_ip.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/ansible/modules/cloud/openstack/os_floating_ip.py b/lib/ansible/modules/cloud/openstack/os_floating_ip.py index c035293dcbd..0465b286829 100644 --- a/lib/ansible/modules/cloud/openstack/os_floating_ip.py +++ b/lib/ansible/modules/cloud/openstack/os_floating_ip.py @@ -204,8 +204,21 @@ def main(): network_id = cloud.get_network(name_or_id=network)["id"] else: network_id = None - if all([(fixed_address and f_ip.fixed_ip_address == fixed_address) or - (nat_destination and f_ip.internal_network == fixed_address), + # check if we have floting ip on given nat_destination network + if nat_destination: + nat_floating_addrs = [addr for addr in server.addresses.get( + cloud.get_network(nat_destination)['name'], []) + if addr.addr == public_ip and + addr['OS-EXT-IPS:type'] == 'floating'] + + if len(nat_floating_addrs) == 0: + module.fail_json(msg="server {server} already has a " + "floating-ip on a different " + "nat-destination than '{nat_destination}'" + .format(server=server_name_or_id, + nat_destination=nat_destination)) + + if all([fixed_address, f_ip.fixed_ip_address == fixed_address, network, f_ip.network != network_id]): # Current state definitely conflicts with requirements module.fail_json(msg="server {server} already has a "