diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-07-26 18:43:55 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-07-26 18:43:55 +0000 |
| commit | 39a40142254d4dbad8dfe1509d92e7e9fdbb44fb (patch) | |
| tree | 9ea927e7fcef0ed15ef55829c671576c5f58cc9d /nova/virt | |
| parent | 7bcd57c88e49efc762372484cde38d2c6d724b9f (diff) | |
| parent | f6f293ea44c73c59e651817a9315778ab5aa0e5e (diff) | |
Merge "Don't import libvirt_utils in disk api."
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, |
