Commit 0794ccb1 by Karsa Zoltán István

resize add via qemu

parent 2b5fe878
......@@ -217,8 +217,14 @@ class Disk(object):
os.removedirs(tmp_dir)
self.size = Disk.get(self.dir, self.name).size
def resize(self, newsize):
file = self.get_path()
# can't resize an image which has snapchots
cmdline =[ 'qemu-img', 'resize', file, newsize]
subprocess.check_output(cmdline)
self.size = Disk.get(self.dir, self.name).size
def download(self, task, url, parent_id=None): # noqa
def download(self, task, url, parent_id=None, resize=None): # noqa
"""Download image from url."""
disk_path = self.get_path()
logger.info("Downloading image from %s to %s", url, disk_path)
......@@ -267,6 +273,10 @@ class Disk(object):
self.size = Disk.get(self.dir, self.name).size
logger.debug("Download finished %s (%s bytes)",
self.name, self.size)
if resize:
self.resize(resize)
logger.debug("Resize finished %s (%s bytes)",
self.name, self.size)
except AbortException:
# Cleanup file:
os.unlink(disk_path)
......
......@@ -29,6 +29,12 @@ def create(disk_desc):
@celery.task()
def resizeqemu(disk_desc, newsize):
disk = Disk.deserialize(disk_desc)
disk.resize(newsize)
@celery.task()
def create_ci_disk(disk_desc, meta_data, user_data, network_data):
disk = Disk.deserialize(disk_desc)
disk.create_ci_disk(meta_data=meta_data, user_data=user_data, network_data=network_data)
......@@ -44,8 +50,9 @@ class download(AbortableTask):
disk_desc = kwargs['disk']
url = kwargs['url']
parent_id = kwargs.get("parent_id", None)
resize = kwargs.get('resize', None)
disk = Disk.deserialize(disk_desc)
disk.download(self, url, parent_id)
disk.download(self, url, parent_id, resize)
return {'size': disk.size,
'type': disk.format,
'checksum': disk.checksum, }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment