diff options
| author | Dan Prince <dprince@redhat.com> | 2012-07-26 11:23:13 -0400 |
|---|---|---|
| committer | Dan Prince <dprince@redhat.com> | 2012-07-26 14:14:57 -0400 |
| commit | f6f293ea44c73c59e651817a9315778ab5aa0e5e (patch) | |
| tree | fd399a2dc565c2cc96e961f08b46b23d3efaa3f7 /nova/virt | |
| parent | ee4e63dbf45a46fc35f1a6681b49ee2aba9b396b (diff) | |
Don't import libvirt_utils in disk api.
Updates the virt/disk/api so that we no longer import libvirt_utils.
This fixes issues when using Nova compute with compute drivers other
than libvirt. (xenapi, etc.)
Fixes LP Bug #1029501.
Change-Id: I46ece309480ce0a0941a96371a51d77712c41eb6
Diffstat (limited to 'nova/virt')
| -rw-r--r-- | nova/virt/disk/api.py | 18 | ||||
| -rw-r--r-- | nova/virt/libvirt/driver.py | 2 | ||||
| -rw-r--r-- | nova/virt/libvirt/imagebackend.py | 2 |
3 files changed, 17 insertions, 5 deletions
diff --git a/nova/virt/disk/api.py b/nova/virt/disk/api.py index 68d83c386..e55b54fa1 100644 --- a/nova/virt/disk/api.py +++ b/nova/virt/disk/api.py @@ -39,7 +39,7 @@ from nova import utils from nova.virt.disk import guestfs from nova.virt.disk import loop from nova.virt.disk import nbd -from nova.virt.libvirt import utils as libvirt_utils +from nova.virt import images LOG = logging.getLogger(__name__) @@ -103,9 +103,21 @@ def resize2fs(image, check_exit_code=False): utils.execute('resize2fs', image, check_exit_code=check_exit_code) +def get_disk_size(path): + """Get the (virtual) size of a disk image + + :param path: Path to the disk image + :returns: Size (in bytes) of the given disk image as it would be seen + by a virtual machine. + """ + size = images.qemu_img_info(path)['virtual size'] + size = size.split('(')[1].split()[0] + return int(size) + + def extend(image, size): """Increase image to size""" - virt_size = libvirt_utils.get_disk_size(image) + virt_size = get_disk_size(image) if virt_size >= size: return utils.execute('qemu-img', 'resize', image, size) @@ -117,7 +129,7 @@ def can_resize_fs(image, size, use_cow=False): """Check whether we can resize contained file system.""" # Check that we're increasing the size - virt_size = libvirt_utils.get_disk_size(image) + virt_size = get_disk_size(image) if virt_size >= size: return False diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 761ca3e45..71454d38e 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -2667,7 +2667,7 @@ class LibvirtDriver(driver.ComputeDriver): disk_type = driver_nodes[cnt].get('type') if disk_type == "qcow2": backing_file = libvirt_utils.get_disk_backing_file(path) - virt_size = libvirt_utils.get_disk_size(path) + virt_size = disk.get_disk_size(path) else: backing_file = "" virt_size = 0 diff --git a/nova/virt/libvirt/imagebackend.py b/nova/virt/libvirt/imagebackend.py index d66dbaf2c..001bf58a3 100644 --- a/nova/virt/libvirt/imagebackend.py +++ b/nova/virt/libvirt/imagebackend.py @@ -191,7 +191,7 @@ class Lvm(Image): def create_image(self, prepare_template, base, size, *args, **kwargs): @utils.synchronized(base) def create_lvm_image(base, size): - base_size = libvirt_utils.get_disk_size(base) + base_size = disk.get_disk_size(base) resize = size > base_size size = size if resize else base_size libvirt_utils.create_lvm_image(self.vg, self.lv, |
