From 75c3f355dbdca919f0913c72e4f0bd95ce944834 Mon Sep 17 00:00:00 2001 From: Wojtek Porczyk Date: Mon, 28 Sep 2015 23:34:29 +0200 Subject: [PATCH] qubes/vm/qubesvm: fix domain's UUID management Now we generate UUID on domain's instantiation. This is needed, because we sometimes don't update XML (like in qvm-start). fixes QubesOS/qubes-issues#1236 --- qubes/vm/__init__.py | 3 +-- qubes/vm/qubesvm.py | 16 ++++++++-------- vm-config/wni-vm-template-hvm.xml | 2 +- vm-config/wni-vm-template.xml | 2 +- vm-config/xen-vm-template-hvm.xml | 2 +- vm-config/xen-vm-template.xml | 2 +- 6 files changed, 13 insertions(+), 14 deletions(-) diff --git a/qubes/vm/__init__.py b/qubes/vm/__init__.py index 41f83a10..1605fe59 100644 --- a/qubes/vm/__init__.py +++ b/qubes/vm/__init__.py @@ -356,8 +356,7 @@ class BaseVM(qubes.PropertyHolder): args['name'] = self.name if hasattr(self, 'kernels_dir'): args['kerneldir'] = self.kernels_dir - args['uuidnode'] = '{!s}'.format(self.uuid) \ - if hasattr(self, 'uuid') else '' + args['uuid'] = str(self.uuid) args['vmdir'] = self.dir_path args['pcidevs'] = ''.join(lxml.etree.tostring(self.lvxml_pci_dev(dev)) for dev in self.devices['pci']) diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index f1cad69c..7181fd38 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -317,13 +317,8 @@ class QubesVM(qubes.vm.BaseVM): # XXX _update_libvirt_domain? try: - if hasattr(self, 'uuid'): - self._libvirt_domain = self.app.vmm.libvirt_conn.lookupByUUID( - self.uuid.bytes) - else: - self._libvirt_domain = self.app.vmm.libvirt_conn.lookupByName( - self.name) - self.uuid = uuid.UUID(bytes=self._libvirt_domain.UUID()) + self._libvirt_domain = self.app.vmm.libvirt_conn.lookupByUUID( + self.uuid.bytes) except libvirt.libvirtError: if self.app.vmm.libvirt_conn.virConnGetLastError()[0] == \ libvirt.VIR_ERR_NO_DOMAIN: @@ -544,6 +539,12 @@ class QubesVM(qubes.vm.BaseVM): # event handlers # + @qubes.events.handler('domain-init', 'domain-loaded') + def on_domain_init_loaded(self, event): + if not hasattr(self, 'uuid'): + self.uuid = uuid.uuid4() + + @qubes.events.handler('property-set:label') def on_property_set_label(self, event, name, new_label, old_label=None): # pylint: disable=unused-argument @@ -1717,7 +1718,6 @@ class QubesVM(qubes.vm.BaseVM): try: self._libvirt_domain = self.app.vmm.libvirt_conn.defineXML( domain_config) - self.uuid = uuid.UUID(bytes=self._libvirt_domain.UUID()) except libvirt.libvirtError: if self.app.vmm.libvirt_conn.virConnGetLastError()[0] == \ libvirt.VIR_ERR_NO_DOMAIN: diff --git a/vm-config/wni-vm-template-hvm.xml b/vm-config/wni-vm-template-hvm.xml index ce0e2eb3..fe26c78b 100644 --- a/vm-config/wni-vm-template-hvm.xml +++ b/vm-config/wni-vm-template-hvm.xml @@ -1,6 +1,6 @@ {name} - {uuidnode} + {uuid} {maxmem} hvm diff --git a/vm-config/wni-vm-template.xml b/vm-config/wni-vm-template.xml index c287819e..d099fa52 100644 --- a/vm-config/wni-vm-template.xml +++ b/vm-config/wni-vm-template.xml @@ -1,6 +1,6 @@ {name} - {uuidnode} + {uuid} {maxmem} pv diff --git a/vm-config/xen-vm-template-hvm.xml b/vm-config/xen-vm-template-hvm.xml index ba2dc862..62ccc5ed 100644 --- a/vm-config/xen-vm-template-hvm.xml +++ b/vm-config/xen-vm-template-hvm.xml @@ -1,6 +1,6 @@ {name} - {uuidnode} + {uuid} {maxmem} {mem} {vcpus} diff --git a/vm-config/xen-vm-template.xml b/vm-config/xen-vm-template.xml index ccb89c93..bbb8b274 100644 --- a/vm-config/xen-vm-template.xml +++ b/vm-config/xen-vm-template.xml @@ -1,6 +1,6 @@ {name} - {uuidnode} + {uuid} {maxmem} {mem} {vcpus}