diff --git a/base/manifest-schema.json b/base/manifest-schema.json index a98907b..cc723a4 100644 --- a/base/manifest-schema.json +++ b/base/manifest-schema.json @@ -10,8 +10,10 @@ "type": "object", "properties": { "mount_dir": { "type": "string" }, + "image_file": { "type": "string" }, "tarball": { "type": "boolean" }, - "tarball_dir": { "type": "string" } + "tarball_dir": { "type": "string" }, + "device" : { "type" : "string" } }, "required": ["mount_dir"] }, diff --git a/manifests/one-raw-virtio.manifest.json b/manifests/one-raw-virtio.manifest.json index 999e8a1..94f65cc 100644 --- a/manifests/one-raw-virtio.manifest.json +++ b/manifests/one-raw-virtio.manifest.json @@ -7,7 +7,8 @@ }, "bootstrapper": { - "mount_dir": "/tmp/target", + "mount_dir": "/mnt/target", + "image_file": "/tmp/target", "tarball": true, "device": "/dev/sda" }, diff --git a/providers/one/tasks/filesystem.py b/providers/one/tasks/filesystem.py index 30a8c36..d3d9a4f 100644 --- a/providers/one/tasks/filesystem.py +++ b/providers/one/tasks/filesystem.py @@ -3,18 +3,22 @@ from common import phases from common.exceptions import TaskError from common.tools import log_check_call from bootstrap import Bootstrap - +import os class FormatVolume(Task): description = 'Formatting the volume' phase = phases.volume_preparation def run(self, info): - mkmount = 'create -f raw "'+info.manifest.bootstrapper['mount_dir']+'" "'+str(info.manifest.volume['size'])+'"' - log_check_call(['/usr/bin/qemu-img',mkmount]) - dev_path = info.manifest.bootstrapper['mount_dir'] - mkfs = '/sbin/mkfs.{fs}'.format(fs=info.manifest.volume['filesystem']) - log_check_call([mkfs, dev_path]) + mkmount = ['/usr/bin/qemu-img', 'create', '-f', 'raw', info.manifest.bootstrapper['image_file'], str(info.manifest.volume['size'])+'M'] + log_check_call(mkmount) + ddcmd = ['/bin/dd', 'if=/dev/zero', 'bs=1024', 'conv=notrunc', 'count='+str(info.manifest.volume['size']), 'of='+info.manifest.bootstrapper['image_file']] + log_check_call(ddcmd) + loopcmd = ['/sbin/losetup', '/dev/loop0', info.manifest.bootstrapper['image_file']] + log_check_call(loopcmd) + mkfs = [ '/sbin/mkfs.{fs}'.format(fs=info.manifest.volume['filesystem']), '-m', '1', '-v', '/dev/loop0'] + log_check_call(mkfs) + class TuneVolumeFS(Task): @@ -23,7 +27,8 @@ class TuneVolumeFS(Task): after = [FormatVolume] def run(self, info): - dev_path = info.bootstrap_device['path'] + #dev_path = info.bootstrap_device['path'] + dev_path = info.manifest.bootstrapper['image_file'] # Disable the time based filesystem check log_check_call(['/sbin/tune2fs', '-i', '0', dev_path]) @@ -44,9 +49,9 @@ class CreateMountDir(Task): def run(self, info): import os mount_dir = info.manifest.bootstrapper['mount_dir'] - info.root = '{mount_dir}/{vol_id}'.format(mount_dir=mount_dir, vol_id=info.volume.id) + info.root = mount_dir # Works recursively, fails if last part exists, which is exaclty what we want. - os.makedirs(info.root) + os.makedirs(mount_dir) class MountVolume(Task): @@ -61,7 +66,7 @@ class MountVolume(Task): msg = 'Something is already mounted at {root}'.format(root=info.root) raise TaskError(msg) - log_check_call(['/bin/mount', info.bootstrap_device['path'], info.root]) + log_check_call(['/bin/mount', '-t', info.manifest.volume['filesystem'], '/dev/loop0', info.root]) class MountSpecials(Task): @@ -94,6 +99,8 @@ class UnmountVolume(Task): def run(self, info): log_check_call(['/bin/umount', info.root]) + log_check_call(['/sbin/losetup', '-d', '/dev/loop0']) + class DeleteMountDir(Task): diff --git a/providers/one/tasks/packages.py b/providers/one/tasks/packages.py index b5474b4..eb2260a 100644 --- a/providers/one/tasks/packages.py +++ b/providers/one/tasks/packages.py @@ -7,7 +7,7 @@ class HostPackages(Task): phase = phases.preparation def run(self, info): - packages = set(['debootstrap']) + packages = set(['debootstrap', 'qemu-utils']) if info.manifest.volume['filesystem'] == 'xfs': packages.add('xfsprogs')