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

70 lines
2 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
class FormatVolume(Task):
description = 'Formatting the volume'
phase = phases.volume_preparation
def run(self, info):
import subprocess
from os import devnull
dev_path = info.bootstrap_device['path']
mkfs = '/sbin/mkfs.{fs}'.format(fs=info.manifest.volume['filesystem'])
with open(devnull, 'w') as dev_null:
subprocess.check_call([mkfs, dev_path], stdout=dev_null, stderr=dev_null)
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):
import subprocess
from os import devnull
dev_path = info.bootstrap_device['path']
# Disable the time based filesystem check
with open(devnull, 'w') as dev_null:
subprocess.check_call(['/sbin/tune2fs', '-i', '0', dev_path], stdout=dev_null, stderr=dev_null)
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):
import os
info.root = '{bs_dir}/{vol_id}'.format(bs_dir=info.manifest.bootstrapdir, 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 = 'Creating mountpoint for 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:
msg = 'Something is already mount at {root}'.format(root=info.root)
raise TaskError(msg)
import subprocess
from os import devnull
dev_path = info.bootstrap_device['path']
with open(devnull, 'w') as dev_null:
subprocess.check_call(['mount', dev_path, info.root], stdout=dev_null, stderr=dev_null)