diff options
| author | Boris Filippov <bfilippov@griddynamics.com> | 2012-09-26 02:53:33 +0400 |
|---|---|---|
| committer | Boris Filippov <bfilippov@griddynamics.com> | 2012-10-03 03:59:26 +0400 |
| commit | c96c4df3e6f3934a9238ca9cd0d3797d28bdf80c (patch) | |
| tree | d17b48ecd593e2df07888bf9d1a06ca4f36903a3 /nova | |
| parent | 3cb3db034ddf9a2b82ebd87b2ba612ab779f63be (diff) | |
| download | nova-c96c4df3e6f3934a9238ca9cd0d3797d28bdf80c.tar.gz nova-c96c4df3e6f3934a9238ca9cd0d3797d28bdf80c.tar.xz nova-c96c4df3e6f3934a9238ca9cd0d3797d28bdf80c.zip | |
Create util for root device path retrieval
blueprint snapshots-for-everyone
Create libvirt.utils.find_disk(virt_dom) function.
This function will retrieve disk path from instance configuration.
Will return path both for file and device backed instance root devices.
Will throw error in case, when device can't be found.
Change-Id: I612a19221c6ff78079ab53a8d77295c555514c77
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/tests/fake_libvirt_utils.py | 4 | ||||
| -rw-r--r-- | nova/virt/libvirt/driver.py | 5 | ||||
| -rw-r--r-- | nova/virt/libvirt/utils.py | 17 |
3 files changed, 22 insertions, 4 deletions
diff --git a/nova/tests/fake_libvirt_utils.py b/nova/tests/fake_libvirt_utils.py index 510774939..378515ac0 100644 --- a/nova/tests/fake_libvirt_utils.py +++ b/nova/tests/fake_libvirt_utils.py @@ -98,6 +98,10 @@ def file_open(path, mode=None): return File(path, mode) +def find_disk(virt_dom): + return "some/path" + + def load_file(path): if os.path.exists(path): with open(path, 'r') as fp: diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 22c64a218..8585c3463 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -823,10 +823,7 @@ class LibvirtDriver(driver.ComputeDriver): metadata['container_format'] = base.get('container_format', 'bare') # Find the disk - xml_desc = virt_dom.XMLDesc(0) - domain = etree.fromstring(xml_desc) - source = domain.find('devices/disk/source') - disk_path = source.get('file') + disk_path = libvirt_utils.find_disk(virt_dom) snapshot_name = uuid.uuid4().hex diff --git a/nova/virt/libvirt/utils.py b/nova/virt/libvirt/utils.py index 8579abb8a..73e0201df 100644 --- a/nova/virt/libvirt/utils.py +++ b/nova/virt/libvirt/utils.py @@ -24,6 +24,7 @@ import hashlib import os import re +from lxml import etree from nova import exception from nova import flags from nova.openstack.common import cfg @@ -394,6 +395,22 @@ def file_delete(path): return os.unlink(path) +def find_disk(virt_dom): + """Find root device path for instance + + May be file or device""" + xml_desc = virt_dom.XMLDesc(0) + domain = etree.fromstring(xml_desc) + source = domain.find('devices/disk/source') + disk_path = source.get('file') or source.get('dev') + + if not disk_path: + raise RuntimeError(_("Can't retrieve root device path " + "from instance libvirt configuration")) + + return disk_path + + def get_fs_info(path): """Get free/used/total space info for a filesystem |
