saltypie-salt api包装器和返回解析器
saltypie的Python项目详细描述
Saltypie-salt api客户端和状态返回解析器
安装
pip install saltypie
本地客户端示例
代码:
fromsaltypieimportSaltfromsaltypie.outputimportStateOutputsalt=Salt(url='https://192.168.70.11:8000',username='saltapiuser',passwd='abc123',trust_host=True)ret=salt.execute(client=Salt.CLIENT_LOCAL,target='*',fun='state.apply',pillar={'sleep':1})sout=StateOutput(ret)print(sout)
输出:
+ minion01 ---------------------------------------------------------+
| State Plot % ms Result |
+-------------------------------------------------------------------+
| test succeed with changes |||||||||||| 42.13% 0.404 True |
| test succeed without changes |||||||| 29.61% 0.284 True |
| test no operation |||||||| 28.26% 0.271 True |
+-------------------------------------------------------------------+
| Total elapsed time: 0.96ms |
+-------------------------------------------------------------------+
Runner客户端示例
代码:
fromsaltypieimportSaltfromsaltypie.outputimportOrchestrationOutputsalt=Salt(url='https://192.168.70.10:8000',username='saltapiuser',passwd='abc123',trust_host=True)salt.eauth='pam'ret=salt.execute(client=Salt.CLIENT_RUNNER,fun='state.orch',args=['orch_fail'],pillar={'sleep':1})orchout=OrchestrationOutput(ret,salt)print(orchout.summary_table(max_bar_size=100,time_unit='s'))
输出:
+ Orchestration -----------------------------------------------------------------+
| Step Plot % Time(s) Result |
+--------------------------------------------------------------------------------+
| Step01 ||||||||||||||||||||||||| 25.20% 5.13 True |
| Step02 |||||||||||||||||||||||| 24.69% 5.03 True |
| Step03 |||||||||||||||||||||||| 24.79% 5.05 True |
| Step04 ||||||||||||||||||||||||| 25.32% 5.16 False |
+--------------------------------------------------------------------------------+
| Total elapsed time: 20.37s |
+--------------------------------------------------------------------------------+
终端安全模式
如果终端编码被检测为utf-8,则所有输出类都具有safe
属性,该属性设置为False
。要始终使用安全模式,请将其设置为True
:
示例:
fromsaltypieimportSaltfromsaltypie.outputimportStateOutput,OrchestrationOutputsout=StateOutput(ret)sout.safe=True# play with the tables here ...orchout=OrchestrationOutput(ret,salt)orchout.safe=True# play with the tables here ...
禁用表格着色
将输出对象colored
属性设置为False
:
示例:
fromsaltypieimportSaltfromsaltypie.outputimportOrchestrationOutputorchout=OrchestrationOutput(ret,salt)orchout.colored=False# play with the tables here ...
更多示例
https://gitlab.com/cathaldallan/saltypie/tree/master/examples
文档
https://cathaldallan.gitlab.io/saltypie/