Add 'create_inventory_context' command
The command 'create_inventory_context' can be used to dump all the
nodes from reclass inventory, they names from recalss.storage,
and any additional keys from nodes if needed, for example:
$ reclass-create-inventory-context \
-d mcp11-ovs-dpdk.local \
parameters.linux.network.interface \
parameters.linux.storage
diff --git a/reclass_tools/cli.py b/reclass_tools/cli.py
index 48e3d9f..1bd80b7 100644
--- a/reclass_tools/cli.py
+++ b/reclass_tools/cli.py
@@ -105,6 +105,7 @@
help=('Show only the nodes which names are ended with the specified domain, for example:'
' reclass-inventory-list -d example.local'))
+
params = parser.parse_args(args)
inventory = reclass_models.inventory_list(domain=params.domain)
@@ -127,5 +128,27 @@
params = parser.parse_args(args)
vcp_node_names = reclass_models.vcp_list(domain=params.domain)
- print('\n'.join(sorted(vcp_node_names)))
+ print('\n'.join(sorted(('{0}.{1}'.format(name, domain) for name, domain in vcp_node_names))))
+
+
+def create_inventory_context(args=None):
+ try:
+ from reclass_tools import create_inventory
+ except ImportError:
+ print("Please run this tool on the salt-master node with installed 'reclass'")
+ return
+
+ parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter,
+ description="Dumps nodes and specified node parameters from reclass, for example: create_inventory_context -d example.local parameters.linux.network.interface parameters.linux.storage")
+ parser.add_argument('--domain', '-d', dest='domain',
+ help=('Show only the nodes which names are ended with the specified domain, for example:'
+ ' reclass-inventory-list -d example.local'))
+ parser.add_argument('keys', help=(
+ 'Reclass key names to dump with nodes'), nargs='*')
+
+ params = parser.parse_args(args)
+
+ current_underlay_context = create_inventory.create_inventory_context(domain=params.domain, keys=params.keys)
+
+ print(yaml.dump(current_underlay_context, default_flow_style=False))