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):
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__)

View file

@ -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
]

View file

@ -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]

View file

@ -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):

View file

@ -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())

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):
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):

View file

@ -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):

View file

@ -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)

View file

@ -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)