首页 > Windows开发 > 详细

salt-satck api使用脚本

时间:2018-09-17 17:24:29      阅读:285      评论:0      收藏:0      [点我收藏+]
#-- coding:utf-8 --

import requests
import json
import urllib3
import sys

#首先获得salt的token
def Get_token():
#准备请求头等各种信息
urllib3.disable_warnings()
URL = ‘https://172.16.185.232/login/
Hander = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36",
"Content-type": "application/json"}
Info = {‘username‘:‘salt‘,‘password‘:‘1P9lS57ZaJ59FFdayuiX‘,‘eauth‘:‘pam‘}
request = requests.post(url=URL,data=Info,verify=False)
response = request.json()
return response[‘return‘][0][‘token‘]

def salt_command():
urllib3.disable_warnings()
tgt = sys.argv[1]
arg = sys.argv[2]
Url = ‘https://172.16.185.232
Hander = {‘X-Auth-Token‘:Get_token()}
Data = {‘client‘: ‘local‘, ‘tgt‘: tgt,‘fun‘: ‘cmd.run‘,‘arg‘:arg}
ret = requests.post(url=Url,data=Data,headers=Hander,verify=False)
print(ret.json())

if name == ‘main‘:
salt_command()

salt-satck api使用脚本

原文:http://blog.51cto.com/2925718/2176013

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!