mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-22 09:50:37 +00:00

Up until now I didn't see the point of using spaces for indentation. However, the previous commit (a18bec3) was quite eye opening. Given that python is an indentation aware language, the amount of mistakes that went unnoticed because tabs and spaces were used at the same time (tabs for indentation and spaces for alignment) were unacceptable. E101,W191 have been re-enable in the tox flake8 checker and the documentation has been modified accordingly. The following files have been left as-is: * bootstrapvz/common/assets/extlinux/extlinux.conf * bootstrapvz/common/assets/init.d/expand-root * bootstrapvz/common/assets/init.d/generate-ssh-hostkeys * bootstrapvz/common/assets/init.d/squeeze/generate-ssh-hostkeys * bootstrapvz/plugins/docker_daemon/assets/init.d/docker * bootstrapvz/providers/ec2/assets/bin/growpart * bootstrapvz/providers/ec2/assets/grub.d/40_custom * bootstrapvz/providers/ec2/assets/init.d/ec2-get-credentials * bootstrapvz/providers/ec2/assets/init.d/ec2-run-user-data * docs/_static/taskoverview.coffee * docs/_static/taskoverview.less * tests/unit/subprocess.sh
99 lines
3.6 KiB
Python
99 lines
3.6 KiB
Python
from bootstrapvz.base import Task
|
|
from bootstrapvz.common import phases
|
|
from bootstrapvz.common.tools import log_check_call
|
|
from bootstrapvz.common.tasks import apt
|
|
from bootstrapvz.common.tasks import locale
|
|
import logging
|
|
import os.path
|
|
|
|
|
|
class AddCloudInitPackages(Task):
|
|
description = 'Adding cloud-init package and sudo'
|
|
phase = phases.preparation
|
|
predecessors = [apt.AddBackports]
|
|
|
|
@classmethod
|
|
def run(cls, info):
|
|
target = None
|
|
from bootstrapvz.common.releases import wheezy
|
|
if info.manifest.release == wheezy:
|
|
target = '{system.release}-backports'
|
|
info.packages.add('cloud-init', target)
|
|
info.packages.add('sudo')
|
|
|
|
|
|
class SetUsername(Task):
|
|
description = 'Setting username in cloud.cfg'
|
|
phase = phases.system_modification
|
|
|
|
@classmethod
|
|
def run(cls, info):
|
|
from bootstrapvz.common.tools import sed_i
|
|
cloud_cfg = os.path.join(info.root, 'etc/cloud/cloud.cfg')
|
|
username = info.manifest.plugins['cloud_init']['username']
|
|
search = '^ name: debian$'
|
|
replace = (' name: {username}\n'
|
|
' sudo: ALL=(ALL) NOPASSWD:ALL\n'
|
|
' shell: /bin/bash').format(username=username)
|
|
sed_i(cloud_cfg, search, replace)
|
|
|
|
|
|
class SetGroups(Task):
|
|
description = 'Setting groups in cloud.cfg'
|
|
phase = phases.system_modification
|
|
|
|
@classmethod
|
|
def run(cls, info):
|
|
from bootstrapvz.common.tools import sed_i
|
|
cloud_cfg = os.path.join(info.root, 'etc/cloud/cloud.cfg')
|
|
groups = info.manifest.plugins['cloud_init']['groups']
|
|
search = ('^ groups: \[adm, audio, cdrom, dialout, floppy, video,'
|
|
' plugdev, dip\]$')
|
|
replace = (' groups: [adm, audio, cdrom, dialout, floppy, video,'
|
|
' plugdev, dip, {groups}]').format(groups=', '.join(groups))
|
|
sed_i(cloud_cfg, search, replace)
|
|
|
|
|
|
class SetMetadataSource(Task):
|
|
description = 'Setting metadata source'
|
|
phase = phases.package_installation
|
|
predecessors = [locale.GenerateLocale]
|
|
successors = [apt.AptUpdate]
|
|
|
|
@classmethod
|
|
def run(cls, info):
|
|
if 'metadata_sources' in info.manifest.plugins['cloud_init']:
|
|
sources = info.manifest.plugins['cloud_init']['metadata_sources']
|
|
else:
|
|
source_mapping = {'ec2': 'Ec2'}
|
|
sources = source_mapping.get(info.manifest.provider['name'], None)
|
|
if sources is None:
|
|
msg = ('No cloud-init metadata source mapping found for provider `{provider}\', '
|
|
'skipping selections setting.').format(provider=info.manifest.provider['name'])
|
|
logging.getLogger(__name__).warn(msg)
|
|
return
|
|
sources = "cloud-init cloud-init/datasources multiselect " + sources
|
|
log_check_call(['chroot', info.root, 'debconf-set-selections'], sources)
|
|
|
|
|
|
class DisableModules(Task):
|
|
description = 'Setting cloud.cfg modules'
|
|
phase = phases.system_modification
|
|
|
|
@classmethod
|
|
def run(cls, info):
|
|
import re
|
|
patterns = ""
|
|
for pattern in info.manifest.plugins['cloud_init']['disable_modules']:
|
|
if patterns != "":
|
|
patterns = patterns + "|" + pattern
|
|
else:
|
|
patterns = "^\s+-\s+(" + pattern
|
|
patterns = patterns + ")$"
|
|
regex = re.compile(patterns)
|
|
|
|
cloud_cfg = os.path.join(info.root, 'etc/cloud/cloud.cfg')
|
|
import fileinput
|
|
for line in fileinput.input(files=cloud_cfg, inplace=True):
|
|
if not regex.match(line):
|
|
print line,
|