Files
cml-community/scripts/breakout-to-secureCRT-session/cmlApiCalls.py
shawnjury b837227eac Breakout tool update add mac support (#25)
* breakout update and MAC OS support

Added getAllNodes function to cmlApiCalls.py.
Added Mac OS support into main.py
Added new logic to get all nodes, find label and node_definition, sort by label and add the SecureCRT ini files.  This matched what the breakout tool provided for my machine.

* Update main.py

* Using Lab_title

Changed to use the LabTitle for the Directory/CRT.  This makes it more human readable when you have multiple labs.
2022-11-03 06:30:35 -04:00

67 lines
1.9 KiB
Python

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 getLabInfo(auth, server, lab):
headers = {
'accept': 'application/json',
'Authorization': auth,
}
response = requests.get(f'https://{server}/api/v0/labs/{lab}/?simplified=true', headers=headers, verify=False)
lab_info = json.loads(response.text)
if response.status_code == 200:
return(lab_info)
else:
return("end of list")
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)
if response.status_code == 200:
return(node)
else:
return("end of list")
def getAllNodes(auth, server, lab ):
headers = {
'accept': 'application/json',
'Authorization': auth,
}
response = requests.get(f'https://{server}/api/v0/labs/{lab}/nodes/?simplified=true', headers=headers, verify=False)
nodes = json.loads(response.text)
if response.status_code == 200:
return(nodes)
else:
return("end of list")