-
Notifications
You must be signed in to change notification settings - Fork 0
/
topologySetUp.py
35 lines (29 loc) · 1.06 KB
/
topologySetUp.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
import requests
import json
baseUrl = "https://10.10.20.161/api/v0"
def login():
credencials = json.dumps({
"username": "developer",
"password": "C1sco12345"
})
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer <Bearer Token>'
}
token_auth = requests.request("POST", baseUrl + "/authenticate", headers=headers, data=credencials, verify=False)
token = 'Bearer ' + token_auth.json()
print(token)
return token
def createTopologyFromFile(token):
with open('campusTopology.yaml', 'rb') as payload:
headers = {'content-type': 'application/json',
'Authorization': token
}
print("")
response = requests.request("POST", baseUrl + "/import?title=net_automation", headers=headers, data=payload,
verify=False)
if response.text.__contains__("id"):
return "Success\n" + response.text
else:
return "Failed\n" +response.text
print(createTopologyFromFile(login()))