From 88ebeadd25fb866adfeddcd46b97e751955ee417 Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Sun, 23 Jun 2013 22:12:29 +0200 Subject: [PATCH] fix phases and their ordering --- base/phase.py | 17 +++---- common/phases.py | 60 +++++++++---------------- plugins/admin_user/adminuser.py | 2 +- plugins/build_metadata/buildmetadata.py | 2 +- providers/ec2/__init__.py | 4 +- providers/ec2/tasks/__init__.py | 2 +- providers/ec2/tasks/connection.py | 4 +- providers/ec2/tasks/ebs.py | 2 +- providers/ec2/tasks/host.py | 4 +- providers/ec2/tasks/packages.py | 4 +- 10 files changed, 39 insertions(+), 62 deletions(-) diff --git a/base/phase.py b/base/phase.py index 89f3ac5..75a2dff 100644 --- a/base/phase.py +++ b/base/phase.py @@ -1,18 +1,15 @@ -from functools import total_ordering -@total_ordering + class Phase(object): - description = None + def __init__(self, description): + self.description = description - def __init__(self): - pass - - def __lt__(self, other): + def pos(self): from common.phases import order - return order.index(self) < order.index(other) + return (i for i, phase in enumerate(order) if phase is self).next() - def __eq__(self, other): - return self == other + def __cmp__(self, other): + return self.pos() - other.pos() def __str__(self): return '{name}'.format(name=self.__class__.__name__) diff --git a/common/phases.py b/common/phases.py index 7809385..f274c11 100644 --- a/common/phases.py +++ b/common/phases.py @@ -1,44 +1,24 @@ from base import Phase +preparation = Phase('Initializing connections, fetching data etc.') +volume_creation = Phase('Creating the volume to bootstrap onto') +volume_preparation = Phase('Formatting the bootstrap volume') +volume_mounting = Phase('Mounting bootstrap volume') +install_os = Phase('Installing the operating system') +modify_system = Phase('Installing software, modifying configuration files etc.') +clean_system = Phase('Removing sensitive data, temporary files and other leftovers') +unmount_volume = Phase('Unmounting the bootstrap volume') +register_image = Phase('Uploading/Registering with the provider') +cleanup = Phase('Removing temporary files') -class Preparation(Phase): - description = 'Initializing connections, fetching data etc.' - -class VolumeCreation(Phase): - description = 'Creating the volume to bootstrap onto' - -class VolumePreparation(Phase): - description = 'Formatting the bootstrap volume' - -class VolumeMounting(Phase): - description = 'Mounting bootstrap volume' - -class InstallOS(Phase): - description = 'Installing the operating system' - -class ModifySystem(Phase): - description = 'Installing software, modifying configuration files etc.' - -class CleanSystem(Phase): - description = 'Removing sensitive data, temporary files and other leftovers' - -class UnmountVolume(Phase): - description = 'Unmounting the bootstrap volume' - -class RegisterImage(Phase): - description = 'Uploading/Registering with the provider' - -class Cleanup(Phase): - description = 'Removing temporary files' - -order = [Preparation, - VolumeCreation, - VolumePreparation, - VolumeMounting, - InstallOS, - ModifySystem, - CleanSystem, - UnmountVolume, - RegisterImage, - Cleanup +order = [preparation + ,volume_creation + ,volume_preparation + ,volume_mounting + ,install_os + ,modify_system + ,clean_system + ,unmount_volume + ,register_image + ,cleanup ] diff --git a/plugins/admin_user/adminuser.py b/plugins/admin_user/adminuser.py index 9ed33d8..bab52af 100644 --- a/plugins/admin_user/adminuser.py +++ b/plugins/admin_user/adminuser.py @@ -6,7 +6,7 @@ from providers.ec2.tasks.host import CheckPackages class AddSudoPackage(Task): description = 'Adding ``sudo\'\' to the image packages' - phase = phases.Preparation + phase = phases.preparation after = [ImagePackages] before = [CheckPackages] diff --git a/plugins/build_metadata/buildmetadata.py b/plugins/build_metadata/buildmetadata.py index 43f1438..9fec61a 100644 --- a/plugins/build_metadata/buildmetadata.py +++ b/plugins/build_metadata/buildmetadata.py @@ -5,7 +5,7 @@ from providers.ec2.tasks.host import GetInfo class PrintInfo(Task): description = 'Printing `info\' to the console' - phase = phases.InstallOS + phase = phases.install_os after = [GetInfo] def run(self, info): diff --git a/providers/ec2/__init__.py b/providers/ec2/__init__.py index ade5422..6c2222b 100644 --- a/providers/ec2/__init__.py +++ b/providers/ec2/__init__.py @@ -3,10 +3,10 @@ from manifest import Manifest def tasks(tasklist, manifest): from tasks import packages - from tasks import ec2 + from tasks import connection from tasks import host from tasks import ebs tasklist.add(packages.HostPackages(), packages.ImagePackages(), host.CheckPackages(), - ec2.GetCredentials(), host.GetInfo(), ec2.Connect()) + connection.GetCredentials(), host.GetInfo(), connection.Connect()) if manifest.volume['backing'] is 'ebs': tasklist.add(ebs.CreateVolume()) diff --git a/providers/ec2/tasks/__init__.py b/providers/ec2/tasks/__init__.py index 0b293e0..873a99d 100644 --- a/providers/ec2/tasks/__init__.py +++ b/providers/ec2/tasks/__init__.py @@ -1 +1 @@ -__all__ = ['packages', 'ec2', 'host'] +__all__ = ['packages', 'connection', 'host', 'ec2'] diff --git a/providers/ec2/tasks/connection.py b/providers/ec2/tasks/connection.py index 66cc1e1..f17b171 100644 --- a/providers/ec2/tasks/connection.py +++ b/providers/ec2/tasks/connection.py @@ -4,7 +4,7 @@ from common import phases class GetCredentials(Task): description = 'Getting AWS credentials' - phase = phases.Preparation + phase = phases.preparation def run(self, info): super(GetCredentials, self).run(info) @@ -30,7 +30,7 @@ class GetCredentials(Task): class Connect(Task): description = 'Connecting to EC2' - phase = phases.Preparation + phase = phases.preparation after = [GetCredentials] def run(self, info): diff --git a/providers/ec2/tasks/ebs.py b/providers/ec2/tasks/ebs.py index 0e2a1af..543c3a1 100644 --- a/providers/ec2/tasks/ebs.py +++ b/providers/ec2/tasks/ebs.py @@ -4,7 +4,7 @@ from connection import Connect class CreateVolume(Task): description = 'Creating an EBS volume for bootstrapping' - phase = phases.VolumeCreation + phase = phases.volume_creation after = [Connect] def run(self, info): diff --git a/providers/ec2/tasks/host.py b/providers/ec2/tasks/host.py index e5aa6f4..11f1a31 100644 --- a/providers/ec2/tasks/host.py +++ b/providers/ec2/tasks/host.py @@ -4,7 +4,7 @@ import packages class CheckPackages(Task): description = 'Checking installed host packages' - phase = phases.Preparation + phase = phases.preparation after = [packages.HostPackages, packages.ImagePackages] def run(self, info): @@ -21,7 +21,7 @@ class CheckPackages(Task): class GetInfo(Task): description = 'Retrieving instance metadata' - phase = phases.Preparation + phase = phases.preparation def run(self, info): super(GetInfo, self).run(info) diff --git a/providers/ec2/tasks/packages.py b/providers/ec2/tasks/packages.py index 7e59b75..3e449f3 100644 --- a/providers/ec2/tasks/packages.py +++ b/providers/ec2/tasks/packages.py @@ -4,7 +4,7 @@ from common import phases class HostPackages(Task): description = 'Determining required host packages' - phase = phases.Preparation + phase = phases.preparation def run(self, info): super(HostPackages, self).run(info) @@ -20,7 +20,7 @@ class HostPackages(Task): class ImagePackages(Task): description = 'Determining required image packages' - phase = phases.Preparation + phase = phases.preparation def run(self, info): super(ImagePackages, self).run(info)