diff --git a/IM/VirtualMachine.py b/IM/VirtualMachine.py index afd5b9623..3886329ec 100644 --- a/IM/VirtualMachine.py +++ b/IM/VirtualMachine.py @@ -1079,3 +1079,27 @@ def get_ssh_command(self): ssh.host)) return command + + @staticmethod + def delete_public_nets(radl): + """ + Helper function to correctly delete references to public nets in an RADL + """ + nets_id = [net.id for net in radl.networks if net.isPublic()] + system = radl.systems[0] + + i = 0 + while system.getValue('net_interface.%d.connection' % i): + next_net = system.getValue('net_interface.%d.connection' % (i + 1)) + next_dns = system.getValue('net_interface.%d.connection' % (i + 1)) + f = system.getFeature("net_interface.%d.connection" % i) + if f.value in nets_id: + if next_net: + system.setValue('net_interface.%d.connection' % i, next_net) + system.setValue('net_interface.%d.dns_name' % i, next_dns) + else: + system.delValue('net_interface.%d.connection' % i) + system.delValue('net_interface.%d.dns_name' % i) + if system.getValue('net_interface.%d.ip' % i): + system.delValue('net_interface.%d.ip' % i) + i += 1 diff --git a/IM/connectors/OCCI.py b/IM/connectors/OCCI.py index 89f391bfe..270f53bcf 100644 --- a/IM/connectors/OCCI.py +++ b/IM/connectors/OCCI.py @@ -1193,18 +1193,7 @@ def manage_nics(self, vm, radl, auth_data, auth_header): if success: # Remove all public net connections in the Requested RADL - 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 - + vm.delete_public_nets(vm.requested_radl) return True, "" else: return False, msg diff --git a/IM/connectors/OpenStack.py b/IM/connectors/OpenStack.py index b98b678b0..89855dab6 100644 --- a/IM/connectors/OpenStack.py +++ b/IM/connectors/OpenStack.py @@ -551,8 +551,7 @@ def update_system_info_from_instance(self, system, instance_type): if instance_type: LibCloudCloudConnector.update_system_info_from_instance(system, instance_type) if instance_type.vcpus: - system.addFeature( - Feature("cpu.count", "=", instance_type.vcpus), conflict="me", missing="other") + system.addFeature(Feature("cpu.count", "=", instance_type.vcpus), conflict="me", missing="other") @staticmethod def get_ost_net(driver, name=None, netid=None): @@ -1088,7 +1087,7 @@ def manage_elastic_ips(self, vm, node, public_ips): while vm.getRequestedSystem().getValue("net_interface." + str(n) + ".connection"): net_conn = vm.getRequestedSystem().getValue('net_interface.' + str(n) + '.connection') net = vm.info.get_network_by_id(net_conn) - if net.isPublic(): + if net and net.isPublic(): fixed_ip = vm.getRequestedSystem().getValue("net_interface." + str(n) + ".ip") pool_name = net.getValue("provider_id") requested_ips.append((fixed_ip, pool_name)) @@ -1610,6 +1609,7 @@ def alter_public_ips(self, vm, radl, auth_data): current_public_ip = vm.getPublicIP() new_has_public_ip = radl.hasPublicNet(vm.info.systems[0].name) if new_has_public_ip and not current_public_ip: + self.log_info("Adding Public IP.") for net in radl.networks: if net.isPublic(): new_public_net = net.clone() @@ -1622,34 +1622,12 @@ def alter_public_ips(self, vm, radl, auth_data): if not new_has_public_ip and current_public_ip: floating_ip = node.driver.ex_get_floating_ip(current_public_ip) + self.log_info("Removing Public IP: %s." % floating_ip) if node.driver.ex_detach_floating_ip_from_node(node, floating_ip): floating_ip.delete() # Remove all public net connections in the Requested RADL - 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) - 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 + vm.delete_public_nets(vm.requested_radl) return True, "" else: diff --git a/test/unit/connectors/OpenStack.py b/test/unit/connectors/OpenStack.py index 1954b6bc8..51fb63258 100755 --- a/test/unit/connectors/OpenStack.py +++ b/test/unit/connectors/OpenStack.py @@ -535,7 +535,7 @@ def test_55_alter(self, add_elastic_ip_from_pool, get_driver): node.id = "1" node.state = "running" node.extra = {'flavorId': 'small', 'vm_state': 'resized'} - node.public_ips = ['158.42.1.1'] + node.public_ips = [] node.private_ips = ['10.0.0.1'] node.driver = driver driver.ex_get_node_details.return_value = node @@ -547,6 +547,7 @@ def test_55_alter(self, add_elastic_ip_from_pool, get_driver): node_size.vcpus = 2 node_size.name = "small" driver.list_sizes.return_value = [node_size] + driver.ex_get_size.return_value = node_size driver.ex_resize.return_value = True driver.ex_confirm_resize.return_value = True @@ -618,6 +619,7 @@ def test_55_alter(self, add_elastic_ip_from_pool, get_driver): fip.delete.return_value = True driver.ex_get_floating_ip.return_value = fip driver.ex_detach_floating_ip_from_node.return_value = True + node.public_ips = ['158.42.1.1'] success, _ = ost_cloud.alterVM(vm, new_radl, auth) self.assertTrue(success, msg="ERROR: modifying VM info.")