2013-05-16 08:00:28 +02:00
|
|
|
from manifest import Manifest
|
2013-07-01 20:56:38 +02:00
|
|
|
import logging
|
2013-06-26 23:40:42 +02:00
|
|
|
from tasks import packages
|
2013-08-10 19:01:54 +02:00
|
|
|
from common.tasks import packages as common_packages
|
2013-06-26 23:40:42 +02:00
|
|
|
from tasks import connection
|
|
|
|
from tasks import host
|
2013-08-10 17:20:10 +02:00
|
|
|
from common.tasks import host as common_host
|
2013-07-07 20:28:24 +02:00
|
|
|
from tasks import ami
|
2013-09-15 13:19:45 +02:00
|
|
|
from common.tasks import volume
|
2013-06-26 23:40:42 +02:00
|
|
|
from tasks import ebs
|
2013-08-10 16:38:45 +02:00
|
|
|
from common.tasks import loopback
|
|
|
|
from common.tasks import filesystem
|
2013-08-10 16:22:16 +02:00
|
|
|
from common.tasks import bootstrap
|
2013-08-10 16:27:43 +02:00
|
|
|
from common.tasks import locale
|
2013-08-10 16:15:49 +02:00
|
|
|
from common.tasks import apt
|
2013-07-01 23:15:49 +02:00
|
|
|
from tasks import boot
|
2013-08-10 16:18:48 +02:00
|
|
|
from common.tasks import boot as common_boot
|
2013-08-10 17:12:58 +02:00
|
|
|
from common.tasks import security
|
2013-09-22 15:41:43 +02:00
|
|
|
from tasks import network
|
|
|
|
from common.tasks import network as common_network
|
2013-07-07 14:58:03 +02:00
|
|
|
from tasks import initd
|
2013-08-10 16:51:42 +02:00
|
|
|
from common.tasks import initd as common_initd
|
2013-08-10 16:24:12 +02:00
|
|
|
from common.tasks import cleanup
|
2013-05-16 08:00:28 +02:00
|
|
|
|
|
|
|
|
2013-07-01 20:56:38 +02:00
|
|
|
def initialize():
|
|
|
|
# Regardless of of loglevel, we don't want boto debug stuff, it's very noisy
|
|
|
|
logging.getLogger('boto').setLevel(logging.INFO)
|
|
|
|
|
|
|
|
|
2013-06-23 15:26:08 +02:00
|
|
|
def tasks(tasklist, manifest):
|
2013-07-01 22:38:33 +02:00
|
|
|
tasklist.add(packages.HostPackages(),
|
2013-08-10 19:01:54 +02:00
|
|
|
common_packages.HostPackages(),
|
2013-07-01 22:38:33 +02:00
|
|
|
packages.ImagePackages(),
|
2013-08-10 19:01:54 +02:00
|
|
|
common_packages.ImagePackages(),
|
2013-08-10 17:20:10 +02:00
|
|
|
common_host.CheckPackages(),
|
2013-07-01 22:38:33 +02:00
|
|
|
connection.GetCredentials(),
|
|
|
|
host.GetInfo(),
|
2013-07-07 20:28:24 +02:00
|
|
|
ami.AMIName(),
|
2013-07-13 15:10:04 +02:00
|
|
|
connection.Connect(),
|
|
|
|
|
|
|
|
filesystem.FormatVolume(),
|
|
|
|
filesystem.CreateMountDir(),
|
|
|
|
filesystem.MountVolume(),
|
|
|
|
|
|
|
|
bootstrap.Bootstrap(),
|
2013-07-01 22:38:33 +02:00
|
|
|
filesystem.MountSpecials(),
|
2013-07-01 22:52:54 +02:00
|
|
|
locale.GenerateLocale(),
|
|
|
|
locale.SetTimezone(),
|
2013-07-07 17:33:19 +02:00
|
|
|
apt.DisableDaemonAutostart(),
|
2013-07-01 22:52:54 +02:00
|
|
|
apt.AptSources(),
|
2013-07-01 23:15:49 +02:00
|
|
|
apt.AptUpgrade(),
|
2013-07-01 23:25:11 +02:00
|
|
|
boot.ConfigureGrub(),
|
2013-09-15 13:19:45 +02:00
|
|
|
filesystem.FStab(),
|
2013-08-10 16:18:48 +02:00
|
|
|
common_boot.BlackListModules(),
|
|
|
|
common_boot.DisableGetTTYs(),
|
2013-07-01 23:41:22 +02:00
|
|
|
security.EnableShadowConfig(),
|
|
|
|
security.DisableSSHPasswordAuthentication(),
|
2013-07-01 23:54:18 +02:00
|
|
|
security.DisableSSHDNSLookup(),
|
2013-09-22 15:41:43 +02:00
|
|
|
common_network.RemoveDNSInfo(),
|
|
|
|
common_network.ConfigureNetworkIF(),
|
|
|
|
network.EnableDHCPCDDNS(),
|
2013-08-10 16:51:42 +02:00
|
|
|
common_initd.ResolveInitScripts(),
|
|
|
|
initd.AddEC2InitScripts(),
|
|
|
|
common_initd.InstallInitScripts(),
|
2013-07-07 16:59:12 +02:00
|
|
|
cleanup.ClearMOTD(),
|
|
|
|
cleanup.ShredHostkeys(),
|
2013-07-07 18:03:49 +02:00
|
|
|
cleanup.CleanTMP(),
|
|
|
|
apt.PurgeUnusedPackages(),
|
|
|
|
apt.AptClean(),
|
2013-07-07 17:55:21 +02:00
|
|
|
apt.EnableDaemonAutostart(),
|
|
|
|
filesystem.UnmountSpecials(),
|
2013-08-10 17:52:24 +02:00
|
|
|
|
2013-07-07 17:55:21 +02:00
|
|
|
filesystem.UnmountVolume(),
|
2013-07-14 23:16:37 +02:00
|
|
|
filesystem.DeleteMountDir(),
|
|
|
|
ami.RegisterAMI())
|
2013-07-13 15:10:04 +02:00
|
|
|
|
2013-09-15 16:59:56 +02:00
|
|
|
if manifest.bootstrapper.get('tarball', False):
|
2013-07-13 15:10:04 +02:00
|
|
|
tasklist.add(bootstrap.MakeTarball())
|
|
|
|
|
|
|
|
backing_specific_tasks = {'ebs': [ebs.Create(),
|
2013-09-15 13:19:45 +02:00
|
|
|
volume.Attach(),
|
|
|
|
volume.Detach(),
|
2013-07-13 15:10:04 +02:00
|
|
|
ebs.Snapshot(),
|
2013-09-15 13:19:45 +02:00
|
|
|
volume.Delete()],
|
2013-07-13 15:10:04 +02:00
|
|
|
's3': [loopback.Create(),
|
2013-09-15 13:19:45 +02:00
|
|
|
volume.Attach(),
|
|
|
|
volume.Detach(),
|
2013-07-14 23:16:37 +02:00
|
|
|
ami.BundleImage(),
|
|
|
|
ami.UploadImage(),
|
2013-09-15 13:19:45 +02:00
|
|
|
volume.Delete(),
|
2013-07-14 23:16:37 +02:00
|
|
|
ami.RemoveBundle()]}
|
2013-07-13 15:10:04 +02:00
|
|
|
tasklist.add(*backing_specific_tasks.get(manifest.volume['backing'].lower()))
|
|
|
|
|
|
|
|
filesystem_specific_tasks = {'xfs': [filesystem.AddXFSProgs()],
|
|
|
|
'ext2': [filesystem.TuneVolumeFS()],
|
|
|
|
'ext3': [filesystem.TuneVolumeFS()],
|
|
|
|
'ext4': [filesystem.TuneVolumeFS()]}
|
|
|
|
tasklist.add(*filesystem_specific_tasks.get(manifest.volume['filesystem'].lower()))
|
2013-06-26 23:40:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
def rollback_tasks(tasklist, tasks_completed, manifest):
|
|
|
|
completed = [type(task) for task in tasks_completed]
|
2013-06-27 22:21:43 +02:00
|
|
|
|
|
|
|
def counter_task(task, counter):
|
|
|
|
if task in completed and counter not in completed:
|
|
|
|
tasklist.add(counter())
|
|
|
|
|
2013-06-26 23:40:42 +02:00
|
|
|
if manifest.volume['backing'].lower() == 'ebs':
|
2013-09-15 13:19:45 +02:00
|
|
|
counter_task(ebs.Create, volume.Delete)
|
|
|
|
counter_task(volume.Attach, volume.Detach)
|
2013-07-14 23:16:37 +02:00
|
|
|
if manifest.volume['backing'].lower() == 's3':
|
2013-09-15 13:19:45 +02:00
|
|
|
counter_task(loopback.Create, volume.Delete)
|
|
|
|
counter_task(volume.Attach, volume.Detach)
|
2013-06-27 22:21:43 +02:00
|
|
|
counter_task(filesystem.CreateMountDir, filesystem.DeleteMountDir)
|
|
|
|
counter_task(filesystem.MountVolume, filesystem.UnmountVolume)
|
2013-07-01 20:48:51 +02:00
|
|
|
counter_task(filesystem.MountSpecials, filesystem.UnmountSpecials)
|