diff --git a/IM/VirtualMachine.py b/IM/VirtualMachine.py index 708a1c040..967ab1113 100644 --- a/IM/VirtualMachine.py +++ b/IM/VirtualMachine.py @@ -564,8 +564,24 @@ def update_status(self, auth, force=False): self.state = new_state self.info.systems[0].setValue("state", new_state) + # Replace the #N# in dns_names + self.replace_dns_name(self.info.systems[0]) + return updated + def replace_dns_name(self, vm_system): + """Replace the #N# in dns_names.""" + cont = 0 + while vm_system.getValue('net_interface.%d.connection' % cont): + vm_dns_name = vm_system.getValue('net_interface.%d.dns_name' % cont) + # if dns_name is not set in iface 0 set the default one + if cont == 0 and vm_dns_name is None: + vm_dns_name = Config.DEFAULT_VM_NAME + if vm_dns_name and "#N#" in vm_dns_name: + vm_dns_name = vm_dns_name.replace("#N#", str(self.im_id)) + vm_system.setValue('net_interface.%d.dns_name' % cont, vm_dns_name) + cont += 1 + @staticmethod def add_public_net(radl): """ diff --git a/test/unit/VirtualMachine.py b/test/unit/VirtualMachine.py index feab96a42..b4f0a6402 100755 --- a/test/unit/VirtualMachine.py +++ b/test/unit/VirtualMachine.py @@ -159,6 +159,18 @@ def test_setIps(self): self.assertEqual(vm.info.systems[0].getValue('net_interface.0.ip'), "10.0.0.1") self.assertEqual(vm.info.systems[0].getValue('net_interface.2.ip'), "192.168.0.1") + def test_replace_dns_name(self): + radl_data = """ + system test ( + net_interface.0.connection = 'public' and + net_interface.0.dns_name = 'vnode-#N#' + )""" + radl = radl_parse.parse_radl(radl_data) + cloud_con = MagicMock() + vm = VirtualMachine(None, "1", None, radl, radl, cloud_con, 1) + vm.update_status(None) + self.assertEqual(vm.info.systems[0].getValue('net_interface.0.dns_name'), "vnode-1") + if __name__ == '__main__': unittest.main()