本模块用于调用Salt-api功能,内容如下
#!/usr/bin/python
# -*- coding: utf-8 -*-
import pycurl
import StringIO
#登录salt-api,获取token
def api_login():
global token
url='https://192.168.90.62:8000/login'
ch=pycurl.Curl() #创建一个pycurl对象的方法
ch.setopt(ch.URL, url) #设置要访问的url
info = StringIO.StringIO()
ch.setopt(ch.WRITEFUNCTION, info.write)
ch.setopt(ch.POST, True)
#如果是https就要开启这两行
ch.setopt(ch.SSL_VERIFYPEER, 0)
ch.setopt(ch.SSL_VERIFYHOST, 2)
ch.setopt(ch.HTTPHEADER, ['Accept: application/x-yaml'])
ch.setopt(ch.POSTFIELDS, 'username=saltapi&password=111111&eauth=pam')
#要包头信息
#ch.setopt(ch.HEADER, True)
#不要包头信息
ch.setopt(ch.HEADER,False)
ch.perform()
html = info.getvalue()
#提取token
token = html.split("\n")[-3].replace("\n", &