-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcmlApiCalls.py
48 lines (37 loc) · 1.42 KB
/
cmlApiCalls.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
import requests
import json
requests.packages.urllib3.disable_warnings()
class CML:
def auth(server, username, password):
headers = {
"accept": "application/json",
"Content-Type": "application/json"
}
data = {"username":username,"password":password}
a = '{"username":'
b = f'"{username}","password":"{password}'
c = '"}'
data = a+b+c
response = requests.post(f"https://{server}/api/v0/authenticate", headers=headers, data=data, verify=False)
access_token = "Bearer " + json.loads(response.text)
return(access_token)
def getAllNodes(auth, server, lab):
headers = {
'accept': 'application/json',
'Authorization': auth,
}
response = requests.get(f'https://{server}/api/v0/labs/{lab}/nodes', headers=headers, verify=False)
nodes = json.loads(response.text)
return(nodes)
def getNodesByID(auth, server, lab, node_id):
headers = {
'accept': 'application/json',
'Authorization': auth,
}
response = requests.get(f'https://{server}/api/v0/labs/{lab}/nodes/{node_id}?simplified=true', headers=headers, verify=False)
node = json.loads(response.text)
#doublequotes = node.replace('"','\\"')
if response.status_code == 200:
return(node)
else:
return("end of list")