-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnxosAPI_rest-with-PUT.py
46 lines (36 loc) · 1.07 KB
/
nxosAPI_rest-with-PUT.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
import requests
import json
from pprint import pprint
url = "https://sbx-nxos-mgmt.cisco.com/api/aaaLogin.json"
payload = json.dumps({
"aaaUser": {
"attributes": {
"name": "admin",
"pwd": "Admin_1234!"
}
}
})
headers = {
'Content-Type': 'application/json'
}
username = "admin"
password = "Admin_1234!"
response = requests.post(url, headers=headers, auth=(username, password),data=payload, verify=False).json()
token = response['imdata'][0]['aaaLogin']['attributes']['token']
#print(token)
cookies={}
cookies['APIC-cookie']=token
#not just parse through the python dictionary to [find][the][token], but actually create an empty dictionary and set a key called "APIC-cookie" = the newly parsed token
url = "https://sbx-nxos-mgmt.cisco.com/api/node/mo/sys/intf/phys-%5Beth1/33%5D.json"
payload = json.dumps({
"l1PhysIf": {
"attributes": {
"descr": "paint it ike a tank!"
}
}
})
headers = {
'Content-Type': 'application/json'
}
put_response = requests.put(url, headers=headers, data=payload, cookies=cookies, verify=False)
pprint(put_response)