API for creating a qemu disk image

This commit is contained in:
Julien Duponchelle
2015-07-27 19:18:36 +02:00
parent 5d8c90d138
commit 5b0c36c0d6
6 changed files with 123 additions and 60 deletions

View File

@ -189,7 +189,6 @@ class QemuVM(BaseVM):
:param hda_disk_image: QEMU hda disk image path
"""
self._hda_disk_image = self.manager.get_abs_image_path(hda_disk_image)
log.info('QEMU VM "{name}" [{id}] has set the QEMU hda disk image path to {disk_image}'.format(name=self._name,
id=self._id,
@ -1242,31 +1241,3 @@ class QemuVM(BaseVM):
answer["kernel_image_md5sum"] = md5sum(self._kernel_image)
return answer
@asyncio.coroutine
def _create_disk(self, name, options):
"""
Create a qemu disk with qemu-img
:param name: Image name without the extension
:param options: Disk image creation options
:returns: Image name with the extensions
"""
img_format = options.pop("format")
img_size = options.pop("size")
img_name = "{}.{}".format(name, img_format)
qemu_img = self._get_qemu_img()
command = [qemu_img, "create", "-f", img_format]
for option in sorted(options.keys()):
command.extend(["-o", "{}={}".format(option, options[option])])
command.append(os.path.join(self.working_dir, img_name))
command.append("{}M".format(img_size))
try:
process = yield from asyncio.create_subprocess_exec(*command)
yield from process.wait()
except (OSError, subprocess.SubprocessError) as e:
raise QemuError("Could create disk image {}:{}".format(name, e))
return img_name