Browse Source

Added support for salt engines, added support for requisite ordering

Change-Id: I772495c38ed5dc21ad833f3c0f351384942e2b23
pull/69/head
Ales Komarek 7 years ago
parent
commit
8f8eee7680
4 changed files with 97 additions and 2 deletions
  1. +1
    -1
      _engines/saltgraph.py
  2. +75
    -0
      _modules/modelutils.py
  3. +5
    -0
      salt/files/_engine.conf
  4. +16
    -1
      salt/master/env.sls

+ 1
- 1
_engines/saltgraph.py View File

opts=__opts__, opts=__opts__,
sock_dir=__opts__['sock_dir'], sock_dir=__opts__['sock_dir'],
listen=True) listen=True)
log.debug('Saltgraph engine started')
log.debug('Saltgraph engine started')


while True: while True:
event = event_bus.get_event() event = event_bus.get_event()

+ 75
- 0
_modules/modelutils.py View File


from collections import OrderedDict


def __virtual__():
return True


def _set_subtree(node, relationships):
return {
v: _set_subtree(v, relationships)
for v in [x['id'] for x in relationships if node in x['require']]
}


def _traverse_subtree(output, data):
for key, value in data.items():
output.append(key)
_traverse_subtree(output, value)
return output


def order_by_requisites(data):
'''
Returns dictionary ordered by require and require_by

CLI Examples:

.. code-block:: bash

salt-call modelutils.order_by_requisites "{'dict':'value'}""

Sample data

passed_data:
syslog2:
pattern: 'syslog.*'
syslog_tele1:
type: parser
require:
- syslog1
syslog1:
pattern: 'syslog.*'
require_in:
- syslog2
syslog_tele2:
require:
- syslog_tele1

'''
raw_key_list = []
ordered_key_list = []
output_dict = OrderedDict()

for datum_id, datum in data.items():
if 'require_in' in datum:
for req in datum['require_in']:
if 'require' not in data[req]:
data[req]['require'] = []
data[req]['require'].append(datum_id)
datum.pop('require_in')

for datum_id, datum in data.items():
if 'require' not in datum:
datum['require'] = ['top']
datum['id'] = datum_id
raw_key_list.append(datum)

tree_data = _set_subtree('top', raw_key_list)
_traverse_subtree(ordered_key_list, tree_data)
for key in ordered_key_list:
output_dict[key] = data[key]

return output_dict


+ 5
- 0
salt/files/_engine.conf View File

{% from "salt/map.jinja" import master with context %} {% from "salt/map.jinja" import master with context %}


engines_dirs:
{%- for environment_name, environment in master.get('environment', {}).iteritems() %}
- /srv/salt/env/{{ environment_name }}/_engines
{%- endfor %}

engines: engines:
{%- for engine_name, engine in master.engine.items() %} {%- for engine_name, engine in master.engine.items() %}
{%- set name = engine.get('engine', engine_name) %} {%- set name = engine.get('engine', engine_name) %}

+ 16
- 1
salt/master/env.sls View File

- /usr/share/salt-formulas/env/_states - /usr/share/salt-formulas/env/_states
- /usr/share/salt-formulas/env/_grains - /usr/share/salt-formulas/env/_grains
- /usr/share/salt-formulas/env/_formulas - /usr/share/salt-formulas/env/_formulas
- /usr/share/salt-formulas/env/_engines
- /usr/share/salt-formulas/env/_runners
- makedirs: True - makedirs: True


salt_env_{{ environment_name }}_dirs: salt_env_{{ environment_name }}_dirs:
- /srv/salt/env/{{ environment_name }}/_states - /srv/salt/env/{{ environment_name }}/_states
- /srv/salt/env/{{ environment_name }}/_grains - /srv/salt/env/{{ environment_name }}/_grains
- /srv/salt/env/{{ environment_name }}/_formulas - /srv/salt/env/{{ environment_name }}/_formulas
- /srv/salt/env/{{ environment_name }}/_engines
- /srv/salt/env/{{ environment_name }}/_runners
- makedirs: True - makedirs: True


{%- endif %} {%- endif %}


{%- for engine_name, engine in formula.get('engine', {}).iteritems() %} {%- for engine_name, engine in formula.get('engine', {}).iteritems() %}


salt_master_{{ environment_name }}_{{ engine_name }}_state:
salt_master_{{ environment_name }}_{{ engine_name }}_engine:
file.symlink: file.symlink:
- name: /srv/salt/env/{{ environment_name }}/_engines/{{ engine_name }} - name: /srv/salt/env/{{ environment_name }}/_engines/{{ engine_name }}
- target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_engines/{{ engine_name }} - target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_engines/{{ engine_name }}


{%- endfor %} {%- endfor %}


{%- for runner_name, runner in formula.get('runner', {}).iteritems() %}

salt_master_{{ environment_name }}_{{ runner_name }}_runner:
file.symlink:
- name: /srv/salt/env/{{ environment_name }}/_engines/{{ runner_name }}
- target: /srv/salt/env/{{ environment_name }}/_formulas/{{ formula_name }}/_engines/{{ runner_name }}
- force: True
- makedirs: True

{%- endfor %}

{%- endif %} {%- endif %}


{%- endif %} {%- endif %}

Loading…
Cancel
Save