bootstrap-vz/providers/ec2/tasks/filesystem.py

108 lines
3 KiB
Python
Raw Normal View History

2013-06-27 00:11:09 +02:00
from base import Task
from common import phases
from common.exceptions import TaskError
2013-07-01 22:06:42 +02:00
from common.tools import log_check_call
2013-07-01 20:48:51 +02:00
from bootstrap import Bootstrap
2013-06-27 00:11:09 +02:00
class FormatVolume(Task):
description = 'Formatting the volume'
phase = phases.volume_preparation
def run(self, info):
dev_path = info.bootstrap_device['path']
mkfs = '/sbin/mkfs.{fs}'.format(fs=info.manifest.volume['filesystem'])
2013-07-01 22:21:47 +02:00
log_check_call([mkfs, dev_path])
2013-06-27 00:11:09 +02:00
class TuneVolumeFS(Task):
description = 'Tuning the bootstrap volume filesystem'
phase = phases.volume_preparation
after = [FormatVolume]
def run(self, info):
dev_path = info.bootstrap_device['path']
# Disable the time based filesystem check
2013-07-01 22:06:42 +02:00
command = ['/sbin/tune2fs', '-i', '0', dev_path]
2013-07-01 22:21:47 +02:00
log_check_call(command)
2013-06-27 00:11:09 +02:00
class AddXFSProgs(Task):
description = 'Adding `xfsprogs\' to the image packages'
phase = phases.preparation
def run(self, info):
include, exclude = info.img_packages
include.add('xfsprogs')
class CreateMountDir(Task):
description = 'Creating mountpoint for the bootstrap volume'
phase = phases.volume_mounting
def run(self, info):
2013-07-01 22:06:42 +02:00
import os
2013-06-27 23:26:29 +02:00
mount_dir = info.manifest.bootstrapper['mount_dir']
info.root = '{mount_dir}/{vol_id}'.format(mount_dir=mount_dir, vol_id=info.volume.id)
# Works recursively, fails if last part exists, which is exaclty what we want.
os.makedirs(info.root)
class MountVolume(Task):
description = 'Mounting the bootstrap volume'
phase = phases.volume_mounting
after = [CreateMountDir]
def run(self, info):
with open('/proc/mounts') as mounts:
for mount in mounts:
if info.root in mount:
2013-07-01 20:48:51 +02:00
msg = 'Something is already mounted at {root}'.format(root=info.root)
raise TaskError(msg)
2013-07-01 22:06:42 +02:00
command = ['mount', info.bootstrap_device['path'], info.root]
2013-07-01 22:21:47 +02:00
log_check_call(command)
2013-07-01 20:48:51 +02:00
class MountSpecials(Task):
description = 'Mounting special block devices'
phase = phases.os_installation
after = [Bootstrap]
def run(self, info):
2013-07-01 22:21:47 +02:00
log_check_call(['mount', '--bind', '/dev', '{root}/dev'.format(root=info.root)])
log_check_call(['chroot', info.root, 'mount', '-t', 'proc', 'none', '/proc'])
log_check_call(['chroot', info.root, 'mount', '-t', 'sysfs', 'none', '/sys'])
log_check_call(['chroot', info.root, 'mount', '-t', 'devpts', 'none', '/dev/pts'])
2013-07-01 20:48:51 +02:00
class UnmountSpecials(Task):
description = 'Unmunting special block devices'
phase = phases.volume_unmounting
def run(self, info):
2013-07-01 22:21:47 +02:00
log_check_call(['chroot', info.root, 'umount', '/dev/pts'])
log_check_call(['chroot', info.root, 'umount', '/sys'])
log_check_call(['chroot', info.root, 'umount', '/proc'])
log_check_call(['umount', '{root}/dev'.format(root=info.root)])
2013-07-01 20:48:51 +02:00
class UnmountVolume(Task):
description = 'Unmounting the bootstrap volume'
phase = phases.volume_unmounting
2013-07-01 20:48:51 +02:00
after = [UnmountSpecials]
def run(self, info):
2013-07-01 22:21:47 +02:00
log_check_call(['umount', info.root])
class DeleteMountDir(Task):
description = 'Deleting mountpoint for the bootstrap volume'
phase = phases.volume_unmounting
after = [UnmountVolume]
def run(self, info):
2013-07-01 22:06:42 +02:00
import os
os.rmdir(info.root)
del info.root