bootstrap-vz is now a proper python package

logs/ was remove. logs are now placed in /var/logs/bootstrap-vz instead
This commit is contained in:
Anders Ingemann 2014-03-23 23:53:20 +01:00
parent bbb06d717e
commit 33a430566b
29 changed files with 76 additions and 22 deletions

3
.gitignore vendored
View file

@ -5,3 +5,6 @@ _site/
# When developing for ec2 `vagrant provision' is quite handy # When developing for ec2 `vagrant provision' is quite handy
/Vagrantfile /Vagrantfile
/.vagrant /.vagrant
/build
/dist
/bootstrap_vz.egg-info

4
MANIFEST.in Normal file
View file

@ -0,0 +1,4 @@
include LICENSE
include manifests/*
recursive-include bootstrapvz assets/*
recursive-include bootstrapvz *.json

View file

@ -81,7 +81,7 @@ class BasePartition(AbstractPartition):
def _before_create(self, e): def _before_create(self, e):
"""Creates the partition """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 # The create command is failry simple, start and end are just Bytes objects coerced into strings
create_command = ('mkpart primary {start} {end}' create_command = ('mkpart primary {start} {end}'
.format(start=str(self.get_start()), .format(start=str(self.get_start()),

View file

@ -5,7 +5,20 @@ both to a file and to the console.
import logging 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 """Returns the path to a logfile given a manifest
The logfile name is constructed from the current timestamp and the basename of the 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) manifest_name, _ = os.path.splitext(manifest_basename)
timestamp = datetime.now().strftime('%Y%m%d%H%M%S') timestamp = datetime.now().strftime('%Y%m%d%H%M%S')
filename = "{timestamp}_{name}.log".format(timestamp=timestamp, name=manifest_name) 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): def setup_logger(logfile=None, debug=False):

View file

@ -20,7 +20,9 @@ def main():
raise Exception('This program requires root privileges.') raise Exception('This program requires root privileges.')
# Setup logging # Setup logging
import log 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) log.setup_logger(logfile=logfile, debug=args.debug)
# Everything has been set up, begin the bootstrapping process # Everything has been set up, begin the bootstrapping process
run(args) run(args)

View file

@ -121,5 +121,5 @@ class Manifest(object):
message (str): Message to user about the error message (str): Message to user about the error
json_path (list): A path to the location in the manifest where the error occurred 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) raise ManifestError(message, self.path, json_path)

View file

@ -17,7 +17,7 @@ def get_partitions():
def remount(volume, fn): def remount(volume, fn):
from base.fs.partitionmaps.none import NoPartitions from bootstrapvz.base.fs.partitionmaps.none import NoPartitions
p_map = volume.partition_map p_map = volume.partition_map
root_dir = p_map.root.mount_dir root_dir = p_map.root.mount_dir

View file

@ -51,7 +51,7 @@ class ConfigureGrub(Task):
@classmethod @classmethod
def run(cls, info): def run(cls, info):
from common.tools import sed_i from bootstrapvz.common.tools import sed_i
grub_def = os.path.join(info.root, 'etc/default/grub') 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_TERMINAL=console', 'GRUB_TERMINAL=console')
sed_i(grub_def, '^GRUB_CMDLINE_LINUX_DEFAULT="quiet"', sed_i(grub_def, '^GRUB_CMDLINE_LINUX_DEFAULT="quiet"',

View file

@ -24,7 +24,7 @@ class Format(Task):
@classmethod @classmethod
def run(cls, info): 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: for partition in info.volume.partition_map.partitions:
if not isinstance(partition, UnformattedPartition): if not isinstance(partition, UnformattedPartition):
partition.format() partition.format()
@ -37,7 +37,7 @@ class TuneVolumeFS(Task):
@classmethod @classmethod
def run(cls, info): def run(cls, info):
from base.fs.partitions.unformatted import UnformattedPartition from bootstrapvz.base.fs.partitions.unformatted import UnformattedPartition
import re import re
# Disable the time based filesystem check # Disable the time based filesystem check
for partition in info.volume.partition_map.partitions: for partition in info.volume.partition_map.partitions:

View file

@ -83,7 +83,7 @@ class AdjustExpandRootScript(Task):
if 'expand-root' not in info.initd['install']: if 'expand-root' not in info.initd['install']:
raise TaskError('The expand-root script was not installed') 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): if not isinstance(info.volume.partition_map, NoPartitions):
import os.path import os.path
from ..tools import sed_i from ..tools import sed_i

View file

@ -1,2 +0,0 @@
*
!.gitignore

View file

@ -53,7 +53,7 @@ class CopyPuppetAssets(Task):
@classmethod @classmethod
def run(cls, info): 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')) copy_tree(info.manifest.plugins['puppet']['assets'], os.path.join(info.root, 'etc/puppet'))

34
setup.py Normal file
View file

@ -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/',
)