From 84c4e791b6ea4e6d488acf29491ef8c901011aa3 Mon Sep 17 00:00:00 2001 From: spisarski Date: Fri, 28 Jul 2017 10:40:49 -0600 Subject: Removed floating IP list from OpenStackVmInstance. There was a list and dict both holding the same floating IP objects which has been problematic especially when trying to initialize the object with a VM instance that already exists. JIRA: SNAPS-149 Change-Id: If4af6dfef04a40b9c8cd7a8add484c9ec03f1ef8 Signed-off-by: spisarski --- snaps/openstack/utils/neutron_utils.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'snaps/openstack/utils') diff --git a/snaps/openstack/utils/neutron_utils.py b/snaps/openstack/utils/neutron_utils.py index 2f8ef7e..19325a8 100644 --- a/snaps/openstack/utils/neutron_utils.py +++ b/snaps/openstack/utils/neutron_utils.py @@ -448,17 +448,31 @@ def get_external_networks(neutron): return out -def get_floating_ips(neutron): +def get_floating_ips(neutron, ports=None): """ Returns all of the floating IPs + When ports is not None, FIPs returned must be associated with one of the + ports in the list and a tuple 2 where the first element being the port's + name and the second being the FloatingIp SNAPS-OO domain object. + When ports is None, all known FloatingIp SNAPS-OO domain objects will be + returned in a list :param neutron: the Neutron client - :return: a list of SNAPS FloatingIp objects + :param ports: a list of SNAPS-OO Port objects to join + :return: a list of tuple 2 (port_name, SNAPS FloatingIp) objects when ports + is not None else a list of Port objects """ out = list() fips = neutron.list_floatingips() for fip in fips['floatingips']: - out.append(FloatingIp(inst_id=fip['id'], - ip=fip['floating_ip_address'])) + if ports: + for port_name, port in ports: + if fip['port_id'] == port.id: + out.append((port.name, FloatingIp( + inst_id=fip['id'], ip=fip['floating_ip_address']))) + break + else: + out.append(FloatingIp(inst_id=fip['id'], + ip=fip['floating_ip_address'])) return out -- cgit 1.2.3-korg