add plugin to convert raw images to vdi,qcow etc...

This commit is contained in:
Olivier Sallou 2013-08-13 10:36:32 +02:00
parent 5e1a531890
commit 3dd3e00e5c
4 changed files with 52 additions and 0 deletions

View file

@ -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,
]

View file

@ -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)

View file

@ -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"]
}

View file

@ -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)