Use a separated option '--env-name' to render a new environment
Change-Id: I3bfa9dc52f141d0d5ab5d372eea63799eacb12ab
diff --git "a/examples/environment/\173\173 cookiecutter.cluster_name \175\175/common.yml" "b/examples/environment/\173\173 _environment_name \175\175/common.yml"
similarity index 100%
rename from "examples/environment/\173\173 cookiecutter.cluster_name \175\175/common.yml"
rename to "examples/environment/\173\173 _environment_name \175\175/common.yml"
diff --git "a/examples/environment/\173\173 cookiecutter.cluster_name \175\175/init.yml" "b/examples/environment/\173\173 _environment_name \175\175/init.yml"
similarity index 93%
rename from "examples/environment/\173\173 cookiecutter.cluster_name \175\175/init.yml"
rename to "examples/environment/\173\173 _environment_name \175\175/init.yml"
index 6153a6b..ca63bc4 100644
--- "a/examples/environment/\173\173 cookiecutter.cluster_name \175\175/init.yml"
+++ "b/examples/environment/\173\173 _environment_name \175\175/init.yml"
@@ -19,5 +19,5 @@
{{ toyaml( node['parameters']['linux']['network']['interface'], width=14 ) }}
{%- endif %}
classes:
- - environment.{{ cookiecutter.cluster_name }}.common
+ - environment.{{ _environment_name }}.common
{%- endfor %}
diff --git a/reclass_tools/cli.py b/reclass_tools/cli.py
index c696400..864ba7b 100644
--- a/reclass_tools/cli.py
+++ b/reclass_tools/cli.py
@@ -109,7 +109,8 @@
create_inventory.render_dir(template_dir=self.params.template_dir,
output_dir=self.params.output_dir,
- contexts=self.params.contexts)
+ contexts=self.params.contexts,
+ env_name=self.params.env_name)
def get_params(self):
@@ -140,6 +141,11 @@
help=('Show only the nodes which names are ended with the '
'specified domain, for example: example.local'))
+ env_name_parser = argparse.ArgumentParser(add_help=False)
+ env_name_parser.add_argument(
+ '--env-name', '-e', dest='env_name',
+ help=("Name of the 'environment' to create or use"))
+
vcp_only_parser = argparse.ArgumentParser(add_help=False)
vcp_only_parser.add_argument(
'--vcp-only', dest='vcp_only',
@@ -210,7 +216,7 @@
"node for already generated inventory "
"only!"))
subparsers.add_parser('render',
- parents=[render_parser],
+ parents=[render_parser, env_name_parser],
help=("Render cookiecutter template using "
"multiple metadata sources"))
diff --git a/reclass_tools/create_inventory.py b/reclass_tools/create_inventory.py
index f08fafe..a427c0d 100644
--- a/reclass_tools/create_inventory.py
+++ b/reclass_tools/create_inventory.py
@@ -80,7 +80,7 @@
return current_underlay_context
-def render_dir(template_dir, output_dir, contexts):
+def render_dir(template_dir, output_dir, contexts, env_name):
"""Coockiecutter echancement to use several source JSON files
:param template_dir: directory with templates to render
@@ -89,6 +89,7 @@
that provide the context variables for rendering.
Merge of the files usind update() into a single
dict is in the same order as files in the list.
+ :param env_name: name for new environment that will be created
"""
def toyaml(value, width=0, indentfirst=False):
string = yaml.dump(value, default_flow_style=False)
@@ -114,6 +115,7 @@
merged_context = helpers.merge_nested_objects(merged_context, context)
merged_context['toyaml'] = toyaml
+ merged_context['_environment_name'] = env_name
try:
generate.generate_files(