bootstrap-vz/bootstrapvz/providers/azure/tasks/image.py

27 lines
1 KiB
Python
Raw Normal View History

2014-04-07 14:23:24 +02:00
from bootstrapvz.base import Task
from bootstrapvz.common import phases
from bootstrapvz.common.tasks import loopback
class ConvertToVhd(Task):
description = 'Convert raw image to vhd disk'
phase = phases.image_registration
@classmethod
def run(cls, info):
image_name = info.manifest.image['name'].format(**info.manifest_vars)
filename = '{image_name}.{ext}'.format(image_name=image_name, ext='vhd')
import os.path
destination = os.path.join(info.manifest.bootstrapper['workspace'], filename)
file_size = os.path.getsize(info.volume.image_path)
rounded_vol_size = str(((file_size/(1024*1024)+1)*(1024*1024)))
from bootstrapvz.common.tools import log_check_call
log_check_call(['qemu-img', 'resize', info.volume.image_path, rounded_vol_size])
log_check_call(['qemu-img', 'convert', '-o', 'subformat=fixed', '-O', 'vpc', info.volume.image_path, destination])
os.remove(info.volume.image_path)
import logging
log = logging.getLogger(__name__)
log.info('The volume image has been moved to {image_path}'.format(image_path=destination))