-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeed_get.py
More file actions
73 lines (61 loc) · 2.06 KB
/
speed_get.py
File metadata and controls
73 lines (61 loc) · 2.06 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
"""
Simple application that change speed of an interface
"""
import requests
import json
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def main():
"""
change speed of an interface
:return: None
"""
# Login to APIC
description = ('Simple application that logs on to the APIC'
' and change speed of an interface.')
cookie = login("https://[IP ADDRESS]:443/api/aaaLogin.json")
if not cookie:
print('%% Could not login to APIC')
# Below logic, changes the speed
http_link="https://[IP ADDRESS]/api/node/mo/uni/infra/funcprof/accportgrp-terraform_intpolg_pc_2.json?query-target=children&target-subtree-class=infraRsHIfPol"
return(request_api(http_link, cookie))
def login(url):
payload = {
"aaaUser": {
"attributes": {
"name": "admin",
"pwd": "PASSWORD"
}
}
}
headers = {'Content-Type': "application/json"}
response = requests.post(url, data=json.dumps(payload), headers=headers, verify=False).json()
# PARSE TOKEN AND SET COOKIE
token = response['imdata'][0]['aaaLogin']['attributes']['token']
cookie = {}
cookie['APIC-cookie'] = token
return cookie
def request_api(add_url, TOKEN):
header ={'Content-Type': "text/xml",
# "Accept": "application/json"
# "X-Aci-Username":"admin",
# 'X-Aci-Rbac': json.dumps({'domain': 'all', "rolesR": 0, "rolesW": 1}),
# 'Cookie':json.dumps({'Set-Cookie': TOKEN})
}
req = requests.get(url=add_url, headers=header, cookies=TOKEN, verify=False)
res = ""
try:
resp = json.dumps(req.json(), indent=1)
res = json.loads(resp)
except ValueError as e:
resp = req.content
if resp:
return(res["imdata"][0]["infraRsHIfPol"]["attributes"]["tnFabricHIfPolName"])
else:
print("Could not get data!!!")
return("Could not get data!!!")
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass