Skip to content

Commit 8f64bac

Browse files
author
Clark Perkins
committed
Add ability to generate all the blueprints at once
1 parent 048b447 commit 8f64bac

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

stackdio/cli/blueprints/generator.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ def validate(self, template_file):
184184

185185
return unset_vars, set_vars
186186

187-
def generate(self, template_file, var_files=(), variables=None, prompt=False, debug=False):
187+
def generate(self, template_file, var_files=(), variables=None,
188+
prompt=False, debug=False, suppress_warnings=False):
188189
"""
189190
Generate the rendered blueprint and return it as a python dict
190191
@@ -255,14 +256,14 @@ def generate(self, template_file, var_files=(), variables=None, prompt=False, de
255256
# If it is set elsewhere, it's not an issue
256257
optional_vars = optional_vars - set(context)
257258

258-
if null_vars:
259+
if null_vars and not suppress_warnings:
259260
warn_str = '\nWARNING: Null variables (replaced with empty string):\n'
260261
for var in null_vars:
261262
warn_str += ' {0}\n'.format(var)
262263
self.warning(warn_str, 0)
263264

264265
# Print a warning if there's unset optional variables
265-
if optional_vars:
266+
if optional_vars and not suppress_warnings:
266267
warn_str = '\nWARNING: Missing optional variables:\n'
267268
for var in sorted(optional_vars):
268269
warn_str += ' {0}\n'.format(var)

stackdio/cli/mixins/blueprints.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ def list_templates(client):
7474
_recurse_dir(os.path.join(blueprint_dir, 'var_files'), ['yaml', 'yml'])
7575

7676

77-
def _create_single_blueprint(config, template_file, var_files, no_prompt, extra_vars=None):
77+
def _create_single_blueprint(config, template_file, var_files, no_prompt,
78+
extra_vars=None, suppress_warnings=False):
7879
blueprint_dir = os.path.expanduser(config['blueprint_dir'])
7980

8081
gen = BlueprintGenerator([os.path.join(blueprint_dir, 'templates')])
@@ -103,7 +104,8 @@ def _create_single_blueprint(config, template_file, var_files, no_prompt, extra_
103104
return gen.generate(template_file,
104105
final_var_files, # Pass in a list
105106
variables=extra_vars,
106-
prompt=no_prompt)
107+
prompt=no_prompt,
108+
suppress_warnings=suppress_warnings)
107109

108110

109111
@blueprints.command(name='create')
@@ -170,10 +172,19 @@ def create_all_blueprints(client):
170172
raise click.UsageError('Missing \'blueprint_dir\' in config. Please run `configure`.')
171173
mapping = yaml.safe_load(open(os.path.join(blueprint_dir, 'mappings.yaml'), 'r'))
172174

175+
blueprints = client.list_blueprints()
176+
177+
blueprint_titles = [blueprint['title'] for blueprint in blueprints]
178+
173179
for name, vals in mapping.items():
180+
if name in blueprint_titles:
181+
click.secho('Skipping creation of {0}, it already exists.'.format(name), fg='yellow')
182+
continue
183+
174184
try:
175185
bp_json = _create_single_blueprint(client.config, vals['template'],
176-
vals['var_files'], False, {'title': name})
186+
vals['var_files'], False, {'title': name},
187+
suppress_warnings=True)
177188
client.create_blueprint(bp_json)
178189
click.secho('Created blueprint {0}'.format(name), fg='green')
179190
except BlueprintException:

0 commit comments

Comments
 (0)