fix phases and their ordering

This commit is contained in:
Anders Ingemann 2013-06-23 22:12:29 +02:00
parent 2f9fa4e6f7
commit 88ebeadd25
10 changed files with 39 additions and 62 deletions

View file

@ -1,18 +1,15 @@
from functools import total_ordering
@total_ordering
class Phase(object): class Phase(object):
description = None def __init__(self, description):
self.description = description
def __init__(self): def pos(self):
pass
def __lt__(self, other):
from common.phases import order 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): def __cmp__(self, other):
return self == other return self.pos() - other.pos()
def __str__(self): def __str__(self):
return '{name}'.format(name=self.__class__.__name__) return '{name}'.format(name=self.__class__.__name__)

View file

@ -1,44 +1,24 @@
from base import Phase 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): order = [preparation
description = 'Initializing connections, fetching data etc.' ,volume_creation
,volume_preparation
class VolumeCreation(Phase): ,volume_mounting
description = 'Creating the volume to bootstrap onto' ,install_os
,modify_system
class VolumePreparation(Phase): ,clean_system
description = 'Formatting the bootstrap volume' ,unmount_volume
,register_image
class VolumeMounting(Phase): ,cleanup
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
] ]

View file

@ -6,7 +6,7 @@ from providers.ec2.tasks.host import CheckPackages
class AddSudoPackage(Task): class AddSudoPackage(Task):
description = 'Adding ``sudo\'\' to the image packages' description = 'Adding ``sudo\'\' to the image packages'
phase = phases.Preparation phase = phases.preparation
after = [ImagePackages] after = [ImagePackages]
before = [CheckPackages] before = [CheckPackages]

View file

@ -5,7 +5,7 @@ from providers.ec2.tasks.host import GetInfo
class PrintInfo(Task): class PrintInfo(Task):
description = 'Printing `info\' to the console' description = 'Printing `info\' to the console'
phase = phases.InstallOS phase = phases.install_os
after = [GetInfo] after = [GetInfo]
def run(self, info): def run(self, info):

View file

@ -3,10 +3,10 @@ from manifest import Manifest
def tasks(tasklist, manifest): def tasks(tasklist, manifest):
from tasks import packages from tasks import packages
from tasks import ec2 from tasks import connection
from tasks import host from tasks import host
from tasks import ebs from tasks import ebs
tasklist.add(packages.HostPackages(), packages.ImagePackages(), host.CheckPackages(), 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': if manifest.volume['backing'] is 'ebs':
tasklist.add(ebs.CreateVolume()) tasklist.add(ebs.CreateVolume())

View file

@ -1 +1 @@
__all__ = ['packages', 'ec2', 'host'] __all__ = ['packages', 'connection', 'host', 'ec2']

View file

@ -4,7 +4,7 @@ from common import phases
class GetCredentials(Task): class GetCredentials(Task):
description = 'Getting AWS credentials' description = 'Getting AWS credentials'
phase = phases.Preparation phase = phases.preparation
def run(self, info): def run(self, info):
super(GetCredentials, self).run(info) super(GetCredentials, self).run(info)
@ -30,7 +30,7 @@ class GetCredentials(Task):
class Connect(Task): class Connect(Task):
description = 'Connecting to EC2' description = 'Connecting to EC2'
phase = phases.Preparation phase = phases.preparation
after = [GetCredentials] after = [GetCredentials]
def run(self, info): def run(self, info):

View file

@ -4,7 +4,7 @@ from connection import Connect
class CreateVolume(Task): class CreateVolume(Task):
description = 'Creating an EBS volume for bootstrapping' description = 'Creating an EBS volume for bootstrapping'
phase = phases.VolumeCreation phase = phases.volume_creation
after = [Connect] after = [Connect]
def run(self, info): def run(self, info):

View file

@ -4,7 +4,7 @@ import packages
class CheckPackages(Task): class CheckPackages(Task):
description = 'Checking installed host packages' description = 'Checking installed host packages'
phase = phases.Preparation phase = phases.preparation
after = [packages.HostPackages, packages.ImagePackages] after = [packages.HostPackages, packages.ImagePackages]
def run(self, info): def run(self, info):
@ -21,7 +21,7 @@ class CheckPackages(Task):
class GetInfo(Task): class GetInfo(Task):
description = 'Retrieving instance metadata' description = 'Retrieving instance metadata'
phase = phases.Preparation phase = phases.preparation
def run(self, info): def run(self, info):
super(GetInfo, self).run(info) super(GetInfo, self).run(info)

View file

@ -4,7 +4,7 @@ from common import phases
class HostPackages(Task): class HostPackages(Task):
description = 'Determining required host packages' description = 'Determining required host packages'
phase = phases.Preparation phase = phases.preparation
def run(self, info): def run(self, info):
super(HostPackages, self).run(info) super(HostPackages, self).run(info)
@ -20,7 +20,7 @@ class HostPackages(Task):
class ImagePackages(Task): class ImagePackages(Task):
description = 'Determining required image packages' description = 'Determining required image packages'
phase = phases.Preparation phase = phases.preparation
def run(self, info): def run(self, info):
super(ImagePackages, self).run(info) super(ImagePackages, self).run(info)