From 90e2462442edd1afaec527019e75d95d4aa648f9 Mon Sep 17 00:00:00 2001 From: micafer Date: Thu, 12 Dec 2019 14:26:29 +0100 Subject: [PATCH] Remove disconnected IPs: #957 --- IM/connectors/OpenStack.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/IM/connectors/OpenStack.py b/IM/connectors/OpenStack.py index a2b8d685c..b98b678b0 100644 --- a/IM/connectors/OpenStack.py +++ b/IM/connectors/OpenStack.py @@ -456,6 +456,14 @@ def setIPsFromInstance(self, vm, node): - node(:py:class:`libcloud.compute.base.Node`): object to connect to EC2 instance. """ + # First remove old + system = vm.info.systems[0] + cont = 0 + while system.getValue('net_interface.%d.connection' % cont): + if system.getValue('net_interface.%d.ip' % cont): + system.delValue('net_interface.%d.ip' % cont) + cont += 1 + if 'addresses' in node.extra: public_ips = [] ip_net_map = {} @@ -481,7 +489,6 @@ def setIPsFromInstance(self, vm, node): map_nets = self.map_radl_ost_networks(vm, ip_net_map) - system = vm.info.systems[0] i = 0 ips_assigned = [] while system.getValue("net_interface." + str(i) + ".connection"): @@ -1622,6 +1629,19 @@ def alter_public_ips(self, vm, radl, auth_data): nets_id = [net.id for net in vm.requested_radl.networks if net.isPublic()] system = vm.requested_radl.systems[0] + i = 0 + while system.getValue('net_interface.%d.connection' % i): + f = system.getFeature("net_interface.%d.connection" % i) + if f.value in nets_id: + system.delValue('net_interface.%d.connection' % i) + if system.getValue('net_interface.%d.ip' % i): + system.delValue('net_interface.%d.ip' % i) + i += 1 + + # Also remove them from the info RADL + nets_id = [net.id for net in vm.info.networks if net.isPublic()] + system = vm.info.systems[0] + i = 0 while system.getValue('net_interface.%d.connection' % i): f = system.getFeature("net_interface.%d.connection" % i)