From 3dd3e00e5c946d839d6903fc2cc4eeadb552be68 Mon Sep 17 00:00:00 2001 From: Olivier Sallou Date: Tue, 13 Aug 2013 10:36:32 +0200 Subject: [PATCH] add plugin to convert raw images to vdi,qcow etc... --- common/phases.py | 2 ++ plugins/convert_image/__init__.py | 11 +++++++++++ plugins/convert_image/manifest-schema.json | 23 ++++++++++++++++++++++ plugins/convert_image/tasks.py | 16 +++++++++++++++ 4 files changed, 52 insertions(+) create mode 100644 plugins/convert_image/__init__.py create mode 100644 plugins/convert_image/manifest-schema.json create mode 100644 plugins/convert_image/tasks.py diff --git a/common/phases.py b/common/phases.py index 3b44eb2..83743d8 100644 --- a/common/phases.py +++ b/common/phases.py @@ -9,6 +9,7 @@ system_modification = Phase('System modification', 'Installing software, modifyi system_cleaning = Phase('System cleaning', 'Removing sensitive data, temporary files and other leftovers') volume_unmounting = Phase('Volume unmounting', 'Unmounting the bootstrap volume') image_registration = Phase('Image registration', 'Uploading/Registering with the provider') +image_conversion = Phase('Image conversion', 'Conversion/Compression of the image result file') cleaning = Phase('Cleaning', 'Removing temporary files') order = [preparation, @@ -20,5 +21,6 @@ order = [preparation, system_cleaning, volume_unmounting, image_registration, + image_conversion, cleaning, ] diff --git a/plugins/convert_image/__init__.py b/plugins/convert_image/__init__.py new file mode 100644 index 0000000..a36d8f4 --- /dev/null +++ b/plugins/convert_image/__init__.py @@ -0,0 +1,11 @@ + + +def tasks(tasklist, manifest): + from tasks import ConvertImage + tasklist.add(ConvertImage()) + + +def validate_manifest(data, schema_validate): + from os import path + schema_path = path.normpath(path.join(path.dirname(__file__), 'manifest-schema.json')) + schema_validate(data, schema_path) diff --git a/plugins/convert_image/manifest-schema.json b/plugins/convert_image/manifest-schema.json new file mode 100644 index 0000000..6c7fd8d --- /dev/null +++ b/plugins/convert_image/manifest-schema.json @@ -0,0 +1,23 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Convert image", + "type": "object", + "properties": { + "plugins": { + "type": "object", + "properties": { + "convert_image": { + "type": "object", + "properties": { + "format": { + "type": "string" + } + }, + "required": ["format"] + } + }, + "required": ["convert_image"] + } + }, + "required": ["plugins"] +} diff --git a/plugins/convert_image/tasks.py b/plugins/convert_image/tasks.py new file mode 100644 index 0000000..91f02fc --- /dev/null +++ b/plugins/convert_image/tasks.py @@ -0,0 +1,16 @@ +from base import Task +from common import phases +from common.tasks.filesystem import DeleteMountDir + + +class ConvertImage(Task): + description = 'Convert raw image' + phase = phases.image_conversion + + def run(self, info): + from common.tools import log_check_call + converted_file = info.loopback_file.replace('img',info.manifest.plugins['convert_image']['format']) + log_check_call(['/usr/bin/qemu-img', 'convert', '-O', info.manifest.plugins['convert_image']['format'], info.loopback_file, converted_file]) + import os + os.remove(info.loopback_file) +