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
This commit is contained in:
Bob Ball
2013-03-19 14:12:29 +00:00
parent db8dfce951
commit 90cda3512a
3 changed files with 48 additions and 1 deletions

View File

@@ -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())