blob: 9f90fa728282fa5bff8548f21b399c8febe4a243 [file] [log] [blame]
Dennis Dmitriev1110ac52017-06-22 21:07:37 +03001import reclass
2from reclass.adapters import salt as reclass_salt
3from reclass import config as reclass_config
4from reclass import core as reclass_core
Dennis Dmitrievde847d92017-06-26 18:58:05 +03005
6from reclass_tools import helpers
Dennis Dmitriev94239b12017-06-23 13:18:38 +03007#import salt.cli.call
8#import salt.cli.caller
Dennis Dmitriev1110ac52017-06-22 21:07:37 +03009
10
11def get_core():
12 """Initializes reclass Core() using /etc/reclass settings"""
13
14 defaults = reclass_config.find_and_read_configfile()
15 inventory_base_uri = defaults['inventory_base_uri']
16 storage_type = defaults['storage_type']
17
18 nodes_uri, classes_uri = reclass_config.path_mangler(inventory_base_uri,
19 None, None)
20 storage = reclass.get_storage(storage_type, nodes_uri, classes_uri,
21 default_environment='base')
22
23 return reclass_core.Core(storage, None, None)
24
25
Dennis Dmitriev94239b12017-06-23 13:18:38 +030026#def get_minion_domain():
27# """Try to get domain from the local salt minion"""
28# client = salt.cli.call.SaltCall()
29# client.parse_args(args=['pillar.items'])
30# caller = salt.cli.caller.Caller.factory(client.config)
31# result = caller.call()
32# # Warning! There is a model-related parameter
33# # TODO: move the path to the parameter to a settings/defaults
34# domain = result['return']['_param']['cluster_domain']
35# return domain
Dennis Dmitriev1110ac52017-06-22 21:07:37 +030036
37
Dennis Dmitriev94239b12017-06-23 13:18:38 +030038def inventory_list(domain=None):
Dennis Dmitriev1110ac52017-06-22 21:07:37 +030039 core = get_core()
Dennis Dmitrievde847d92017-06-26 18:58:05 +030040 inventory = core.inventory()['nodes']
Dennis Dmitriev94239b12017-06-23 13:18:38 +030041 if domain is not None:
Dennis Dmitrievde847d92017-06-26 18:58:05 +030042 inventory = {key:val for (key, val) in inventory.items() if key.endswith(domain)}
43 return inventory
44
45
46def vcp_list(domain=None):
47 """List VCP node names
48
49 Scan all nodes for the object salt.control.cluster.internal.node.XXX.name
50 """
51
52 inventory = inventory_list(domain=domain)
53 vcp_path = 'parameters.salt.control.cluster.internal.node'.split('.')
54
55 vcp_node_names = set()
56
57 for node_name, node in inventory.items():
58 vcp_nodes = helpers.get_nested_key(node, path=vcp_path)
59 if vcp_nodes is not None:
60 for vcp_node_name, vcp_node in vcp_nodes.items():
61 vcp_node_names.add(vcp_node['name'])
62 return vcp_node_names
63
64