diff --git a/providers/ec2/__init__.py b/providers/ec2/__init__.py index 67dd990..6f14570 100644 --- a/providers/ec2/__init__.py +++ b/providers/ec2/__init__.py @@ -3,6 +3,7 @@ from tasks import packages from tasks import connection from tasks import host from tasks import ebs +from tasks import filesystem def tasks(tasklist, manifest): @@ -10,6 +11,12 @@ def tasks(tasklist, manifest): connection.GetCredentials(), host.GetInfo(), connection.Connect()) if manifest.volume['backing'].lower() == 'ebs': tasklist.add(ebs.CreateVolume(), ebs.AttachVolume()) + tasklist.add(filesystem.FormatVolume()) + if manifest.volume['filesystem'].lower() == 'xfs': + tasklist.add(filesystem.AddXFSProgs()) + import re + if re.search('ext.', manifest.volume['filesystem'].lower()): + tasklist.add(filesystem.TuneVolumeFS()) from common.tasks import TriggerRollback tasklist.add(TriggerRollback()) diff --git a/providers/ec2/manifest-schema.json b/providers/ec2/manifest-schema.json index d222b62..9169060 100644 --- a/providers/ec2/manifest-schema.json +++ b/providers/ec2/manifest-schema.json @@ -12,9 +12,13 @@ "backing": { "type": "string", "enum": ["ebs", "s3"] + }, + "filesystem": { + "type": "string", + "enum": ["ext2", "ext3", "ext4", "xfs"] } }, - "required": ["backing"] + "required": ["backing", "filesystem"] } }, "required": ["bootstrapdir", "volume"] diff --git a/providers/ec2/tasks/filesystem.py b/providers/ec2/tasks/filesystem.py new file mode 100644 index 0000000..f65d73d --- /dev/null +++ b/providers/ec2/tasks/filesystem.py @@ -0,0 +1,46 @@ +from base import Task +from common import phases +from common.exceptions import TaskError + + +class FormatVolume(Task): + description = 'Formatting the volume' + phase = phases.volume_preparation + after = [] + + 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']) + try: + with open(devnull, 'w') as dev_null: + subprocess.check_call([mkfs, dev_path], stdout=dev_null, stderr=dev_null) + except subprocess.CalledProcessError: + raise TaskError('Unable to format the bootstrap device') + + +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'] + try: + with open(devnull, 'w') as dev_null: + subprocess.check_call(['/sbin/tune2fs', '-i', '0', dev_path], stdout=dev_null, stderr=dev_null) + except subprocess.CalledProcessError: + raise TaskError('Unable to disable the time based check interval for the bootstrap volume') + + +class AddXFSProgs(Task): + description = 'Adding `xfsprogs\' to the image packages' + phase = phases.preparation + after = [] + + def run(self, info): + include, exclude = info.img_packages + include.add('xfsprogs')