Skip to content

Commit

Permalink
Merge pull request #1072 from grycap/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
micafer authored Oct 20, 2020
2 parents 4c417db + 6ae616b commit ced8d09
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions IM/VirtualMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down
12 changes: 12 additions & 0 deletions test/unit/VirtualMachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit ced8d09

Please sign in to comment.