浏览代码

Added requests example for salt api

nee2c 4 年之前
父节点
当前提交
90e7e61c5a
共有 1 个文件被更改,包括 27 次插入0 次删除
  1. 27 0
      api/requestsexample.py

+ 27 - 0
api/requestsexample.py

@@ -0,0 +1,27 @@
+import requests
+
+surl = 'https://localhost:32768'
+auth = {'username': 'salt', 'password':'foobar', 'eauth':'sharedsecret'}
+ver = False
+
+with requests.Session() as s:
+    res = s.post(url=f'{surl}/login', json=auth, verify=ver)
+    print(res.text)
+
+
+    resp = s.post('https://localhost:32768', json=[{
+    'client': 'local',
+    'tgt': '*',
+    'fun': 'network.ipaddrs'
+    }],
+    verify=False)
+    print(resp.text)
+
+    resp = s.post('https://localhost:32768', json=[{
+    'client': 'local',
+    'tgt': '*',
+    'fun': 'file.readdir',
+    'arg': ['/etc/']
+    }],
+    verify=False)
+    print(resp.text)