New Saltstack Salt formula
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # -*- coding: utf-8 -*-
  2. """
  3. Salt engine for intercepting state jobs and forwarding to the Architect.
  4. """
  5. # Import python libs
  6. from __future__ import absolute_import
  7. import logging
  8. from architect_client.libarchitect import ArchitectClient
  9. # Import salt libs
  10. import salt.utils.event
  11. logger = logging.getLogger(__name__)
  12. def start(project='default',
  13. host='127.0.0.1',
  14. port=8181,
  15. username=None,
  16. password=None):
  17. '''
  18. Listen to state jobs events and forward state functions and node info
  19. '''
  20. state_functions = ['state.sls', 'state.apply', 'state.highstate']
  21. model_functions = ['architect.node_info']
  22. class_tag = 'architect/minion/classify'
  23. if __opts__['__role'] == 'master':
  24. event_bus = salt.utils.event.get_master_event(__opts__,
  25. __opts__['sock_dir'],
  26. listen=True)
  27. else:
  28. event_bus = salt.utils.event.get_event(
  29. 'minion',
  30. transport=__opts__['transport'],
  31. opts=__opts__,
  32. sock_dir=__opts__['sock_dir'],
  33. listen=True)
  34. logger.info('Architect Engine initialised')
  35. while True:
  36. event = event_bus.get_event()
  37. if event and event.get('fun', None) in state_functions:
  38. is_test_run = 'test=true' in [arg.lower() for arg in event.get('fun_args', [])]
  39. if not is_test_run:
  40. output = ArchitectClient().push_event(event)
  41. logger.info("Sent Architect state function {}".format(output))
  42. if event and event.get('fun', None) in model_functions:
  43. output = ArchitectClient().push_node_info({event['id']: event['return']})
  44. logger.info("Sent Architect node info function {}".format(output))
  45. if event and event.get('tag', None) == class_tag:
  46. output = ArchitectClient().classify_node({
  47. 'name': event['id'],
  48. 'data': event['data']
  49. })
  50. logger.info("Sent Architect node classification {}".format(output))