blob: 1bc83de68fa2542ec2cfa5d355e1ea307317b427 [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
5import salt.cli.call
6import salt.cli.caller
7
8
9def get_core():
10 """Initializes reclass Core() using /etc/reclass settings"""
11
12 defaults = reclass_config.find_and_read_configfile()
13 inventory_base_uri = defaults['inventory_base_uri']
14 storage_type = defaults['storage_type']
15
16 nodes_uri, classes_uri = reclass_config.path_mangler(inventory_base_uri,
17 None, None)
18 storage = reclass.get_storage(storage_type, nodes_uri, classes_uri,
19 default_environment='base')
20
21 return reclass_core.Core(storage, None, None)
22
23
24def get_minion_domain():
25 """Try to get domain from the local salt minion"""
26 client = salt.cli.call.SaltCall()
27 client.parse_args(args=['pillar.items'])
28 caller = salt.cli.caller.Caller.factory(client.config)
29 result = caller.call()
30 # Warning! There is a model-related parameter
31 # TODO: move the path to the parameter to a settings/defaults
32 domain = result['return']['_param']['cluster_domain']
33 return domain
34
35
36def inventory_list(all_nodes=False):
37 core = get_core()
38 inventory = core.inventory()
39 nodes_list = inventory['nodes'].keys()
40 if not all_nodes:
41 domain = get_minion_domain()
42 nodes_list = [node for node in nodes_list if domain in node]
43 print('\n'.join(sorted(nodes_list)))