From 5446a54a65905936fab8869eea2384904eb32f06 Mon Sep 17 00:00:00 2001 From: Jake Yip Date: Mon, 10 Dec 2018 20:08:06 +1100 Subject: [PATCH] Ignore floating ips not attached to instances If floating ip is on a port attached to devices other than a nova compute instance, (e.g. it is attached to a loadbalancer) ignore it. Change-Id: Icda92f0f4b5246aebb082cf48bef751d9e6df2ba --- ec2api/api/address.py | 2 +- ec2api/tests/unit/fakes.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ec2api/api/address.py b/ec2api/api/address.py index a1b2bfa9..66c92364 100644 --- a/ec2api/api/address.py +++ b/ec2api/api/address.py @@ -201,7 +201,7 @@ def _get_os_instance_id(context, os_floating_ip, os_ports=[]): if port_id: port = next((port for port in os_ports if port['id'] == port_id), None) - if port: + if port and port.get('device_owner').startswith('compute:'): os_instance_id = port.get('device_id') return os_instance_id diff --git a/ec2api/tests/unit/fakes.py b/ec2api/tests/unit/fakes.py index 6cf786e6..cf70c590 100644 --- a/ec2api/tests/unit/fakes.py +++ b/ec2api/tests/unit/fakes.py @@ -669,7 +669,7 @@ OS_PORT_1 = {'id': ID_OS_PORT_1, 'fixed_ips': [{'ip_address': IP_NETWORK_INTERFACE_1, 'subnet_id': ID_OS_SUBNET_1}], 'device_id': None, - 'device_owner': '', + 'device_owner': "compute:{}".format(NAME_AVAILABILITY_ZONE), 'security_groups': [ID_OS_SECURITY_GROUP_1]} OS_PORT_2 = {'id': ID_OS_PORT_2, 'network_id': ID_OS_SUBNET_2, @@ -683,7 +683,7 @@ OS_PORT_2 = {'id': ID_OS_PORT_2, {'ip_address': IP_NETWORK_INTERFACE_2_EXT_2, 'subnet_id': ID_OS_SUBNET_2}], 'device_id': ID_OS_INSTANCE_1, - 'device_owner': '', + 'device_owner': "compute:{}".format(NAME_AVAILABILITY_ZONE), 'security_groups': [ID_OS_SECURITY_GROUP_1], 'tenant_id': ID_OS_PROJECT}