與Python-要求,您可以創建這樣一個功能:
import requests
import os
def accept_salt_clientkey(keyname):
url = 'https://saltmaster:8000'
headers = {'Accept':'application/json'}
login_payload = {'username':'saltuser','password':'saltpasswd','eauth':'pam'}
accept_key_payload = {'fun': 'key.accept','client':'wheel','tgt':'*','match':keyname}
login_request = requests.post(os.path.join(url,'login'),headers=headers,data=login_payload)
request = requests.post(url,headers=headers,data=accept_key_payload,cookies=login_request.cookies)
keytype = request.json()['return'][0]['data']['return']
if keytype:
for key,value in keytype.iteritems():
if value[0] == keyname:
return True
break
else:
raise Exception('{} does not match!'.format(keyname))
else:
raise Exception('{} key does not exist in master until now...'.format(keyname))
,並且可以使用主機名(這應該是鍵名)作爲參數調用它:
accept_salt_clientkey(mynewhost.com)
中當然,您可以將用戶名/密碼存儲在config.py文件中,或根據您將如何調用它的方式以其他方式存儲,但這可能會給您一個大致的想法。