Bläddra i källkod

SaltStack - Architect integration

Change-Id: I96e16a3b203f9b3c9c150db1cb85e966bd14b573
pull/73/head
Ales Komarek 6 år sedan
förälder
incheckning
459407bb30
5 ändrade filer med 127 tillägg och 1 borttagningar
  1. +30
    -1
      README.rst
  2. +62
    -0
      _engines/architect.py
  3. +8
    -0
      salt/files/architect.yml
  4. +8
    -0
      salt/files/master.conf
  5. +19
    -0
      salt/master/pillar.sls

+ 30
- 1
README.rst Visa fil

@@ -28,6 +28,21 @@ Salt master with reclass ENC metadata backend
.. literalinclude:: tests/pillar/master_single_reclass.sls
:language: yaml

Salt master with Architect ENC metadata backend

.. code-block:: yaml

salt:
master:
enabled: true
pillar:
engine: architect
project: project-name
host: architect-api
port: 8181
username: salt
password: password

Salt master with multiple ext_pillars

.. literalinclude:: tests/pillar/master_single_extpillars.sls
@@ -150,7 +165,6 @@ Salt master with logging handlers
host: 127.0.0.1
port: 9999


Salt engine definition for saltgraph metadata collector

.. code-block:: yaml
@@ -166,6 +180,21 @@ Salt engine definition for saltgraph metadata collector
password: salt
database: salt

Salt engine definition for Architect service

.. code-block:: yaml

salt:
master:
engine:
architect:
engine: architect
project: project-name
host: architect-api
port: 8181
username: salt
password: password

Salt engine definition for sending events from docker events

.. code-block:: yaml

+ 62
- 0
_engines/architect.py Visa fil

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

# Import python libs
from __future__ import absolute_import
import json
import logging

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

log = logging.getLogger(__name__)


def start(project='default',
host='127.0.0.1',
port=8181,
username=None,
password=None):
'''
Listen to state jobs events and forward Salt states
'''
url = "{}://{}:{}/salt/{}/event/{}".format('http',
host,
port,
'v1',
project)
target_functions = ['state.sls', 'state.apply', 'state.highstate']

if __opts__['__role'] == 'master':
event_bus = salt.utils.event.get_master_event(__opts__,
__opts__['sock_dir'],
listen=True)
else:
event_bus = salt.utils.event.get_event(
'minion',
transport=__opts__['transport'],
opts=__opts__,
sock_dir=__opts__['sock_dir'],
listen=True)

log.info('Salt Architect engine initialised')

while True:
event = event_bus.get_event()
if event and event.get('fun', None) in target_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))

+ 8
- 0
salt/files/architect.yml Visa fil

@@ -0,0 +1,8 @@
{% from "salt/map.jinja" import master with context %}
project: {{ master.pillar.project }}
host: {{ master.pillar.host }}
port: {{ master.pillar.port }}
{%- if master.pillar.username is defined %}
username: {{ master.pillar.username }}
password: {{ master.pillar.password }}
{%- endif %}

+ 8
- 0
salt/files/master.conf Visa fil

@@ -60,6 +60,14 @@ pillar_roots:
- {{ master.pillar.get('salt', {}).get('path', '/srv/salt/pillar') }}
{%- endif %}

{%- if master.pillar.engine == 'architect' %}
ext_pillar:
- cmd_yaml: 'architect-salt-pillar %s'

master_tops:
ext_nodes: architect-salt-top
{%- endif %}

{%- if master.pillar.engine == 'reclass' or (master.pillar.engine == 'composite' and master.pillar.reclass is defined) %}

reclass: &reclass

+ 19
- 0
salt/master/pillar.sls Visa fil

@@ -31,6 +31,25 @@ include:

{%- endif %}

{%- elif master.pillar.engine == 'architect' %}

salt_pillar_architect_package:
pip.installed:
- name: architect-client

salt_pillar_architect_package_config_dir:
file.directory:
- name: /etc/architect

salt_pillar_architect_package_config_file:
file.managed:
- name: /etc/architect/client.yml
- source: salt://salt/files/architect.yml
- user: root
- template: jinja
- require:
- file: salt_pillar_architect_package_config_dir

{%- elif master.pillar.engine == 'reclass' %}

include:

Laddar…
Avbryt
Spara