From 90cda3512ae509d548bf2b4343ce0d8b8b9bfb43 Mon Sep 17 00:00:00 2001 From: Bob Ball Date: Tue, 19 Mar 2013 14:12:29 +0000 Subject: xenapi: Retrieve VM uuid from xenstore. Fall back to retrieving the uuid from xenstore if /sys/hypervisor/uuid isn't accessible. Change-Id: I409079068d3102ff86a71431b29c1ce2e6fe8857 Fixes: bug #1157211 --- nova/virt/xenapi/vm_utils.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'nova/virt') diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 26bd9d268..99e7712c8 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -1918,11 +1918,25 @@ def vdi_attached_here(session, vdi_ref, read_only=False): LOG.debug(_('Destroying VBD for VDI %s done.'), vdi_ref) -def get_this_vm_uuid(): +def _get_sys_hypervisor_uuid(): with file('/sys/hypervisor/uuid') as f: return f.readline().strip() +def get_this_vm_uuid(): + try: + return _get_sys_hypervisor_uuid() + except IOError: + # Some guest kernels (without 5c13f8067745efc15f6ad0158b58d57c44104c25) + # cannot read from uuid after a reboot. Fall back to trying xenstore. + # See https://bugs.launchpad.net/ubuntu/+source/xen-api/+bug/1081182 + domid, _ = utils.execute('xenstore-read', 'domid', run_as_root=True) + vm_key, _ = utils.execute('xenstore-read', + '/local/domain/%s/vm' % domid.strip(), + run_as_root=True) + return vm_key.strip()[4:] + + def _get_this_vm_ref(session): return session.call_xenapi("VM.get_by_uuid", get_this_vm_uuid()) -- cgit