New command 'add-key'
also, fixed pep8
Change-Id: I526083d72b50dc99b7e945db8d3e95ddbb81459f
diff --git a/reclass_tools/create_inventory.py b/reclass_tools/create_inventory.py
index a8e048b..8bb5840 100644
--- a/reclass_tools/create_inventory.py
+++ b/reclass_tools/create_inventory.py
@@ -1,13 +1,25 @@
-import yaml
-import json
-import sys
+# Copyright 2013 - 2017 Mirantis, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
-from cookiecutter import generate
+import sys
+import yaml
+
from cookiecutter.exceptions import UndefinedVariableInTemplate
+from cookiecutter import generate
from reclass_tools import helpers
from reclass_tools import reclass_models
-from reclass_tools import walk_models
def create_inventory_context(domain=None, keys=None):
@@ -35,10 +47,12 @@
"""
inventory = reclass_models.inventory_list(domain=domain)
vcp_list = reclass_models.vcp_list(domain=domain, inventory=inventory)
- reclass_storage = reclass_models.reclass_storage(domain=domain, inventory=inventory)
+ reclass_storage = reclass_models.reclass_storage(domain=domain,
+ inventory=inventory)
if domain is None:
- sys.exit("Error: please specify a domain name from: \n{}".format('\n'.join(reclass_storage.keys())))
+ sys.exit("Error: please specify a domain name from: \n{}"
+ .format('\n'.join(reclass_storage.keys())))
for storage_domain, storage_nodes in reclass_storage.items():
if storage_domain != domain:
@@ -46,7 +60,8 @@
current_cluster_nodes = {}
for storage_node_name, storage_node in storage_nodes.items():
- inventory_node_name = "{0}.{1}".format(storage_node['name'], storage_node['domain'])
+ inventory_node_name = "{0}.{1}".format(storage_node['name'],
+ storage_node['domain'])
current_cluster_nodes[inventory_node_name] = {
'name': storage_node['name'],
'reclass_storage_name': storage_node_name,
@@ -56,7 +71,8 @@
if (storage_node['name'], storage_node['domain']) in vcp_list:
# Add role 'vcp' to mark the VM nodes.
- current_cluster_nodes[inventory_node_name]['roles'].append('vcp')
+ current_cluster_nodes[
+ inventory_node_name]['roles'].append('vcp')
if keys:
# Dump specified parameters for the node
@@ -68,7 +84,10 @@
key_path = key.split('.')
reclass_key = helpers.get_nested_key(node, path=key_path)
if reclass_key:
- helpers.create_nested_key(current_cluster_nodes[inventory_node_name], path=key_path, value=reclass_key)
+ helpers.create_nested_key(
+ current_cluster_nodes[inventory_node_name],
+ path=key_path,
+ value=reclass_key)
current_underlay_context = {
'cookiecutter': {
@@ -131,6 +150,7 @@
undefined_err.context,
default_flow_style=False
)
- print('='*15 + ' Context: '+ '='*15 + '\n{}'.format(context_str) + '='*40)
+ print('=' * 15 + ' Context: ' + '=' * 15 +
+ '\n{}'.format(context_str) + '='*40)
print('>>> {}'.format(undefined_err.message))
sys.exit('>>> Error message: {}'.format(undefined_err.error.message))