From 4b5c2d8c5faece1dd902c046961ce3ae40b53fd5 Mon Sep 17 00:00:00 2001 From: Rory Finnegan Date: Tue, 8 Apr 2014 05:33:34 +0000 Subject: [PATCH 1/4] Added YAML config support. - Manifest format parsing is now checked by the file extension ie: .json, .yml or .yaml. - load_yaml in common/tools is the same as the json version. - schema checking of manifest still passes (and fails appropriately) like the json manifests. - I've also included a sample yaml config based off of the debian test json manifest. --- bootstrapvz/base/manifest.py | 8 +++-- bootstrapvz/common/tools.py | 4 +++ ...-ebs-debian-testing-amd64-pvm.manifest.yml | 36 +++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 manifests/ec2-ebs-debian-testing-amd64-pvm.manifest.yml diff --git a/bootstrapvz/base/manifest.py b/bootstrapvz/base/manifest.py index 0ad10d6..6bca3eb 100644 --- a/bootstrapvz/base/manifest.py +++ b/bootstrapvz/base/manifest.py @@ -3,7 +3,7 @@ to determine which tasks should be added to the tasklist, what arguments various invocations should have etc.. .. module:: manifest """ -from bootstrapvz.common.tools import load_json +from bootstrapvz.common.tools import load_json, load_yaml import logging log = logging.getLogger(__name__) @@ -34,7 +34,11 @@ class Manifest(object): """ # Load the manifest JSON using the loader in common.tools # It strips comments (which are invalid in strict json) before loading the data. - self.data = load_json(self.path) + if self.path.endswith('.json'): + self.data = load_json(self.path) + elif self.path.endswith('.yml') or self.path.endswith('.yaml'): + self.data = load_yaml(self.path) + # Get the provider name from the manifest and load the corresponding module provider_modname = 'bootstrapvz.providers.{provider}'.format(provider=self.data['provider']) log.debug('Loading provider `{modname}\''.format(modname=provider_modname)) diff --git a/bootstrapvz/common/tools.py b/bootstrapvz/common/tools.py index 8721144..d40eaab 100644 --- a/bootstrapvz/common/tools.py +++ b/bootstrapvz/common/tools.py @@ -63,6 +63,10 @@ def load_json(path): with open(path) as stream: return json.loads(json_minify(stream.read(), False)) +def load_yaml(path): + import yaml + with open(path, 'r') as fobj: + return yaml.load(fobj) def config_get(path, config_path): config = load_json(path) diff --git a/manifests/ec2-ebs-debian-testing-amd64-pvm.manifest.yml b/manifests/ec2-ebs-debian-testing-amd64-pvm.manifest.yml new file mode 100644 index 0000000..43f44b0 --- /dev/null +++ b/manifests/ec2-ebs-debian-testing-amd64-pvm.manifest.yml @@ -0,0 +1,36 @@ +--- +provider: "ec2" +virtualization: "pvm" +credentials: + access-key: null + secret-key: null +bootstrapper: + workspace: "/target" +image: + name: "debian-{system.release}-{system.architecture}-{virtualization}-{%Y}-{%m}-{%d}-ebs" + description: "Debian {system.release} {system.architecture}" +system: + release: "testing" + architecture: "amd64" + bootloader: "pvgrub" + timezone: "UTC" + locale: "en_US" + charmap: "UTF-8" +packages: + #mirror: "http://cloudfront.debian.net/debian" + install_standard: true +volume: + backing: "ebs" + partitions: + type: "none" + root: + size: "8GiB" + filesystem: "ext4" +plugins: + cloud_init: + username: "admin" + #metadata_sources: "Ec2" + disable_modules: + - "landscape" + - "byobu" + - "ssh-import-id" From df6f190a6a6d4d60adf1cf07acde4fa83c52036e Mon Sep 17 00:00:00 2001 From: Rory Finnegan Date: Tue, 8 Apr 2014 14:33:40 +0000 Subject: [PATCH 2/4] Fixed import style. --- bootstrapvz/base/manifest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bootstrapvz/base/manifest.py b/bootstrapvz/base/manifest.py index 6bca3eb..370f952 100644 --- a/bootstrapvz/base/manifest.py +++ b/bootstrapvz/base/manifest.py @@ -3,7 +3,8 @@ to determine which tasks should be added to the tasklist, what arguments various invocations should have etc.. .. module:: manifest """ -from bootstrapvz.common.tools import load_json, load_yaml +from bootstrapvz.common.tools import load_json +from bootstrapvz.common.tools import load_yaml import logging log = logging.getLogger(__name__) From 338465c2b7337046f43063d8feef8025e2491d1e Mon Sep 17 00:00:00 2001 From: Rory Finnegan Date: Tue, 8 Apr 2014 15:21:23 +0000 Subject: [PATCH 3/4] Added pyyaml to setup.py. --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 9bc5358..a3e61ca 100644 --- a/setup.py +++ b/setup.py @@ -19,6 +19,7 @@ setup(name='bootstrap-vz', install_requires=['termcolor >= 1.1.0', 'fysom >= 1.0.15', 'jsonschema >= 2.3.0', + 'pyyaml >= 3.10', ], license='Apache License, Version 2.0', description='Bootstrap Debian images for virtualized environments', From 60571f66adeaaccc097a94054bc2579fd9724788 Mon Sep 17 00:00:00 2001 From: Rory Finnegan Date: Tue, 8 Apr 2014 11:56:27 -0500 Subject: [PATCH 4/4] Fixed formatting standards on files I've changed. Used command `find . -name '*.py' | grep -v minify_json | xargs pep8 --ignore=E101,E221,E241,E501,W191` --- bootstrapvz/common/tools.py | 6 ++++-- setup.py | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/bootstrapvz/common/tools.py b/bootstrapvz/common/tools.py index d40eaab..f392f35 100644 --- a/bootstrapvz/common/tools.py +++ b/bootstrapvz/common/tools.py @@ -63,18 +63,21 @@ def load_json(path): with open(path) as stream: return json.loads(json_minify(stream.read(), False)) + def load_yaml(path): import yaml with open(path, 'r') as fobj: return yaml.load(fobj) + def config_get(path, config_path): config = load_json(path) for key in config_path: config = config.get(key) return config -def copy_tree(from_path,to_path): + +def copy_tree(from_path, to_path): from shutil import copy import os for abs_prefix, dirs, files in os.walk(from_path): @@ -90,4 +93,3 @@ def copy_tree(from_path,to_path): for path in files: copy(os.path.join(abs_prefix, path), os.path.join(to_path, prefix, path)) - diff --git a/setup.py b/setup.py index a3e61ca..20d6568 100644 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ setup(name='bootstrap-vz', install_requires=['termcolor >= 1.1.0', 'fysom >= 1.0.15', 'jsonschema >= 2.3.0', - 'pyyaml >= 3.10', + 'pyyaml >= 3.10', ], license='Apache License, Version 2.0', description='Bootstrap Debian images for virtualized environments',