Simplify adding tasks

There is now a get_standard_groups function
This commit is contained in:
Anders Ingemann 2014-05-03 12:22:51 +02:00
parent aad9bc69c4
commit c81045cc6e
6 changed files with 130 additions and 216 deletions

View file

@ -10,89 +10,130 @@ from tasks import cleanup
from tasks import apt from tasks import apt
from tasks import security from tasks import security
from tasks import locale from tasks import locale
from tasks import network
base_set = [workspace.CreateWorkspace,
bootstrap.AddRequiredCommands,
host.CheckExternalCommands,
bootstrap.Bootstrap,
workspace.DeleteWorkspace,
]
volume_set = [volume.Attach, def get_standard_groups(manifest):
volume.Detach, group = []
filesystem.AddRequiredCommands, group.extend(get_base_group(manifest))
filesystem.Format, group.extend(volume_group)
filesystem.FStab, if manifest.volume['partitions']['type'] != 'none':
] group.extend(partitioning_group)
if 'boot' in manifest.volume['partitions']:
group.extend(boot_partition_group)
group.extend(mounting_group)
group.extend(get_fs_specific_group(manifest))
group.extend(get_network_group(manifest))
group.extend(get_apt_group(manifest))
group.extend(locale_group)
group.extend(bootloader_group.get(manifest.system['bootloader'], []))
group.extend(cleanup_group)
return group
partitioning_set = [partitioning.AddRequiredCommands,
partitioning.PartitionVolume,
partitioning.MapPartitions,
partitioning.UnmapPartitions,
]
boot_partition_set = [filesystem.CreateBootMountDir, def get_base_group(manifest):
filesystem.MountBoot, group = [workspace.CreateWorkspace,
] bootstrap.AddRequiredCommands,
host.CheckExternalCommands,
bootstrap.Bootstrap,
workspace.DeleteWorkspace,
]
if manifest.bootstrapper.get('tarball', False):
group.append(bootstrap.MakeTarball)
return group
mounting_set = [filesystem.CreateMountDir,
filesystem.MountRoot, volume_group = [volume.Attach,
filesystem.MountSpecials, volume.Detach,
filesystem.UnmountRoot, filesystem.AddRequiredCommands,
filesystem.DeleteMountDir, filesystem.Format,
filesystem.FStab,
] ]
ssh_set = [security.DisableSSHPasswordAuthentication, partitioning_group = [partitioning.AddRequiredCommands,
security.DisableSSHDNSLookup, partitioning.PartitionVolume,
cleanup.ShredHostkeys, partitioning.MapPartitions,
] partitioning.UnmapPartitions,
]
boot_partition_group = [filesystem.CreateBootMountDir,
filesystem.MountBoot,
]
mounting_group = [filesystem.CreateMountDir,
filesystem.MountRoot,
filesystem.MountSpecials,
filesystem.UnmountRoot,
filesystem.DeleteMountDir,
]
ssh_group = [security.DisableSSHPasswordAuthentication,
security.DisableSSHDNSLookup,
cleanup.ShredHostkeys,
]
def get_apt_set(manifest): def get_network_group(manifest):
base = [apt.AddDefaultSources, group = [network.ConfigureNetworkIF,
apt.WriteSources, network.RemoveDNSInfo]
apt.DisableDaemonAutostart, if manifest.system.get('hostname', False):
apt.AptUpdate, group.append(network.SetHostname)
apt.AptUpgrade, else:
packages.InstallPackages, group.append(network.RemoveHostname)
apt.PurgeUnusedPackages, return group
apt.AptClean,
apt.EnableDaemonAutostart,
] def get_apt_group(manifest):
group = [apt.AddDefaultSources,
apt.WriteSources,
apt.DisableDaemonAutostart,
apt.AptUpdate,
apt.AptUpgrade,
packages.InstallPackages,
apt.PurgeUnusedPackages,
apt.AptClean,
apt.EnableDaemonAutostart,
]
if 'sources' in manifest.packages: if 'sources' in manifest.packages:
base.append(apt.AddManifestSources) group.append(apt.AddManifestSources)
if 'trusted-keys' in manifest.packages: if 'trusted-keys' in manifest.packages:
base.append(apt.InstallTrustedKeys) group.append(apt.InstallTrustedKeys)
if 'preferences' in manifest.packages: if 'preferences' in manifest.packages:
base.append(apt.AddManifestPreferences) group.append(apt.AddManifestPreferences)
base.append(apt.WritePreferences) group.append(apt.WritePreferences)
if 'install' in manifest.packages: if 'install' in manifest.packages:
base.append(packages.AddManifestPackages) group.append(packages.AddManifestPackages)
if manifest.packages.get('install_standard', False): if manifest.packages.get('install_standard', False):
base.append(packages.AddTaskselStandardPackages) group.append(packages.AddTaskselStandardPackages)
return base return group
locale_set = [locale.LocaleBootstrapPackage, locale_group = [locale.LocaleBootstrapPackage,
locale.GenerateLocale, locale.GenerateLocale,
locale.SetTimezone, locale.SetTimezone,
] ]
bootloader_set = {'grub': [boot.AddGrubPackage, boot.ConfigureGrub, boot.InstallGrub], bootloader_group = {'grub': [boot.AddGrubPackage, boot.ConfigureGrub, boot.InstallGrub],
'extlinux': [boot.AddExtlinuxPackage, boot.InstallExtLinux], 'extlinux': [boot.AddExtlinuxPackage, boot.InstallExtLinux],
} }
def get_fs_specific_set(partitions): def get_fs_specific_group(manifest):
task_set = {'ext2': [filesystem.TuneVolumeFS], partitions = manifest.volume['partitions']
'ext3': [filesystem.TuneVolumeFS], fs_specific_tasks = {'ext2': [filesystem.TuneVolumeFS],
'ext4': [filesystem.TuneVolumeFS], 'ext3': [filesystem.TuneVolumeFS],
'xfs': [filesystem.AddXFSProgs], 'ext4': [filesystem.TuneVolumeFS],
} 'xfs': [filesystem.AddXFSProgs],
tasks = set() }
group = set()
if 'boot' in partitions: if 'boot' in partitions:
tasks.update(task_set.get(partitions['boot']['filesystem'], [])) group.update(fs_specific_tasks.get(partitions['boot']['filesystem'], []))
if 'root' in partitions: if 'root' in partitions:
tasks.update(task_set.get(partitions['root']['filesystem'], [])) group.update(fs_specific_tasks.get(partitions['root']['filesystem'], []))
return tasks return list(group)
cleanup_group = [cleanup.ClearMOTD,
cleanup.CleanTMP,
]

View file

@ -28,44 +28,18 @@ def validate_manifest(data, validator, error):
def resolve_tasks(taskset, manifest): def resolve_tasks(taskset, manifest):
from bootstrapvz.common import task_groups from bootstrapvz.common import task_groups
taskset.update(task_groups.base_set) taskset.update(task_groups.get_standard_groups(manifest))
taskset.update(task_groups.volume_set)
taskset.update(task_groups.mounting_set)
taskset.update(task_groups.get_apt_set(manifest))
taskset.update(task_groups.locale_set)
taskset.update(task_groups.bootloader_set.get(manifest.system['bootloader']))
if manifest.volume['partitions']['type'] != 'none':
taskset.update(task_groups.partitioning_set)
if manifest.system.get('hostname', False):
taskset.add(network.SetHostname)
else:
taskset.add(network.RemoveHostname)
taskset.update([tasks.packages.DefaultPackages, taskset.update([tasks.packages.DefaultPackages,
loopback.Create, loopback.Create,
security.EnableShadowConfig, security.EnableShadowConfig,
network.RemoveDNSInfo,
network.ConfigureNetworkIF,
initd.AddSSHKeyGeneration, initd.AddSSHKeyGeneration,
initd.InstallInitScripts, initd.InstallInitScripts,
tasks.packages.Waagent, tasks.packages.Waagent,
tasks.boot.ConfigureGrub, tasks.boot.ConfigureGrub,
cleanup.ClearMOTD,
cleanup.CleanTMP,
tasks.image.ConvertToVhd, tasks.image.ConvertToVhd,
]) ])
if manifest.bootstrapper.get('tarball', False):
taskset.add(bootstrap.MakeTarball)
taskset.update(task_groups.get_fs_specific_set(manifest.volume['partitions']))
if 'boot' in manifest.volume['partitions']:
taskset.update(task_groups.boot_partition_set)
def resolve_rollback_tasks(taskset, manifest, counter_task): def resolve_rollback_tasks(taskset, manifest, counter_task):
counter_task(loopback.Create, volume.Delete) counter_task(loopback.Create, volume.Delete)

View file

@ -52,19 +52,8 @@ def validate_manifest(data, validator, error):
def resolve_tasks(taskset, manifest): def resolve_tasks(taskset, manifest):
from bootstrapvz.common import task_groups from bootstrapvz.common import task_groups
taskset.update(task_groups.base_set) taskset.update(task_groups.get_standard_groups(manifest))
taskset.update(task_groups.mounting_set) taskset.update(task_groups.ssh_group)
taskset.update(task_groups.get_apt_set(manifest))
taskset.update(task_groups.locale_set)
taskset.update(task_groups.ssh_set)
if manifest.volume['partitions']['type'] != 'none':
taskset.update(task_groups.partitioning_set)
if manifest.system.get('hostname', False):
taskset.add(network.SetHostname)
else:
taskset.add(network.RemoveHostname)
taskset.update([tasks.host.AddExternalCommands, taskset.update([tasks.host.AddExternalCommands,
tasks.packages.DefaultPackages, tasks.packages.DefaultPackages,
@ -75,8 +64,6 @@ def resolve_tasks(taskset, manifest):
boot.BlackListModules, boot.BlackListModules,
boot.DisableGetTTYs, boot.DisableGetTTYs,
security.EnableShadowConfig, security.EnableShadowConfig,
network.RemoveDNSInfo,
network.ConfigureNetworkIF,
tasks.network.EnableDHCPCDDNS, tasks.network.EnableDHCPCDDNS,
initd.AddExpandRoot, initd.AddExpandRoot,
initd.AddSSHKeyGeneration, initd.AddSSHKeyGeneration,
@ -84,8 +71,6 @@ def resolve_tasks(taskset, manifest):
tasks.initd.AddEC2InitScripts, tasks.initd.AddEC2InitScripts,
initd.InstallInitScripts, initd.InstallInitScripts,
initd.AdjustExpandRootScript, initd.AdjustExpandRootScript,
cleanup.ClearMOTD,
cleanup.CleanTMP,
tasks.ami.RegisterAMI, tasks.ami.RegisterAMI,
]) ])
@ -93,36 +78,30 @@ def resolve_tasks(taskset, manifest):
if manifest.system['bootloader'] == 'pvgrub': if manifest.system['bootloader'] == 'pvgrub':
taskset.add(boot.AddGrubPackage) taskset.add(boot.AddGrubPackage)
taskset.add(tasks.boot.ConfigurePVGrub) taskset.add(tasks.boot.ConfigurePVGrub)
else:
taskset.update(task_groups.bootloader_set.get(manifest.system['bootloader']))
backing_specific_tasks = {'ebs': [tasks.host.GetInstanceMetadata, if manifest.volume['backing'].lower() == 'ebs':
tasks.ebs.Create, taskset.update([tasks.host.GetInstanceMetadata,
tasks.ebs.Attach, tasks.ebs.Create,
filesystem.FStab, tasks.ebs.Snapshot,
tasks.ebs.Snapshot], ])
's3': [loopback.AddRequiredCommands, taskset.add(tasks.ebs.Attach)
tasks.host.SetRegion, taskset.discard(volume.Attach)
loopback.Create,
volume.Attach, if manifest.volume['backing'].lower() == 's3':
tasks.filesystem.S3FStab, taskset.update([loopback.AddRequiredCommands,
tasks.ami.BundleImage, tasks.host.SetRegion,
tasks.ami.UploadImage, loopback.Create,
tasks.ami.RemoveBundle]} tasks.filesystem.S3FStab,
taskset.update(backing_specific_tasks.get(manifest.volume['backing'].lower())) tasks.ami.BundleImage,
tasks.ami.UploadImage,
tasks.ami.RemoveBundle,
])
taskset.discard(filesystem.FStab)
taskset.update([filesystem.Format, taskset.update([filesystem.Format,
volume.Detach,
volume.Delete, volume.Delete,
]) ])
if manifest.bootstrapper.get('tarball', False):
taskset.add(bootstrap.MakeTarball)
taskset.update(task_groups.get_fs_specific_set(manifest.volume['partitions']))
if 'boot' in manifest.volume['partitions']:
taskset.update(task_groups.boot_partition_set)
def resolve_rollback_tasks(taskset, manifest, counter_task): def resolve_rollback_tasks(taskset, manifest, counter_task):
counter_task(tasks.ebs.Create, volume.Delete) counter_task(tasks.ebs.Create, volume.Delete)

View file

@ -4,14 +4,9 @@ import tasks.configuration
import tasks.image import tasks.image
import tasks.host import tasks.host
import tasks.packages import tasks.packages
from bootstrapvz.common.tasks import volume
from bootstrapvz.common.tasks import loopback from bootstrapvz.common.tasks import loopback
from bootstrapvz.common.tasks import partitioning
from bootstrapvz.common.tasks import filesystem
from bootstrapvz.common.tasks import security from bootstrapvz.common.tasks import security
from bootstrapvz.common.tasks import network
from bootstrapvz.common.tasks import initd from bootstrapvz.common.tasks import initd
from bootstrapvz.common.tasks import workspace
import bootstrapvz.plugins.cloud_init.tasks import bootstrapvz.plugins.cloud_init.tasks
@ -26,17 +21,7 @@ def validate_manifest(data, validator, error):
def resolve_tasks(tasklist, manifest): def resolve_tasks(tasklist, manifest):
import bootstrapvz.common.task_groups tasklist.update(bootstrapvz.common.task_groups.get_standard_groups(manifest))
tasklist.update(bootstrapvz.common.task_groups.base_set)
tasklist.update(bootstrapvz.common.task_groups.volume_set)
tasklist.update(bootstrapvz.common.task_groups.mounting_set)
tasklist.update(bootstrapvz.common.task_groups.get_apt_set(manifest))
tasklist.update(bootstrapvz.common.task_groups.locale_set)
tasklist.update(bootstrapvz.common.task_groups.bootloader_set.get(manifest.system['bootloader']))
if manifest.volume['partitions']['type'] != 'none':
tasklist.update(bootstrapvz.common.task_groups.partitioning_set)
tasklist.update([bootstrapvz.plugins.cloud_init.tasks.AddBackports, tasklist.update([bootstrapvz.plugins.cloud_init.tasks.AddBackports,
loopback.Create, loopback.Create,
@ -49,14 +34,9 @@ def resolve_tasks(tasklist, manifest):
tasks.configuration.GatherReleaseInformation, tasks.configuration.GatherReleaseInformation,
security.EnableShadowConfig, security.EnableShadowConfig,
network.RemoveDNSInfo,
network.RemoveHostname,
network.ConfigureNetworkIF,
tasks.host.DisableIPv6, tasks.host.DisableIPv6,
tasks.host.SetHostname,
tasks.boot.ConfigureGrub, tasks.boot.ConfigureGrub,
initd.AddSSHKeyGeneration, initd.AddSSHKeyGeneration,
initd.InstallInitScripts,
tasks.apt.CleanGoogleRepositoriesAndKeys, tasks.apt.CleanGoogleRepositoriesAndKeys,
loopback.MoveImage, loopback.MoveImage,
@ -68,11 +48,6 @@ def resolve_tasks(tasklist, manifest):
if 'gce_project' in manifest.image: if 'gce_project' in manifest.image:
tasklist.add(tasks.image.RegisterImage) tasklist.add(tasks.image.RegisterImage)
tasklist.update(bootstrapvz.common.task_groups.get_fs_specific_set(manifest.volume['partitions']))
if 'boot' in manifest.volume['partitions']:
tasklist.update(bootstrapvz.common.task_groups.boot_partition_set)
def resolve_rollback_tasks(tasklist, manifest, counter_task): def resolve_rollback_tasks(tasklist, manifest, counter_task):
counter_task(loopback.Create, volume.Delete) counter_task(loopback.Create, volume.Delete)

View file

@ -26,46 +26,20 @@ def validate_manifest(data, validator, error):
def resolve_tasks(taskset, manifest): def resolve_tasks(taskset, manifest):
from bootstrapvz.common import task_groups from bootstrapvz.common import task_groups
taskset.update(task_groups.base_set) taskset.update(task_groups.get_standard_groups(manifest))
taskset.update(task_groups.volume_set)
taskset.update(task_groups.mounting_set)
taskset.update(task_groups.get_apt_set(manifest))
taskset.update(task_groups.locale_set)
taskset.update(task_groups.bootloader_set.get(manifest.system['bootloader']))
if manifest.volume['partitions']['type'] != 'none':
taskset.update(task_groups.partitioning_set)
if manifest.system.get('hostname', False):
taskset.add(network.SetHostname)
else:
taskset.add(network.RemoveHostname)
taskset.update([tasks.packages.DefaultPackages, taskset.update([tasks.packages.DefaultPackages,
loopback.Create, loopback.Create,
security.EnableShadowConfig, security.EnableShadowConfig,
network.RemoveDNSInfo,
network.ConfigureNetworkIF,
initd.AddSSHKeyGeneration, initd.AddSSHKeyGeneration,
initd.InstallInitScripts, initd.InstallInitScripts,
cleanup.ClearMOTD,
cleanup.CleanTMP,
loopback.MoveImage, loopback.MoveImage,
]) ])
if manifest.bootstrapper.get('tarball', False):
taskset.add(bootstrap.MakeTarball)
if manifest.bootstrapper.get('virtio', []): if manifest.bootstrapper.get('virtio', []):
from tasks import virtio from tasks import virtio
taskset.update([virtio.VirtIO]) taskset.update([virtio.VirtIO])
taskset.update(task_groups.get_fs_specific_set(manifest.volume['partitions']))
if 'boot' in manifest.volume['partitions']:
taskset.update(task_groups.boot_partition_set)
def resolve_rollback_tasks(taskset, manifest, counter_task): def resolve_rollback_tasks(taskset, manifest, counter_task):
counter_task(loopback.Create, volume.Delete) counter_task(loopback.Create, volume.Delete)

View file

@ -26,34 +26,13 @@ def validate_manifest(data, validator, error):
def resolve_tasks(taskset, manifest): def resolve_tasks(taskset, manifest):
from bootstrapvz.common import task_groups from bootstrapvz.common import task_groups
taskset.update(task_groups.base_set) taskset.update(task_groups.get_standard_groups(manifest))
taskset.update(task_groups.volume_set)
taskset.update(task_groups.mounting_set)
taskset.update(task_groups.get_apt_set(manifest))
taskset.update(task_groups.locale_set)
taskset.update(task_groups.bootloader_set.get(manifest.system['bootloader']))
if manifest.volume['partitions']['type'] != 'none':
taskset.update(task_groups.partitioning_set)
if manifest.system.get('hostname', False):
taskset.add(network.SetHostname)
else:
taskset.add(network.RemoveHostname)
taskset.update([tasks.packages.DefaultPackages, taskset.update([tasks.packages.DefaultPackages,
loopback.Create, loopback.Create,
security.EnableShadowConfig, security.EnableShadowConfig,
network.RemoveDNSInfo,
network.ConfigureNetworkIF,
initd.AddSSHKeyGeneration, initd.AddSSHKeyGeneration,
initd.InstallInitScripts, initd.InstallInitScripts,
cleanup.ClearMOTD,
cleanup.CleanTMP,
loopback.MoveImage, loopback.MoveImage,
]) ])
@ -64,14 +43,6 @@ def resolve_tasks(taskset, manifest):
guest_additions.InstallGuestAdditions, guest_additions.InstallGuestAdditions,
]) ])
if manifest.bootstrapper.get('tarball', False):
taskset.add(bootstrap.MakeTarball)
taskset.update(task_groups.get_fs_specific_set(manifest.volume['partitions']))
if 'boot' in manifest.volume['partitions']:
taskset.update(task_groups.boot_partition_set)
def resolve_rollback_tasks(taskset, manifest, counter_task): def resolve_rollback_tasks(taskset, manifest, counter_task):
counter_task(loopback.Create, volume.Delete) counter_task(loopback.Create, volume.Delete)