-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-3.py
55 lines (41 loc) · 1.25 KB
/
test-3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
import requests
import getpass
import json
import urllib3
#Disable Security warning
urllib3.disable_warnings()
# Define HOST, Username & Password
HOST = input("HOST : ")
PORT = 8006
realm = "pam"
url = "https://%s:%s" %(HOST,PORT)
user = input("username : ")
username = user + "@" + realm
password = getpass.getpass()
credential = {"username":username, "password":password }
# Generate Token & Cookie
url1= url +"/api2/json/access/ticket"
response = requests.post(url1, data=credential, verify=False)
if response.status_code == 200:
data = json.loads(response.text.encode('utf8'))
ticket = data['data']['ticket']
crsf = data['data']['CSRFPreventionToken']
print("respon status : ", response.status_code)
print("===>> Generate Token and Cookie <<===")
print("Ticket : ", ticket)
print("Token : ", crsf)
else :
print ("respon status : ", response.status_code)
# Get list VM
url2 = url + "/api2/json/cluster/resources?"
cookie = {'PVEAuthCookie' : ticket}
header = {
'Accept: */*',
'Content-Type :application/json',
'CSRFPreventionToken: str(crsf)'
}
result = requests.get(url2, cookies = cookie, verify=False)
json_results = result.json()
raw_data = json.dumps(json_results, iterate=2)
print(raw_data)