diff --git a/.gitignore b/.gitignore index 3bfd84e..ebaa1c3 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ _site/ # When developing for ec2 `vagrant provision' is quite handy /Vagrantfile /.vagrant +/build +/dist +/bootstrap_vz.egg-info diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..a671734 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,4 @@ +include LICENSE +include manifests/* +recursive-include bootstrapvz assets/* +recursive-include bootstrapvz *.json diff --git a/bootstrapvz/base/fs/partitions/base.py b/bootstrapvz/base/fs/partitions/base.py index c1ac273..d17881b 100644 --- a/bootstrapvz/base/fs/partitions/base.py +++ b/bootstrapvz/base/fs/partitions/base.py @@ -81,7 +81,7 @@ class BasePartition(AbstractPartition): def _before_create(self, e): """Creates the partition """ - from common.tools import log_check_call + from bootstrapvz.common.tools import log_check_call # The create command is failry simple, start and end are just Bytes objects coerced into strings create_command = ('mkpart primary {start} {end}' .format(start=str(self.get_start()), diff --git a/bootstrapvz/base/log.py b/bootstrapvz/base/log.py index ece32e7..15551c8 100644 --- a/bootstrapvz/base/log.py +++ b/bootstrapvz/base/log.py @@ -5,7 +5,20 @@ both to a file and to the console. import logging -def get_logfile_path(manifest_path): +def create_log_dir(): + """Creates the log directory + + Returns: + str. The path to the logdirectory + """ + log_dir_path = '/var/log/bootstrap-vz' + import os + if not os.path.exists(log_dir_path): + os.makedirs(log_dir_path) + return log_dir_path + + +def get_log_filename(manifest_path): """Returns the path to a logfile given a manifest The logfile name is constructed from the current timestamp and the basename of the manifest @@ -22,7 +35,7 @@ def get_logfile_path(manifest_path): manifest_name, _ = os.path.splitext(manifest_basename) timestamp = datetime.now().strftime('%Y%m%d%H%M%S') filename = "{timestamp}_{name}.log".format(timestamp=timestamp, name=manifest_name) - return os.path.normpath(os.path.join(os.path.dirname(__file__), '../logs', filename)) + return filename def setup_logger(logfile=None, debug=False): diff --git a/bootstrapvz/base/main.py b/bootstrapvz/base/main.py index add0301..936abe4 100644 --- a/bootstrapvz/base/main.py +++ b/bootstrapvz/base/main.py @@ -20,7 +20,9 @@ def main(): raise Exception('This program requires root privileges.') # Setup logging import log - logfile = log.get_logfile_path(args.manifest) + log_dir = log.create_log_dir() + log_filename = log.get_log_filename(args.manifest) + logfile = os.path.join(log_dir, log_filename) log.setup_logger(logfile=logfile, debug=args.debug) # Everything has been set up, begin the bootstrapping process run(args) diff --git a/bootstrapvz/base/manifest.py b/bootstrapvz/base/manifest.py index 631f6c1..58f7994 100644 --- a/bootstrapvz/base/manifest.py +++ b/bootstrapvz/base/manifest.py @@ -121,5 +121,5 @@ class Manifest(object): message (str): Message to user about the error json_path (list): A path to the location in the manifest where the error occurred """ - from common.exceptions import ManifestError + from bootstrapvz.common.exceptions import ManifestError raise ManifestError(message, self.path, json_path) diff --git a/bootstrapvz/common/fs/__init__.py b/bootstrapvz/common/fs/__init__.py index 93ba9ae..694846e 100644 --- a/bootstrapvz/common/fs/__init__.py +++ b/bootstrapvz/common/fs/__init__.py @@ -17,7 +17,7 @@ def get_partitions(): def remount(volume, fn): - from base.fs.partitionmaps.none import NoPartitions + from bootstrapvz.base.fs.partitionmaps.none import NoPartitions p_map = volume.partition_map root_dir = p_map.root.mount_dir diff --git a/bootstrapvz/common/tasks/boot.py b/bootstrapvz/common/tasks/boot.py index 94545c2..05dab75 100644 --- a/bootstrapvz/common/tasks/boot.py +++ b/bootstrapvz/common/tasks/boot.py @@ -45,17 +45,17 @@ class AddGrubPackage(Task): class ConfigureGrub(Task): - description = 'Configuring grub' - phase = phases.system_modification - predecessors = [filesystem.FStab] + description = 'Configuring grub' + phase = phases.system_modification + predecessors = [filesystem.FStab] - @classmethod - def run(cls, info): - from common.tools import sed_i - grub_def = os.path.join(info.root, 'etc/default/grub') - sed_i(grub_def, '^#GRUB_TERMINAL=console', 'GRUB_TERMINAL=console') - sed_i(grub_def, '^GRUB_CMDLINE_LINUX_DEFAULT="quiet"', - 'GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0"') + @classmethod + def run(cls, info): + from bootstrapvz.common.tools import sed_i + grub_def = os.path.join(info.root, 'etc/default/grub') + sed_i(grub_def, '^#GRUB_TERMINAL=console', 'GRUB_TERMINAL=console') + sed_i(grub_def, '^GRUB_CMDLINE_LINUX_DEFAULT="quiet"', + 'GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0"') class InstallGrub(Task): diff --git a/bootstrapvz/common/tasks/filesystem.py b/bootstrapvz/common/tasks/filesystem.py index 0eb0f7e..71845f6 100644 --- a/bootstrapvz/common/tasks/filesystem.py +++ b/bootstrapvz/common/tasks/filesystem.py @@ -24,7 +24,7 @@ class Format(Task): @classmethod def run(cls, info): - from base.fs.partitions.unformatted import UnformattedPartition + from bootstrapvz.base.fs.partitions.unformatted import UnformattedPartition for partition in info.volume.partition_map.partitions: if not isinstance(partition, UnformattedPartition): partition.format() @@ -37,7 +37,7 @@ class TuneVolumeFS(Task): @classmethod def run(cls, info): - from base.fs.partitions.unformatted import UnformattedPartition + from bootstrapvz.base.fs.partitions.unformatted import UnformattedPartition import re # Disable the time based filesystem check for partition in info.volume.partition_map.partitions: diff --git a/bootstrapvz/common/tasks/initd.py b/bootstrapvz/common/tasks/initd.py index 2cf3bc5..97adb89 100644 --- a/bootstrapvz/common/tasks/initd.py +++ b/bootstrapvz/common/tasks/initd.py @@ -83,7 +83,7 @@ class AdjustExpandRootScript(Task): if 'expand-root' not in info.initd['install']: raise TaskError('The expand-root script was not installed') - from base.fs.partitionmaps.none import NoPartitions + from bootstrapvz.base.fs.partitionmaps.none import NoPartitions if not isinstance(info.volume.partition_map, NoPartitions): import os.path from ..tools import sed_i diff --git a/bootstrapvz/logs/.gitignore b/bootstrapvz/logs/.gitignore deleted file mode 100644 index d6b7ef3..0000000 --- a/bootstrapvz/logs/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/bootstrapvz/plugins/puppet/tasks.py b/bootstrapvz/plugins/puppet/tasks.py index 844424f..dca4cd7 100644 --- a/bootstrapvz/plugins/puppet/tasks.py +++ b/bootstrapvz/plugins/puppet/tasks.py @@ -53,7 +53,7 @@ class CopyPuppetAssets(Task): @classmethod def run(cls, info): - from common.tools import copy_tree + from bootstrapvz.common.tools import copy_tree copy_tree(info.manifest.plugins['puppet']['assets'], os.path.join(info.root, 'etc/puppet')) diff --git a/bootstrapvz/manifests/ec2-ebs-debian-official-amd64-hvm-cn-north-1.manifest.json b/manifests/ec2-ebs-debian-official-amd64-hvm-cn-north-1.manifest.json similarity index 100% rename from bootstrapvz/manifests/ec2-ebs-debian-official-amd64-hvm-cn-north-1.manifest.json rename to manifests/ec2-ebs-debian-official-amd64-hvm-cn-north-1.manifest.json diff --git a/bootstrapvz/manifests/ec2-ebs-debian-official-amd64-hvm.manifest.json b/manifests/ec2-ebs-debian-official-amd64-hvm.manifest.json similarity index 100% rename from bootstrapvz/manifests/ec2-ebs-debian-official-amd64-hvm.manifest.json rename to manifests/ec2-ebs-debian-official-amd64-hvm.manifest.json diff --git a/bootstrapvz/manifests/ec2-ebs-debian-official-amd64-pvm-cn-north-1.manifest.json b/manifests/ec2-ebs-debian-official-amd64-pvm-cn-north-1.manifest.json similarity index 100% rename from bootstrapvz/manifests/ec2-ebs-debian-official-amd64-pvm-cn-north-1.manifest.json rename to manifests/ec2-ebs-debian-official-amd64-pvm-cn-north-1.manifest.json diff --git a/bootstrapvz/manifests/ec2-ebs-debian-official-amd64-pvm.manifest.json b/manifests/ec2-ebs-debian-official-amd64-pvm.manifest.json similarity index 100% rename from bootstrapvz/manifests/ec2-ebs-debian-official-amd64-pvm.manifest.json rename to manifests/ec2-ebs-debian-official-amd64-pvm.manifest.json diff --git a/bootstrapvz/manifests/ec2-ebs-debian-official-i386-pvm.manifest.json b/manifests/ec2-ebs-debian-official-i386-pvm.manifest.json similarity index 100% rename from bootstrapvz/manifests/ec2-ebs-debian-official-i386-pvm.manifest.json rename to manifests/ec2-ebs-debian-official-i386-pvm.manifest.json diff --git a/bootstrapvz/manifests/ec2-ebs-debian-testing-amd64-pvm.manifest.json b/manifests/ec2-ebs-debian-testing-amd64-pvm.manifest.json similarity index 100% rename from bootstrapvz/manifests/ec2-ebs-debian-testing-amd64-pvm.manifest.json rename to manifests/ec2-ebs-debian-testing-amd64-pvm.manifest.json diff --git a/bootstrapvz/manifests/ec2-ebs-debian-unstable-amd64-pvm.manifest.json b/manifests/ec2-ebs-debian-unstable-amd64-pvm.manifest.json similarity index 100% rename from bootstrapvz/manifests/ec2-ebs-debian-unstable-amd64-pvm.manifest.json rename to manifests/ec2-ebs-debian-unstable-amd64-pvm.manifest.json diff --git a/bootstrapvz/manifests/ec2-ebs-debian-unstable-contrib-amd64-pvm.manifest.json b/manifests/ec2-ebs-debian-unstable-contrib-amd64-pvm.manifest.json similarity index 100% rename from bootstrapvz/manifests/ec2-ebs-debian-unstable-contrib-amd64-pvm.manifest.json rename to manifests/ec2-ebs-debian-unstable-contrib-amd64-pvm.manifest.json diff --git a/bootstrapvz/manifests/ec2-ebs-partitioned.manifest.json b/manifests/ec2-ebs-partitioned.manifest.json similarity index 100% rename from bootstrapvz/manifests/ec2-ebs-partitioned.manifest.json rename to manifests/ec2-ebs-partitioned.manifest.json diff --git a/bootstrapvz/manifests/ec2-ebs-single.manifest.json b/manifests/ec2-ebs-single.manifest.json similarity index 100% rename from bootstrapvz/manifests/ec2-ebs-single.manifest.json rename to manifests/ec2-ebs-single.manifest.json diff --git a/bootstrapvz/manifests/ec2-s3-debian-official-amd64-pvm-cn-north-1.manifest.json b/manifests/ec2-s3-debian-official-amd64-pvm-cn-north-1.manifest.json similarity index 100% rename from bootstrapvz/manifests/ec2-s3-debian-official-amd64-pvm-cn-north-1.manifest.json rename to manifests/ec2-s3-debian-official-amd64-pvm-cn-north-1.manifest.json diff --git a/bootstrapvz/manifests/ec2-s3.manifest.json b/manifests/ec2-s3.manifest.json similarity index 100% rename from bootstrapvz/manifests/ec2-s3.manifest.json rename to manifests/ec2-s3.manifest.json diff --git a/bootstrapvz/manifests/kvm-virtio.manifest.json b/manifests/kvm-virtio.manifest.json similarity index 100% rename from bootstrapvz/manifests/kvm-virtio.manifest.json rename to manifests/kvm-virtio.manifest.json diff --git a/bootstrapvz/manifests/kvm.manifest.json b/manifests/kvm.manifest.json similarity index 100% rename from bootstrapvz/manifests/kvm.manifest.json rename to manifests/kvm.manifest.json diff --git a/bootstrapvz/manifests/virtualbox-vagrant.manifest.json b/manifests/virtualbox-vagrant.manifest.json similarity index 100% rename from bootstrapvz/manifests/virtualbox-vagrant.manifest.json rename to manifests/virtualbox-vagrant.manifest.json diff --git a/bootstrapvz/manifests/virtualbox.manifest.json b/manifests/virtualbox.manifest.json similarity index 100% rename from bootstrapvz/manifests/virtualbox.manifest.json rename to manifests/virtualbox.manifest.json diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..9bc5358 --- /dev/null +++ b/setup.py @@ -0,0 +1,34 @@ +from setuptools import setup +from setuptools import find_packages +import os.path + + +def find_version(path): + import re + version_file = open(path).read() + version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", version_file, re.M) + if version_match: + return version_match.group(1) + raise RuntimeError("Unable to find version string.") + +setup(name='bootstrap-vz', + version=find_version(os.path.join(os.path.dirname(__file__), 'bootstrapvz/__init__.py')), + packages=find_packages(), + include_package_data=True, + entry_points={'console_scripts': ['bootstrap-vz = bootstrapvz.base:main']}, + install_requires=['termcolor >= 1.1.0', + 'fysom >= 1.0.15', + 'jsonschema >= 2.3.0', + ], + license='Apache License, Version 2.0', + description='Bootstrap Debian images for virtualized environments', + long_description='''bootstrap-vz is a bootstrapping framework for Debian. +It is is specifically targeted at bootstrapping systems for virtualized environments. +bootstrap-vz runs without any user intervention and generates ready-to-boot images for +a number of virtualization platforms. +Its aim is to provide a reproducable bootstrapping process using manifests +as well as supporting a high degree of customizability through plugins.''', + author='Anders Ingemann', + author_email='anders@ingemann.de', + url='http://www.python.org/sigs/distutils-sig/', + )