2014-03-23 23:12:07 +01:00
|
|
|
from tasks import workspace
|
|
|
|
from tasks import packages
|
|
|
|
from tasks import host
|
2014-12-31 14:14:43 +01:00
|
|
|
from tasks import grub
|
|
|
|
from tasks import extlinux
|
2014-03-23 23:12:07 +01:00
|
|
|
from tasks import bootstrap
|
|
|
|
from tasks import volume
|
2014-05-03 13:28:24 +02:00
|
|
|
from tasks import loopback
|
2014-03-23 23:12:07 +01:00
|
|
|
from tasks import filesystem
|
|
|
|
from tasks import partitioning
|
|
|
|
from tasks import cleanup
|
|
|
|
from tasks import apt
|
|
|
|
from tasks import security
|
|
|
|
from tasks import locale
|
2014-05-03 12:22:51 +02:00
|
|
|
from tasks import network
|
2014-05-03 12:56:40 +02:00
|
|
|
from tasks import initd
|
|
|
|
from tasks import ssh
|
2015-01-16 01:53:35 +01:00
|
|
|
from tasks import kernel
|
2013-09-22 20:46:25 +02:00
|
|
|
|
|
|
|
|
2014-05-03 12:22:51 +02:00
|
|
|
def get_standard_groups(manifest):
|
|
|
|
group = []
|
|
|
|
group.extend(get_base_group(manifest))
|
|
|
|
group.extend(volume_group)
|
|
|
|
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)
|
2015-01-16 01:53:35 +01:00
|
|
|
group.extend(kernel_group)
|
2014-05-03 12:22:51 +02:00
|
|
|
group.extend(get_fs_specific_group(manifest))
|
|
|
|
group.extend(get_network_group(manifest))
|
|
|
|
group.extend(get_apt_group(manifest))
|
2014-05-03 13:11:32 +02:00
|
|
|
group.extend(security_group)
|
2014-05-03 12:22:51 +02:00
|
|
|
group.extend(locale_group)
|
2014-07-09 21:20:26 +02:00
|
|
|
group.extend(get_bootloader_group(manifest))
|
2014-05-03 12:22:51 +02:00
|
|
|
group.extend(cleanup_group)
|
|
|
|
return group
|
|
|
|
|
|
|
|
|
|
|
|
def get_base_group(manifest):
|
|
|
|
group = [workspace.CreateWorkspace,
|
|
|
|
bootstrap.AddRequiredCommands,
|
|
|
|
host.CheckExternalCommands,
|
|
|
|
bootstrap.Bootstrap,
|
|
|
|
workspace.DeleteWorkspace,
|
|
|
|
]
|
|
|
|
if manifest.bootstrapper.get('tarball', False):
|
|
|
|
group.append(bootstrap.MakeTarball)
|
2014-05-04 21:50:32 +05:30
|
|
|
if manifest.bootstrapper.get('include_packages', False):
|
|
|
|
group.append(bootstrap.IncludePackagesInBootstrap)
|
|
|
|
if manifest.bootstrapper.get('exclude_packages', False):
|
|
|
|
group.append(bootstrap.ExcludePackagesInBootstrap)
|
2014-05-03 12:22:51 +02:00
|
|
|
return group
|
|
|
|
|
|
|
|
|
|
|
|
volume_group = [volume.Attach,
|
|
|
|
volume.Detach,
|
|
|
|
filesystem.AddRequiredCommands,
|
|
|
|
filesystem.Format,
|
|
|
|
filesystem.FStab,
|
2013-09-22 20:46:25 +02:00
|
|
|
]
|
|
|
|
|
2014-05-03 12:22:51 +02:00
|
|
|
partitioning_group = [partitioning.AddRequiredCommands,
|
|
|
|
partitioning.PartitionVolume,
|
|
|
|
partitioning.MapPartitions,
|
|
|
|
partitioning.UnmapPartitions,
|
|
|
|
]
|
|
|
|
|
|
|
|
boot_partition_group = [filesystem.CreateBootMountDir,
|
|
|
|
filesystem.MountBoot,
|
|
|
|
]
|
|
|
|
|
|
|
|
mounting_group = [filesystem.CreateMountDir,
|
|
|
|
filesystem.MountRoot,
|
|
|
|
filesystem.MountSpecials,
|
|
|
|
filesystem.UnmountRoot,
|
|
|
|
filesystem.DeleteMountDir,
|
|
|
|
]
|
|
|
|
|
2015-01-16 01:53:35 +01:00
|
|
|
kernel_group = [kernel.DetermineKernelVersion,
|
|
|
|
]
|
|
|
|
|
2014-05-03 12:56:40 +02:00
|
|
|
ssh_group = [ssh.AddOpenSSHPackage,
|
|
|
|
ssh.DisableSSHPasswordAuthentication,
|
|
|
|
ssh.DisableSSHDNSLookup,
|
|
|
|
ssh.AddSSHKeyGeneration,
|
|
|
|
initd.InstallInitScripts,
|
|
|
|
ssh.ShredHostkeys,
|
2014-05-03 12:22:51 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def get_network_group(manifest):
|
|
|
|
group = [network.ConfigureNetworkIF,
|
|
|
|
network.RemoveDNSInfo]
|
|
|
|
if manifest.system.get('hostname', False):
|
|
|
|
group.append(network.SetHostname)
|
|
|
|
else:
|
|
|
|
group.append(network.RemoveHostname)
|
|
|
|
return group
|
|
|
|
|
|
|
|
|
|
|
|
def get_apt_group(manifest):
|
|
|
|
group = [apt.AddDefaultSources,
|
|
|
|
apt.WriteSources,
|
|
|
|
apt.DisableDaemonAutostart,
|
|
|
|
apt.AptUpdate,
|
|
|
|
apt.AptUpgrade,
|
|
|
|
packages.InstallPackages,
|
|
|
|
apt.PurgeUnusedPackages,
|
|
|
|
apt.AptClean,
|
|
|
|
apt.EnableDaemonAutostart,
|
|
|
|
]
|
2014-01-09 17:21:29 +01:00
|
|
|
if 'sources' in manifest.packages:
|
2014-05-03 12:22:51 +02:00
|
|
|
group.append(apt.AddManifestSources)
|
2014-01-12 12:46:59 +01:00
|
|
|
if 'trusted-keys' in manifest.packages:
|
2014-05-03 12:22:51 +02:00
|
|
|
group.append(apt.InstallTrustedKeys)
|
2014-04-04 10:16:19 +02:00
|
|
|
if 'preferences' in manifest.packages:
|
2014-05-03 12:22:51 +02:00
|
|
|
group.append(apt.AddManifestPreferences)
|
|
|
|
group.append(apt.WritePreferences)
|
2014-01-12 12:46:59 +01:00
|
|
|
if 'install' in manifest.packages:
|
2014-05-03 12:22:51 +02:00
|
|
|
group.append(packages.AddManifestPackages)
|
2014-04-01 13:31:07 -03:00
|
|
|
if manifest.packages.get('install_standard', False):
|
2014-05-03 12:22:51 +02:00
|
|
|
group.append(packages.AddTaskselStandardPackages)
|
|
|
|
return group
|
2014-01-09 17:21:29 +01:00
|
|
|
|
2014-05-03 13:11:32 +02:00
|
|
|
security_group = [security.EnableShadowConfig]
|
2013-09-22 20:46:25 +02:00
|
|
|
|
2014-05-03 12:22:51 +02:00
|
|
|
locale_group = [locale.LocaleBootstrapPackage,
|
|
|
|
locale.GenerateLocale,
|
|
|
|
locale.SetTimezone,
|
|
|
|
]
|
2013-09-22 20:46:25 +02:00
|
|
|
|
2013-10-06 01:42:32 +02:00
|
|
|
|
2014-07-09 21:20:26 +02:00
|
|
|
def get_bootloader_group(manifest):
|
|
|
|
group = []
|
|
|
|
if manifest.system['bootloader'] == 'grub':
|
2014-12-31 14:14:43 +01:00
|
|
|
group.extend([grub.AddGrubPackage,
|
|
|
|
grub.ConfigureGrub])
|
2014-07-09 21:20:26 +02:00
|
|
|
from bootstrapvz.common.tools import get_codename
|
|
|
|
if get_codename(manifest.system['release']) in ['squeeze', 'wheezy']:
|
2014-12-31 14:14:43 +01:00
|
|
|
group.append(grub.InstallGrub_1_99)
|
2014-07-09 21:20:26 +02:00
|
|
|
else:
|
2014-12-31 14:14:43 +01:00
|
|
|
group.append(grub.InstallGrub_2)
|
2014-07-09 21:20:26 +02:00
|
|
|
if manifest.system['bootloader'] == 'extlinux':
|
2014-12-31 14:14:43 +01:00
|
|
|
group.extend([extlinux.AddExtlinuxPackage,
|
|
|
|
extlinux.ConfigureExtlinux,
|
|
|
|
extlinux.InstallExtlinux])
|
2014-07-09 21:20:26 +02:00
|
|
|
return group
|
2013-12-30 12:14:43 +01:00
|
|
|
|
|
|
|
|
2014-05-03 12:22:51 +02:00
|
|
|
def get_fs_specific_group(manifest):
|
|
|
|
partitions = manifest.volume['partitions']
|
|
|
|
fs_specific_tasks = {'ext2': [filesystem.TuneVolumeFS],
|
|
|
|
'ext3': [filesystem.TuneVolumeFS],
|
|
|
|
'ext4': [filesystem.TuneVolumeFS],
|
|
|
|
'xfs': [filesystem.AddXFSProgs],
|
|
|
|
}
|
|
|
|
group = set()
|
2013-10-06 01:42:32 +02:00
|
|
|
if 'boot' in partitions:
|
2014-05-03 12:22:51 +02:00
|
|
|
group.update(fs_specific_tasks.get(partitions['boot']['filesystem'], []))
|
2013-10-06 01:42:32 +02:00
|
|
|
if 'root' in partitions:
|
2014-05-03 12:22:51 +02:00
|
|
|
group.update(fs_specific_tasks.get(partitions['root']['filesystem'], []))
|
|
|
|
return list(group)
|
|
|
|
|
|
|
|
|
|
|
|
cleanup_group = [cleanup.ClearMOTD,
|
|
|
|
cleanup.CleanTMP,
|
|
|
|
]
|
2014-05-03 13:28:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
rollback_map = {workspace.CreateWorkspace: workspace.DeleteWorkspace,
|
|
|
|
loopback.Create: volume.Delete,
|
|
|
|
volume.Attach: volume.Detach,
|
|
|
|
partitioning.MapPartitions: partitioning.UnmapPartitions,
|
|
|
|
filesystem.CreateMountDir: filesystem.DeleteMountDir,
|
|
|
|
filesystem.MountRoot: filesystem.UnmountRoot,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def get_standard_rollback_tasks(completed):
|
|
|
|
rollback_tasks = set()
|
|
|
|
for task in completed:
|
|
|
|
if task not in rollback_map:
|
|
|
|
continue
|
|
|
|
counter = rollback_map[task]
|
|
|
|
if task in completed and counter not in completed:
|
|
|
|
rollback_tasks.add(counter)
|
|
|
|
return rollback_tasks
|