-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathACI request.py
65 lines (45 loc) · 1.39 KB
/
ACI request.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import requests
import json
from pprint import pprint
###### LOGIN ######
url="https://sandboxapicdc.cisco.com:443/api/aaaLogin.json"
payload={
"aaaUser":{
"attributes":{
"name":"admin",
"pwd":"ciscopsdt"
}
}
}
headers={
"Content-type":"application/json"
}
response=requests.post(url,data=json.dumps(payload),headers=headers,verify=False).json()
#print(json.dumps(response,indent=2,sort_keys=True))
#parse token and sent cookies
token=response['imdata'][0]['aaaLogin']['attributes']['token']
cookie={}
cookie['APIC-cookie']=token
### GET APN ###
##### GET Application profile
url="https://sandboxapicdc.cisco.com:443/api/node/mo/uni/tn-Heroes/ap-Save_The_Planet.json"
headers={
'cache-control':'no-cache'
}
get_response=requests.get(url,headers=headers,cookies=cookie,verify=False).json()
""" koment
with open('output.json', 'wt') as out:
pprint(json.dumps(get_response,indent=2,sort_keys=True), stream=out)
"""
#### update description######
post_payload={
"fvAp":{
"attributes":{
"descr":"",
"dn":"uni/tn-Heroes/ap-Save_The_Planet"
}
}
}
post_respone=requests.post(url,headers=headers,cookies=cookie,verify=False,data=json.dumps(post_payload)).json()
get_response=requests.get(url,headers=headers,cookies=cookie,verify=False).json()
print(json.dumps(get_response,indent=2,sort_keys=True))