import http.client
import json
import pprint
import ssl
address = "10.0.0.1"
username = "admin"
password = "password"
def main():
conn = http.client.HTTPSConnection(
address, context=ssl._create_unverified_context())
token = authenticate(conn, username, password)
labs = get_labs(conn, token)
for lab in labs:
data = get_topology(conn, token, lab)
print("##### " + lab)
pprint.pprint(data)
def authenticate(conn, username, password):
payload = json.dumps({
"username": username,
"password": password
})
headers = {
'Content-Type': 'application/json'
}
conn.request("POST", "/api/v0/authenticate", payload, headers)
res = conn.getresponse()
data = res.read()
return data.decode("utf-8").replace('"', '')
def get_labs(conn, token):
payload = ''
headers = {
'Authorization': 'Bearer ' + token
}
conn.request("GET", "/api/v0/labs", payload, headers)
res = conn.getresponse()
data = res.read()
return json.loads(data.decode("utf-8"))
def get_topology(conn, token, lab):
payload = ''
headers = {
'Authorization': 'Bearer ' + token
}
conn.request("GET", "/api/v0/labs/" + lab + "/topology", payload, headers)
res = conn.getresponse()
data = res.read()
return json.loads(data.decode("utf-8"))
if __name__ == "__main__":
main()