Sfoglia il codice sorgente

Updated Arch engine and modules

Change-Id: I6f206ad2af8cc2664c1f1fa315833d9502c34851
pull/73/head
Ales Komarek 6 anni fa
parent
commit
c312a291d0
2 ha cambiato i file con 47 aggiunte e 36 eliminazioni
  1. +20
    -24
      _engines/architect.py
  2. +27
    -12
      _modules/architect.py

+ 20
- 24
_engines/architect.py Vedi File

@@ -1,19 +1,17 @@
# -*- coding: utf-8 -*-
"""
Salt engine for intercepting state jobs and forwarding to the Architect
service.
Salt engine for intercepting state jobs and forwarding to the Architect.
"""

# Import python libs
from __future__ import absolute_import
import json
import logging
from architect_client.libarchitect import ArchitectClient

# Import salt libs
import salt.utils.event
import salt.utils.http

log = logging.getLogger(__name__)
logger = logging.getLogger(__name__)


def start(project='default',
@@ -22,14 +20,11 @@ def start(project='default',
username=None,
password=None):
'''
Listen to state jobs events and forward Salt states
Listen to state jobs events and forward state functions and node info
'''
url = "{}://{}:{}/salt/{}/event/{}".format('http',
host,
port,
'v1',
project)
target_functions = ['state.sls', 'state.apply', 'state.highstate']
state_functions = ['state.sls', 'state.apply', 'state.highstate']
model_functions = ['architect.node_info']
class_tag = 'architect/minion/classify'

if __opts__['__role'] == 'master':
event_bus = salt.utils.event.get_master_event(__opts__,
@@ -43,20 +38,21 @@ def start(project='default',
sock_dir=__opts__['sock_dir'],
listen=True)

log.info('Salt Architect engine initialised')
logger.info('Architect Engine initialised')

while True:
event = event_bus.get_event()
if event and event.get('fun', None) in target_functions:
if event and event.get('fun', None) in state_functions:
is_test_run = 'test=true' in [arg.lower() for arg in event.get('fun_args', [])]
if not is_test_run:
data = salt.utils.http.query(url=url,
method='POST',
decode=False,
data=json.dumps(event))
if 'OK' in data.get('body', ''):
log.info("Architect Engine request to '{}'"
" was successful".format(url))
else:
log.warning("Problem with Architect Engine"
" request to '{}' ({})".format(url, data))
output = ArchitectClient().push_event(event)
logger.info("Sent Architect state function {}".format(output))
if event and event.get('fun', None) in model_functions:
output = ArchitectClient().push_node_info({event['id']: event['return']})
logger.info("Sent Architect node info function {}".format(output))
if event and event.get('tag', None) == class_tag:
output = ArchitectClient().classify_node({
'name': event['id'],
'data': event['data']
})
logger.info("Sent Architect node classification {}".format(output))

+ 27
- 12
_modules/architect.py Vedi File

@@ -6,8 +6,8 @@ Salt modules to work with the Architect service.
# Import python libs
from __future__ import absolute_import
import yaml
from architect_client.libarchitect import ArchitectClient
import logging
from architect_client.libarchitect import ArchitectClient

__virtualname__ = 'architect'

@@ -22,30 +22,30 @@ def _client():
return ArchitectClient()


def get_inventory():
def inventory():
'''
Get the Architect metadata inventory for given Salt master.
Get the Architect metadata inventory

CLI Examples:

.. code-block:: bash

salt-call architect.get_inventory
salt-call architect.inventory
'''
data = yaml.load(_client().get_data())

return data


def get_node(name):
def node_pillar(name):
'''
Get the Architect node metadata for given Salt master.
Get the Architect node pillar for given Salt master.

CLI Examples:

.. code-block:: bash

salt-call architect.get_node node.domain
salt-call architect.node_pillar node.domain
'''

data = yaml.load(_client().get_data(name))
@@ -55,21 +55,36 @@ def get_node(name):
}


def collect_minion_info():
def node_classify(name, data={}):
'''
Get Salt minion metadata and forward it to the Architect master.
CLassify node by given dictionary of parameters

CLI Examples:

.. code-block:: bash

salt-call architect.collect_minion_info
salt-call architect.node_classify minion.net {'param1': 'value2'}
'''
output = _client().classify_node({
'name': name,
'data': data
})
return output


def node_info():
'''
Get Salt minion metadata and forward it to the Architect master.

CLI Examples:

.. code-block:: bash

salt-call architect.minion_info
'''
data = {
'pillar': __salt__['pillar.data'](),
'grain': __salt__['grains.items'](),
'lowstate': __salt__['state.show_lowstate'](),
}
output = _client().push_salt_minion({data['grain']['id']: data})
return output
return data

Loading…
Annulla
Salva