This repository has been archived by the owner on Jun 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 142
/
task_groups.py
223 lines (194 loc) · 7.39 KB
/
task_groups.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
from tasks import workspace
from tasks import packages
from tasks import host
from tasks import grub
from tasks import extlinux
from tasks import bootstrap
from tasks import volume
from tasks import loopback
from tasks import filesystem
from tasks import partitioning
from tasks import cleanup
from tasks import apt
from tasks import security
from tasks import locale
from tasks import network
from tasks import initd
from tasks import ssh
from tasks import kernel
from tasks import folder
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)
group.extend(kernel_group)
group.extend(get_fs_specific_group(manifest))
group.extend(get_network_group(manifest))
group.extend(get_apt_group(manifest))
group.extend(security_group)
group.extend(get_locale_group(manifest))
group.extend(get_bootloader_group(manifest))
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)
if manifest.bootstrapper.get('include_packages', False):
group.append(bootstrap.IncludePackagesInBootstrap)
if manifest.bootstrapper.get('exclude_packages', False):
group.append(bootstrap.ExcludePackagesInBootstrap)
return group
volume_group = [volume.Attach,
volume.Detach,
filesystem.AddRequiredCommands,
filesystem.Format,
filesystem.FStab,
]
partitioning_group = [partitioning.AddRequiredCommands,
partitioning.PartitionVolume,
partitioning.MapPartitions,
partitioning.UnmapPartitions,
]
boot_partition_group = [filesystem.CreateBootMountDir,
filesystem.MountBoot,
]
mounting_group = [filesystem.CreateMountDir,
filesystem.MountRoot,
filesystem.MountAdditional,
filesystem.MountSpecials,
filesystem.CopyMountTable,
filesystem.RemoveMountTable,
filesystem.UnmountRoot,
filesystem.DeleteMountDir,
]
kernel_group = [kernel.DetermineKernelVersion,
kernel.UpdateInitramfs,
]
ssh_group = [ssh.AddOpenSSHPackage,
ssh.DisableSSHPasswordAuthentication,
ssh.DisableSSHDNSLookup,
ssh.AddSSHKeyGeneration,
initd.InstallInitScripts,
ssh.ShredHostkeys,
]
def get_network_group(manifest):
if manifest.bootstrapper.get('variant', None) == 'minbase':
# minbase has no networking
return []
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,
]
if 'sources' in manifest.packages:
group.append(apt.AddManifestSources)
if 'trusted-keys' in manifest.packages:
group.append(apt.ValidateTrustedKeys)
group.append(apt.InstallTrustedKeys)
if 'preferences' in manifest.packages:
group.append(apt.AddManifestPreferences)
group.append(apt.WritePreferences)
if 'apt.conf.d' in manifest.packages:
group.append(apt.WriteConfiguration)
if 'install' in manifest.packages:
group.append(packages.AddManifestPackages)
if manifest.packages.get('install_standard', False):
group.append(packages.AddTaskselStandardPackages)
return group
security_group = [security.EnableShadowConfig]
def get_locale_group(manifest):
from bootstrapvz.common.releases import jessie
group = [
locale.LocaleBootstrapPackage,
locale.GenerateLocale,
locale.SetTimezone,
]
if manifest.release > jessie:
group.append(locale.SetLocalTimeLink)
else:
group.append(locale.SetLocalTimeCopy)
return group
def get_bootloader_group(manifest):
from bootstrapvz.common.releases import jessie
from bootstrapvz.common.releases import stretch
group = []
if manifest.system['bootloader'] == 'grub':
group.extend([grub.AddGrubPackage,
grub.InitGrubConfig,
grub.SetGrubTerminalToConsole,
grub.SetGrubConsolOutputDeviceToSerial,
grub.RemoveGrubTimeout,
grub.DisableGrubRecovery,
grub.WriteGrubConfig])
if manifest.release < jessie:
group.append(grub.InstallGrub_1_99)
else:
group.append(grub.InstallGrub_2)
if manifest.release >= stretch:
group.append(grub.DisablePNIN)
if manifest.system['bootloader'] == 'extlinux':
group.append(extlinux.AddExtlinuxPackage)
if manifest.release < jessie:
group.extend([extlinux.ConfigureExtlinux,
extlinux.InstallExtlinux])
else:
group.extend([extlinux.ConfigureExtlinuxJessie,
extlinux.InstallExtlinuxJessie])
return group
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()
if 'boot' in partitions:
group.update(fs_specific_tasks.get(partitions['boot']['filesystem'], []))
if 'root' in partitions:
group.update(fs_specific_tasks.get(partitions['root']['filesystem'], []))
return list(group)
cleanup_group = [cleanup.ClearMOTD,
cleanup.CleanTMP,
]
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,
folder.Create: folder.Delete,
}
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