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 141
/
Copy path__init__.py
153 lines (126 loc) · 6.69 KB
/
__init__.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
from bootstrapvz.common import task_groups
from .tasks import packages, connection, host, ami, ebs, filesystem, boot, network, initd, tuning
import bootstrapvz.common.tasks.boot
import bootstrapvz.common.tasks.filesystem
import bootstrapvz.common.tasks.grub
import bootstrapvz.common.tasks.initd
from bootstrapvz.common.tasks import apt, kernel, loopback, volume
from bootstrapvz.common.tools import rel_path
def validate_manifest(data, validator, error):
validator(data, rel_path(__file__, 'manifest-schema.yml'))
from bootstrapvz.common.bytes import Bytes
if data['volume']['backing'] == 'ebs':
volume_size = Bytes(0)
for key, partition in data['volume']['partitions'].iteritems():
if key != 'type':
volume_size += Bytes(partition['size'])
if int(volume_size % Bytes('1GiB')) != 0:
msg = ('The volume size must be a multiple of 1GiB when using EBS backing')
error(msg, ['volume', 'partitions'])
else:
validator(data, rel_path(__file__, 'manifest-schema-s3.yml'))
bootloader = data['system']['bootloader']
virtualization = data['provider']['virtualization']
encrypted = data['provider'].get('encrypted', False)
kms_key_id = data['provider'].get('kms_key_id', None)
backing = data['volume']['backing']
partition_type = data['volume']['partitions']['type']
enhanced_networking = data['provider']['enhanced_networking'] if 'enhanced_networking' in data['provider'] else None
if virtualization == 'pvm' and bootloader != 'pvgrub':
error('Paravirtualized AMIs only support pvgrub as a bootloader', ['system', 'bootloader'])
if backing != 'ebs' and virtualization == 'hvm':
error('HVM AMIs currently only work when they are EBS backed', ['volume', 'backing'])
if backing == 's3' and partition_type != 'none':
error('S3 backed AMIs currently only work with unpartitioned volumes', ['system', 'bootloader'])
if backing != 'ebs' and encrypted:
error('Encryption is supported only on EBS volumes')
if encrypted is False and kms_key_id is not None:
error('KMS Key Id can be set only when encryption is enabled')
if enhanced_networking == 'simple' and virtualization != 'hvm':
error('Enhanced networking only works with HVM virtualization', ['provider', 'virtualization'])
def resolve_tasks(taskset, manifest):
"""
Function setting up tasks to run for this provider
"""
from bootstrapvz.common.releases import wheezy, jessie, stable
taskset.update(task_groups.get_standard_groups(manifest))
taskset.update(task_groups.ssh_group)
taskset.update([host.AddExternalCommands,
packages.DefaultPackages,
connection.SilenceBotoDebug,
connection.GetCredentials,
ami.AMIName,
connection.Connect,
tuning.TuneSystem,
tuning.BlackListModules,
bootstrapvz.common.tasks.boot.BlackListModules,
bootstrapvz.common.tasks.boot.DisableGetTTYs,
bootstrapvz.common.tasks.initd.AddExpandRoot,
bootstrapvz.common.tasks.initd.RemoveHWClock,
bootstrapvz.common.tasks.initd.InstallInitScripts,
ami.RegisterAMI,
])
if manifest.release > wheezy:
taskset.add(network.InstallNetworkingUDevHotplugAndDHCPSubinterface)
if manifest.release <= wheezy:
# The default DHCP client `isc-dhcp' doesn't work properly on wheezy and earlier
taskset.add(network.InstallDHCPCD)
taskset.add(network.EnableDHCPCDDNS)
if manifest.release >= jessie:
taskset.add(packages.AddWorkaroundGrowpart)
taskset.add(bootstrapvz.common.tasks.initd.AdjustGrowpartWorkaround)
if manifest.system['bootloader'] == 'grub':
taskset.add(bootstrapvz.common.tasks.grub.EnableSystemd)
if manifest.release <= stable:
taskset.add(apt.AddBackports)
if manifest.provider.get('install_init_scripts', True):
taskset.add(initd.AddEC2InitScripts)
if manifest.volume['partitions']['type'] != 'none':
taskset.add(bootstrapvz.common.tasks.initd.AdjustExpandRootScript)
if manifest.system['bootloader'] in ('grub', 'pvgrub'):
taskset.update([boot.AddXenGrubConsoleOutputDevice,
bootstrapvz.common.tasks.grub.WriteGrubConfig,
boot.UpdateGrubConfig])
if manifest.system['bootloader'] == 'pvgrub':
taskset.add(bootstrapvz.common.tasks.grub.AddGrubPackage)
taskset.update([bootstrapvz.common.tasks.grub.AddGrubPackage,
bootstrapvz.common.tasks.grub.InitGrubConfig,
bootstrapvz.common.tasks.grub.SetGrubTerminalToConsole,
bootstrapvz.common.tasks.grub.SetGrubConsolOutputDeviceToSerial,
bootstrapvz.common.tasks.grub.RemoveGrubTimeout,
bootstrapvz.common.tasks.grub.DisableGrubRecovery,
boot.CreatePVGrubCustomRule,
boot.ConfigurePVGrub,
bootstrapvz.common.tasks.grub.WriteGrubConfig,
boot.UpdateGrubConfig,
boot.LinkGrubConfig])
if manifest.volume['backing'].lower() == 'ebs':
taskset.update([host.GetInstanceMetadata,
ebs.Create,
ebs.Snapshot,
])
taskset.add(ebs.Attach)
taskset.discard(volume.Attach)
if manifest.volume['backing'].lower() == 's3':
taskset.update([loopback.AddRequiredCommands,
host.SetRegion,
loopback.Create,
filesystem.S3FStab,
ami.BundleImage,
ami.UploadImage,
ami.RemoveBundle,
])
taskset.discard(bootstrapvz.common.tasks.filesystem.FStab)
if manifest.provider.get('enhanced_networking', None) == 'simple':
taskset.update([kernel.AddDKMSPackages,
network.InstallEnhancedNetworking,
network.InstallENANetworking,
kernel.UpdateInitramfs])
taskset.update([bootstrapvz.common.tasks.filesystem.Format,
volume.Delete,
])
def resolve_rollback_tasks(taskset, manifest, completed, counter_task):
taskset.update(task_groups.get_standard_rollback_tasks(completed))
counter_task(taskset, ebs.Create, volume.Delete)
counter_task(taskset, ebs.Attach, volume.Detach)
counter_task(taskset, ami.BundleImage, ami.RemoveBundle)