Skip to content

Commit 786c340

Browse files
author
Clark Perkins
committed
Merged in 0.7
2 parents 57f8e6f + 82a76ec commit 786c340

File tree

5 files changed

+70
-7
lines changed

5 files changed

+70
-7
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:

stackdio/client/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@
3535
from .region import RegionMixin
3636
from .settings import SettingsMixin
3737
from .stack import StackMixin
38+
from .snapshot import SnapshotMixin
3839

3940
logger = logging.getLogger(__name__)
4041
logger.addHandler(logging.NullHandler())
4142

4243

4344
class StackdioClient(BlueprintMixin, FormulaMixin, AccountMixin, ImageMixin,
44-
RegionMixin, StackMixin, SettingsMixin, HttpMixin):
45+
RegionMixin, StackMixin, SettingsMixin, SnapshotMixin, HttpMixin):
4546

4647
def __init__(self, url=None, username=None, password=None, verify=None, cfg_file=None):
4748
self.config = StackdioConfig(cfg_file)

stackdio/client/blueprint.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ def get_blueprint(self, blueprint_id):
6767
def delete_blueprint(self, blueprint_id):
6868
pass
6969

70+
@get('blueprints/{blueprint_id}/host_definitions/', paginate=True)
71+
def get_blueprint_host_definitions(self, blueprint_id):
72+
pass
73+
74+
@get('blueprints/{blueprint_id}/properties/')
75+
def get_blueprint_properties(self, blueprint_id):
76+
pass
77+
7078
@put('blueprints/{blueprint_id}/properties/')
7179
def update_blueprint_properties(self, blueprint_id, properties):
7280
return properties

stackdio/client/snapshot.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright 2014, Digital Reasoning
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
from .http import HttpMixin, get, post, delete
19+
20+
21+
class SnapshotMixin(HttpMixin):
22+
23+
@post('cloud/snapshots/')
24+
def create_snapshot(self, snapshot):
25+
"""Create a snapshot"""
26+
return snapshot
27+
28+
@get('cloud/snapshots/', paginate=True)
29+
def list_snapshots(self):
30+
pass
31+
32+
@get('cloud/snapshots/{snapshot_id}/')
33+
def get_snapshot(self, snapshot_id):
34+
pass
35+
36+
@get('cloud/snapshots/', paginate=True)
37+
def search_snapshots(self, **kwargs):
38+
pass
39+
40+
@delete('cloud/snapshots/{snapshot_id}/')
41+
def delete_snapshot(self, snapshot_id):
42+
pass

0 commit comments

Comments
 (0)