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
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user