2014-05-03 13:28:24 +02:00
|
|
|
from bootstrapvz.common import task_groups
|
2013-12-29 23:52:08 +01:00
|
|
|
import tasks.packages
|
|
|
|
import tasks.connection
|
|
|
|
import tasks.host
|
|
|
|
import tasks.ami
|
|
|
|
import tasks.ebs
|
|
|
|
import tasks.filesystem
|
|
|
|
import tasks.boot
|
|
|
|
import tasks.network
|
|
|
|
import tasks.initd
|
2014-03-23 23:12:07 +01:00
|
|
|
from bootstrapvz.common.tasks import volume
|
|
|
|
from bootstrapvz.common.tasks import filesystem
|
|
|
|
from bootstrapvz.common.tasks import boot
|
2014-12-31 14:14:43 +01:00
|
|
|
from bootstrapvz.common.tasks import grub
|
2014-03-23 23:12:07 +01:00
|
|
|
from bootstrapvz.common.tasks import initd
|
|
|
|
from bootstrapvz.common.tasks import loopback
|
2014-11-29 13:46:57 -08:00
|
|
|
from bootstrapvz.common.tasks import kernel
|
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
|
2013-12-29 23:52:08 +01:00
|
|
|
import logging
|
2013-07-01 20:56:38 +02:00
|
|
|
logging.getLogger('boto').setLevel(logging.INFO)
|
|
|
|
|
|
|
|
|
2014-01-05 14:03:04 +01:00
|
|
|
def validate_manifest(data, validator, error):
|
|
|
|
import os.path
|
2014-07-05 20:01:20 +02:00
|
|
|
validator(data, os.path.join(os.path.dirname(__file__), 'manifest-schema.yml'))
|
2014-01-05 14:03:04 +01:00
|
|
|
|
2014-03-23 23:12:07 +01:00
|
|
|
from bootstrapvz.common.bytes import Bytes
|
2014-01-05 14:03:04 +01:00
|
|
|
if data['volume']['backing'] == 'ebs':
|
2014-01-19 15:57:54 +01:00
|
|
|
volume_size = Bytes(0)
|
2014-01-05 14:03:04 +01:00
|
|
|
for key, partition in data['volume']['partitions'].iteritems():
|
|
|
|
if key != 'type':
|
2014-01-19 12:39:07 +01:00
|
|
|
volume_size += Bytes(partition['size'])
|
2015-01-02 15:11:36 +01:00
|
|
|
if int(volume_size % Bytes('1GiB')) != 0:
|
2014-01-19 12:39:07 +01:00
|
|
|
msg = ('The volume size must be a multiple of 1GiB when using EBS backing')
|
2014-01-05 14:03:04 +01:00
|
|
|
error(msg, ['volume', 'partitions'])
|
|
|
|
else:
|
2014-07-05 20:01:20 +02:00
|
|
|
validator(data, os.path.join(os.path.dirname(__file__), 'manifest-schema-s3.yml'))
|
2014-01-05 14:03:04 +01:00
|
|
|
|
2014-05-04 12:41:59 +02:00
|
|
|
bootloader = data['system']['bootloader']
|
2014-07-05 18:14:29 +02:00
|
|
|
virtualization = data['provider']['virtualization']
|
2014-05-04 13:24:29 +02:00
|
|
|
backing = data['volume']['backing']
|
2014-05-04 12:41:59 +02:00
|
|
|
partition_type = data['volume']['partitions']['type']
|
2014-11-29 13:46:57 -08:00
|
|
|
enhanced_networking = data['provider']['enhanced_networking'] if 'enhanced_networking' in data['provider'] else None
|
2014-05-04 12:41:59 +02:00
|
|
|
|
|
|
|
if virtualization == 'pvm' and bootloader != 'pvgrub':
|
|
|
|
error('Paravirtualized AMIs only support pvgrub as a bootloader', ['system', 'bootloader'])
|
|
|
|
|
|
|
|
if virtualization == 'hvm':
|
2014-05-04 13:24:29 +02:00
|
|
|
if backing != 'ebs':
|
|
|
|
error('HVM AMIs currently only work when they are EBS backed', ['volume', 'backing'])
|
2014-05-04 12:41:59 +02:00
|
|
|
if bootloader != 'extlinux':
|
2014-05-04 13:24:29 +02:00
|
|
|
error('HVM AMIs currently only work with extlinux as a bootloader', ['system', 'bootloader'])
|
2014-05-04 12:41:59 +02:00
|
|
|
if bootloader == 'extlinux' and partition_type not in ['none', 'msdos']:
|
2015-04-08 21:59:41 +02:00
|
|
|
error('HVM AMIs booted with extlinux currently work with unpartitioned or msdos partitioned volumes',
|
2014-05-04 13:24:29 +02:00
|
|
|
['volume', 'partitions', 'type'])
|
|
|
|
|
|
|
|
if backing == 's3':
|
|
|
|
if partition_type != 'none':
|
|
|
|
error('S3 backed AMIs currently only work with unpartitioned volumes', ['system', 'bootloader'])
|
2014-01-05 14:03:04 +01:00
|
|
|
|
2014-11-29 13:46:57 -08:00
|
|
|
if enhanced_networking == 'simple':
|
|
|
|
if virtualization != 'hvm':
|
|
|
|
error('Enhanced networking currently only works with HVM virtualization', ['provider', 'virtualization'])
|
|
|
|
|
2014-01-05 14:03:04 +01:00
|
|
|
|
2014-01-05 15:13:09 +01:00
|
|
|
def resolve_tasks(taskset, manifest):
|
2014-05-03 12:22:51 +02:00
|
|
|
taskset.update(task_groups.get_standard_groups(manifest))
|
|
|
|
taskset.update(task_groups.ssh_group)
|
2014-04-13 21:18:02 -03:00
|
|
|
|
2014-02-23 21:51:28 +01:00
|
|
|
taskset.update([tasks.host.AddExternalCommands,
|
2014-01-05 15:13:09 +01:00
|
|
|
tasks.packages.DefaultPackages,
|
|
|
|
tasks.connection.GetCredentials,
|
|
|
|
tasks.ami.AMIName,
|
|
|
|
tasks.connection.Connect,
|
|
|
|
|
|
|
|
boot.BlackListModules,
|
|
|
|
boot.DisableGetTTYs,
|
|
|
|
tasks.network.EnableDHCPCDDNS,
|
|
|
|
initd.AddExpandRoot,
|
|
|
|
initd.RemoveHWClock,
|
|
|
|
tasks.initd.AddEC2InitScripts,
|
|
|
|
initd.InstallInitScripts,
|
|
|
|
|
|
|
|
tasks.ami.RegisterAMI,
|
|
|
|
])
|
2013-10-09 00:09:34 +02:00
|
|
|
|
2014-05-04 11:48:03 +02:00
|
|
|
if manifest.volume['partitions']['type'] != 'none':
|
|
|
|
taskset.add(initd.AdjustExpandRootScript)
|
|
|
|
|
2013-12-30 12:14:43 +01:00
|
|
|
if manifest.system['bootloader'] == 'pvgrub':
|
2014-12-31 14:14:43 +01:00
|
|
|
taskset.add(grub.AddGrubPackage)
|
2014-01-05 15:13:09 +01:00
|
|
|
taskset.add(tasks.boot.ConfigurePVGrub)
|
2014-05-03 12:22:51 +02:00
|
|
|
|
|
|
|
if manifest.volume['backing'].lower() == 'ebs':
|
|
|
|
taskset.update([tasks.host.GetInstanceMetadata,
|
|
|
|
tasks.ebs.Create,
|
|
|
|
tasks.ebs.Snapshot,
|
|
|
|
])
|
|
|
|
taskset.add(tasks.ebs.Attach)
|
|
|
|
taskset.discard(volume.Attach)
|
|
|
|
|
|
|
|
if manifest.volume['backing'].lower() == 's3':
|
|
|
|
taskset.update([loopback.AddRequiredCommands,
|
|
|
|
tasks.host.SetRegion,
|
|
|
|
loopback.Create,
|
|
|
|
tasks.filesystem.S3FStab,
|
|
|
|
tasks.ami.BundleImage,
|
|
|
|
tasks.ami.UploadImage,
|
|
|
|
tasks.ami.RemoveBundle,
|
|
|
|
])
|
|
|
|
taskset.discard(filesystem.FStab)
|
|
|
|
|
2014-11-29 13:46:57 -08:00
|
|
|
if 'enhanced_networking' in manifest.provider and manifest.provider['enhanced_networking'] == 'simple':
|
|
|
|
taskset.update([kernel.AddDKMSPackages,
|
|
|
|
tasks.network.InstallEnhancedNetworking,
|
|
|
|
kernel.UpdateInitramfs])
|
|
|
|
|
2014-01-05 15:13:09 +01:00
|
|
|
taskset.update([filesystem.Format,
|
|
|
|
volume.Delete,
|
|
|
|
])
|
2013-10-09 00:09:34 +02:00
|
|
|
|
2013-06-26 23:40:42 +02:00
|
|
|
|
2014-05-03 13:28:24 +02:00
|
|
|
def resolve_rollback_tasks(taskset, manifest, completed, counter_task):
|
|
|
|
taskset.update(task_groups.get_standard_rollback_tasks(completed))
|
2014-05-10 17:24:50 +02:00
|
|
|
counter_task(taskset, tasks.ebs.Create, volume.Delete)
|
|
|
|
counter_task(taskset, tasks.ebs.Attach, volume.Detach)
|
|
|
|
counter_task(taskset, tasks.ami.BundleImage, tasks.ami.RemoveBundle)
|