blob: 20874d60334e81645c92ea8939cf4827adce76cd [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 Dmitriev94239b12017-06-23 13:18:38 +03005#import salt.cli.call
6#import salt.cli.caller
Dennis Dmitriev1110ac52017-06-22 21:07:37 +03007
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
Dennis Dmitriev94239b12017-06-23 13:18:38 +030024#def 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
Dennis Dmitriev1110ac52017-06-22 21:07:37 +030034
35
Dennis Dmitriev94239b12017-06-23 13:18:38 +030036def inventory_list(domain=None):
Dennis Dmitriev1110ac52017-06-22 21:07:37 +030037 core = get_core()
38 inventory = core.inventory()
39 nodes_list = inventory['nodes'].keys()
Dennis Dmitriev94239b12017-06-23 13:18:38 +030040 if domain is not None:
41 #domain = get_minion_domain()
42 nodes_list = [node for node in nodes_list if node.endswith(domain)]
Dennis Dmitriev1110ac52017-06-22 21:07:37 +030043 print('\n'.join(sorted(nodes_list)))