mirror of
https://github.com/kevingruesser/bootstrap-vz.git
synced 2025-08-24 07:26:29 +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
92 lines
3.2 KiB
Python
92 lines
3.2 KiB
Python
from bootstrapvz.base import Task
|
|
from bootstrapvz.common import phases
|
|
from bootstrapvz.common.tools import sed_i
|
|
import os
|
|
|
|
|
|
class CheckAssetsPath(Task):
|
|
description = 'Checking whether the assets path exist'
|
|
phase = phases.preparation
|
|
|
|
@classmethod
|
|
def run(cls, info):
|
|
from bootstrapvz.common.exceptions import TaskError
|
|
assets = info.manifest.plugins['puppet']['assets']
|
|
if not os.path.exists(assets):
|
|
msg = 'The assets directory {assets} does not exist.'.format(assets=assets)
|
|
raise TaskError(msg)
|
|
if not os.path.isdir(assets):
|
|
msg = 'The assets path {assets} does not point to a directory.'.format(assets=assets)
|
|
raise TaskError(msg)
|
|
|
|
|
|
class CheckManifestPath(Task):
|
|
description = 'Checking whether the manifest path exist'
|
|
phase = phases.preparation
|
|
|
|
@classmethod
|
|
def run(cls, info):
|
|
from bootstrapvz.common.exceptions import TaskError
|
|
manifest = info.manifest.plugins['puppet']['manifest']
|
|
if not os.path.exists(manifest):
|
|
msg = 'The manifest file {manifest} does not exist.'.format(manifest=manifest)
|
|
raise TaskError(msg)
|
|
if not os.path.isfile(manifest):
|
|
msg = 'The manifest path {manifest} does not point to a file.'.format(manifest=manifest)
|
|
raise TaskError(msg)
|
|
|
|
|
|
class AddPackages(Task):
|
|
description = 'Add puppet package'
|
|
phase = phases.preparation
|
|
|
|
@classmethod
|
|
def run(cls, info):
|
|
info.packages.add('puppet')
|
|
|
|
|
|
class CopyPuppetAssets(Task):
|
|
description = 'Copying puppet assets'
|
|
phase = phases.system_modification
|
|
|
|
@classmethod
|
|
def run(cls, info):
|
|
from bootstrapvz.common.tools import copy_tree
|
|
copy_tree(info.manifest.plugins['puppet']['assets'], os.path.join(info.root, 'etc/puppet'))
|
|
|
|
|
|
class ApplyPuppetManifest(Task):
|
|
description = 'Applying puppet manifest'
|
|
phase = phases.user_modification
|
|
|
|
@classmethod
|
|
def run(cls, info):
|
|
with open(os.path.join(info.root, 'etc/hostname')) as handle:
|
|
hostname = handle.read().strip()
|
|
with open(os.path.join(info.root, 'etc/hosts'), 'a') as handle:
|
|
handle.write('127.0.0.1\t{hostname}\n'.format(hostname=hostname))
|
|
|
|
from shutil import copy
|
|
pp_manifest = info.manifest.plugins['puppet']['manifest']
|
|
manifest_rel_dst = os.path.join('tmp', os.path.basename(pp_manifest))
|
|
manifest_dst = os.path.join(info.root, manifest_rel_dst)
|
|
copy(pp_manifest, manifest_dst)
|
|
|
|
manifest_path = os.path.join('/', manifest_rel_dst)
|
|
from bootstrapvz.common.tools import log_check_call
|
|
log_check_call(['chroot', info.root,
|
|
'puppet', 'apply', manifest_path])
|
|
os.remove(manifest_dst)
|
|
|
|
hosts_path = os.path.join(info.root, 'etc/hosts')
|
|
sed_i(hosts_path, '127.0.0.1\s*{hostname}\n?'.format(hostname=hostname), '')
|
|
|
|
|
|
class EnableAgent(Task):
|
|
description = 'Enabling the puppet agent'
|
|
phase = phases.system_modification
|
|
|
|
@classmethod
|
|
def run(cls, info):
|
|
puppet_defaults = os.path.join(info.root, 'etc/defaults/puppet')
|
|
sed_i(puppet_defaults, 'START=no', 'START=yes')
|