mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 07:26:29 +00:00

Got stuck on the bundle image call, it uses argparse. Somehow we need to fake the arguments.
46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
from base import Task
|
|
from common import phases
|
|
from common.tools import log_check_call
|
|
|
|
|
|
class Create(Task):
|
|
description = 'Creating a loopback volume'
|
|
phase = phases.volume_creation
|
|
|
|
def run(self, info):
|
|
loopback_filename = 'loopback-{id:x}.img'.format(id=info.run_id)
|
|
import os.path
|
|
info.loopback_file = os.path.join(info.manifest.volume['loopback_dir'], loopback_filename)
|
|
log_check_call(['/bin/dd',
|
|
'if=/dev/zero', 'of='+info.loopback_file,
|
|
'bs=1M', 'seek='+info.manifest.volume['size'], 'count=0'])
|
|
|
|
|
|
class Attach(Task):
|
|
description = 'Attaching the loopback volume'
|
|
phase = phases.volume_creation
|
|
after = [Create]
|
|
|
|
def run(self, info):
|
|
info.bootstrap_device = {}
|
|
info.bootstrap_device['path'] = log_check_call(['/sbin/losetup', '--find'])
|
|
log_check_call(['/sbin/losetup', info.bootstrap_device['path'], info.loopback_file])
|
|
|
|
|
|
class Detach(Task):
|
|
description = 'Detaching the loopback volume'
|
|
phase = phases.volume_unmounting
|
|
|
|
def run(self, info):
|
|
log_check_call(['/sbin/losetup', '-d', info.bootstrap_device['path']])
|
|
del info.bootstrap_device
|
|
|
|
|
|
class Delete(Task):
|
|
description = 'Deleting the loopback volume'
|
|
phase = phases.cleaning
|
|
|
|
def run(self, info):
|
|
from os import remove
|
|
remove(info.bootstrap_device['path'])
|
|
del info.loopback_file
|