Avoid AttributeError: internal_network on os_floating_ip (#32887)

Fixes #32884

Change-Id: I3be1dc81266b32dd8f545b743365c2bbc02dfdeb
Signed-off-by: Sorin Sbarnea <ssbarnea@redhat.com>
This commit is contained in:
Sorin Sbarnea 2017-11-14 18:42:20 +00:00 committed by ansibot
parent 71fa60bc68
commit 3fedd88a9f

View file

@ -204,8 +204,21 @@ def main():
network_id = cloud.get_network(name_or_id=network)["id"] network_id = cloud.get_network(name_or_id=network)["id"]
else: else:
network_id = None network_id = None
if all([(fixed_address and f_ip.fixed_ip_address == fixed_address) or # check if we have floting ip on given nat_destination network
(nat_destination and f_ip.internal_network == fixed_address), 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]): network, f_ip.network != network_id]):
# Current state definitely conflicts with requirements # Current state definitely conflicts with requirements
module.fail_json(msg="server {server} already has a " module.fail_json(msg="server {server} already has a "