项目作者: wils0ns

项目描述 :
Saltstack API wrapper and state return parser.
高级语言: Python
项目地址: git://github.com/wils0ns/saltypie.git
创建时间: 2020-08-28T08:44:45Z
项目社区:https://github.com/wils0ns/saltypie

开源协议:MIT License

下载


Saltypie - salt-api client and state return parser.

Installation

  1. pip install saltypie

Local client example

Code:

  1. from saltypie import Salt
  2. from saltypie.output import StateOutput
  3. salt = Salt(
  4. url='https://192.168.70.11:8000',
  5. username='saltapiuser',
  6. passwd='abc123',
  7. trust_host=True
  8. )
  9. ret = salt.execute(
  10. client=Salt.CLIENT_LOCAL,
  11. target='*',
  12. fun='state.apply',
  13. pillar={'sleep': 1}
  14. )
  15. sout = StateOutput(ret)
  16. print(sout)

Output:

  1. + minion01 ---------------------------------------------------------+
  2. | State Plot % ms Result |
  3. +-------------------------------------------------------------------+
  4. | test succeed with changes |||||||||||| 42.13% 0.404 True |
  5. | test succeed without changes |||||||| 29.61% 0.284 True |
  6. | test no operation |||||||| 28.26% 0.271 True |
  7. +-------------------------------------------------------------------+
  8. | Total elapsed time: 0.96ms |
  9. +-------------------------------------------------------------------+

Runner client example

Code:

  1. from saltypie import Salt
  2. from saltypie.output import OrchestrationOutput
  3. salt = Salt(
  4. url='https://192.168.70.10:8000',
  5. username='saltapiuser',
  6. passwd='abc123',
  7. trust_host=True
  8. )
  9. salt.eauth = 'pam'
  10. ret = salt.execute(
  11. client=Salt.CLIENT_RUNNER,
  12. fun='state.orch',
  13. args=['orch_fail'],
  14. pillar={'sleep': 1}
  15. )
  16. orchout = OrchestrationOutput(ret, salt)
  17. print(orchout.summary_table(max_bar_size=100, time_unit='s'))

Output:

  1. + Orchestration -----------------------------------------------------------------+
  2. | Step Plot % Time(s) Result |
  3. +--------------------------------------------------------------------------------+
  4. | Step01 ||||||||||||||||||||||||| 25.20% 5.13 True |
  5. | Step02 |||||||||||||||||||||||| 24.69% 5.03 True |
  6. | Step03 |||||||||||||||||||||||| 24.79% 5.05 True |
  7. | Step04 ||||||||||||||||||||||||| 25.32% 5.16 False |
  8. +--------------------------------------------------------------------------------+
  9. | Total elapsed time: 20.37s |
  10. +--------------------------------------------------------------------------------+

Terminal safe mode

All output classes have the safe property that is set to False if the terminal encoding is dectected to be utf-8. To always use safe mode set it to True:

Example:

  1. from saltypie import Salt
  2. from saltypie.output import StateOutput, OrchestrationOutput
  3. sout = StateOutput(ret)
  4. sout.safe = True
  5. # play with the tables here ...
  6. orchout = OrchestrationOutput(ret, salt)
  7. orchout.safe = True
  8. # play with the tables here ...

Disable table coloring

Set the output object colored property to False:

Example:

  1. from saltypie import Salt
  2. from saltypie.output import OrchestrationOutput
  3. orchout = OrchestrationOutput(ret, salt)
  4. orchout.colored = False
  5. # play with the tables here ...

More examples

https://gitlab.com/cathaldallan/saltypie/tree/master/examples

Documentation

https://cathaldallan.gitlab.io/saltypie/