Ales Komarek | ef0eea3 | 2018-02-14 15:47:13 +0100 | [diff] [blame^] | 1 | # -*- coding: utf-8 -*- |
| 2 | ''' |
| 3 | Salt modules to work with the Architect service. |
| 4 | ''' |
| 5 | |
| 6 | # Import python libs |
| 7 | from __future__ import absolute_import |
| 8 | import yaml |
| 9 | from architect_client.libarchitect import ArchitectClient |
| 10 | import logging |
| 11 | |
| 12 | __virtualname__ = 'architect' |
| 13 | |
| 14 | logger = logging.getLogger(__name__) |
| 15 | |
| 16 | |
| 17 | def __virtual__(): |
| 18 | return __virtualname__ |
| 19 | |
| 20 | |
| 21 | def _client(): |
| 22 | return ArchitectClient() |
| 23 | |
| 24 | |
| 25 | def get_inventory(): |
| 26 | ''' |
| 27 | Get the Architect metadata inventory for given Salt master. |
| 28 | |
| 29 | CLI Examples: |
| 30 | |
| 31 | .. code-block:: bash |
| 32 | |
| 33 | salt-call architect.get_inventory |
| 34 | ''' |
| 35 | data = yaml.load(_client().get_data()) |
| 36 | |
| 37 | return data |
| 38 | |
| 39 | |
| 40 | def get_node(name): |
| 41 | ''' |
| 42 | Get the Architect node metadata for given Salt master. |
| 43 | |
| 44 | CLI Examples: |
| 45 | |
| 46 | .. code-block:: bash |
| 47 | |
| 48 | salt-call architect.get_node node.domain |
| 49 | ''' |
| 50 | |
| 51 | data = yaml.load(_client().get_data(name)) |
| 52 | |
| 53 | return { |
| 54 | name: data |
| 55 | } |
| 56 | |
| 57 | |
| 58 | def collect_minion_info(): |
| 59 | ''' |
| 60 | Get Salt minion metadata and forward it to the Architect master. |
| 61 | |
| 62 | CLI Examples: |
| 63 | |
| 64 | .. code-block:: bash |
| 65 | |
| 66 | salt-call architect.collect_minion_info |
| 67 | ''' |
| 68 | |
| 69 | data = { |
| 70 | 'pillar': __salt__['pillar.data'](), |
| 71 | 'grain': __salt__['grains.items'](), |
| 72 | } |
| 73 | output = _client().push_salt_minion({data['grain']['id']: data}) |
| 74 | return output |