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 | de847d9 | 2017-06-26 18:58:05 +0300 | [diff] [blame^] | 5 | |
| 6 | from reclass_tools import helpers |
Dennis Dmitriev | 94239b1 | 2017-06-23 13:18:38 +0300 | [diff] [blame] | 7 | #import salt.cli.call |
| 8 | #import salt.cli.caller |
Dennis Dmitriev | 1110ac5 | 2017-06-22 21:07:37 +0300 | [diff] [blame] | 9 | |
| 10 | |
| 11 | def 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 Dmitriev | 94239b1 | 2017-06-23 13:18:38 +0300 | [diff] [blame] | 26 | #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 Dmitriev | 1110ac5 | 2017-06-22 21:07:37 +0300 | [diff] [blame] | 36 | |
| 37 | |
Dennis Dmitriev | 94239b1 | 2017-06-23 13:18:38 +0300 | [diff] [blame] | 38 | def inventory_list(domain=None): |
Dennis Dmitriev | 1110ac5 | 2017-06-22 21:07:37 +0300 | [diff] [blame] | 39 | core = get_core() |
Dennis Dmitriev | de847d9 | 2017-06-26 18:58:05 +0300 | [diff] [blame^] | 40 | inventory = core.inventory()['nodes'] |
Dennis Dmitriev | 94239b1 | 2017-06-23 13:18:38 +0300 | [diff] [blame] | 41 | if domain is not None: |
Dennis Dmitriev | de847d9 | 2017-06-26 18:58:05 +0300 | [diff] [blame^] | 42 | inventory = {key:val for (key, val) in inventory.items() if key.endswith(domain)} |
| 43 | return inventory |
| 44 | |
| 45 | |
| 46 | def 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 | |