diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-03-12 22:56:05 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-03-12 22:56:05 +0000 |
| commit | b9b30e0ff8e8a7e0ddcfc6f5007f647eee54e6f1 (patch) | |
| tree | 39f73e53136571d93c9d6cff934dd4ca80d92c1b /nova | |
| parent | f734f751759c7ad5c9d6f0f98f04284742d3b68f (diff) | |
| parent | 77664b256856980cfaf35173d59d463c16562673 (diff) | |
| download | nova-b9b30e0ff8e8a7e0ddcfc6f5007f647eee54e6f1.tar.gz nova-b9b30e0ff8e8a7e0ddcfc6f5007f647eee54e6f1.tar.xz nova-b9b30e0ff8e8a7e0ddcfc6f5007f647eee54e6f1.zip | |
Merge "Checks image virtual size before qemu-img resize."
Diffstat (limited to 'nova')
| -rw-r--r-- | nova/virt/disk/api.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/nova/virt/disk/api.py b/nova/virt/disk/api.py index f8b51fb31..7b207c09e 100644 --- a/nova/virt/disk/api.py +++ b/nova/virt/disk/api.py @@ -29,6 +29,7 @@ import crypt import json import os import random +import re import tempfile from nova import exception @@ -90,6 +91,10 @@ for s in FLAGS.virt_mkfs: _DEFAULT_MKFS_COMMAND = mkfs_command +_QEMU_VIRT_SIZE_REGEX = re.compile('^virtual size: (.*) \(([0-9]+) bytes\)', + re.MULTILINE) + + def mkfs(os_type, fs_label, target): mkfs_command = (_MKFS_COMMAND.get(os_type, _DEFAULT_MKFS_COMMAND) or '') % locals() @@ -97,10 +102,17 @@ def mkfs(os_type, fs_label, target): utils.execute(*mkfs_command.split()) +def get_image_virtual_size(image): + out, _err = utils.execute('qemu-img', 'info', image) + m = _QEMU_VIRT_SIZE_REGEX.search(out) + return int(m.group(2)) + + def extend(image, size): """Increase image to size""" - file_size = os.path.getsize(image) - if file_size >= size: + # NOTE(MotoKen): check image virtual size before resize + virt_size = get_image_virtual_size(image) + if virt_size >= size: return utils.execute('qemu-img', 'resize', image, size) # NOTE(vish): attempts to resize filesystem |
