Dennis Dmitriev | 1110ac5 | 2017-06-22 21:07:37 +0300 | [diff] [blame] | 1 | import reclass |
| 2 | from reclass.adapters import salt as reclass_salt |
| 3 | from reclass import config as reclass_config |
| 4 | from reclass import core as reclass_core |
Dennis Dmitriev | 94239b1 | 2017-06-23 13:18:38 +0300 | [diff] [blame^] | 5 | #import salt.cli.call |
| 6 | #import salt.cli.caller |
Dennis Dmitriev | 1110ac5 | 2017-06-22 21:07:37 +0300 | [diff] [blame] | 7 | |
| 8 | |
| 9 | def 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 Dmitriev | 94239b1 | 2017-06-23 13:18:38 +0300 | [diff] [blame^] | 24 | #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 Dmitriev | 1110ac5 | 2017-06-22 21:07:37 +0300 | [diff] [blame] | 34 | |
| 35 | |
Dennis Dmitriev | 94239b1 | 2017-06-23 13:18:38 +0300 | [diff] [blame^] | 36 | def inventory_list(domain=None): |
Dennis Dmitriev | 1110ac5 | 2017-06-22 21:07:37 +0300 | [diff] [blame] | 37 | core = get_core() |
| 38 | inventory = core.inventory() |
| 39 | nodes_list = inventory['nodes'].keys() |
Dennis Dmitriev | 94239b1 | 2017-06-23 13:18:38 +0300 | [diff] [blame^] | 40 | if domain is not None: |
| 41 | #domain = get_minion_domain() |
| 42 | nodes_list = [node for node in nodes_list if node.endswith(domain)] |
Dennis Dmitriev | 1110ac5 | 2017-06-22 21:07:37 +0300 | [diff] [blame] | 43 | print('\n'.join(sorted(nodes_list))) |