-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrestconf-example.py
38 lines (26 loc) · 1.38 KB
/
restconf-example.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
import requests
username = 'developer'
password = 'C1sco12345'
host = "ios-xe-mgmt-latest.cisco.com"
port = '9443'
#url = "https://" + host + ":" + port + "/restconf/data/ietf-interfaces:interfaces/interface"
url = "https://" + host + ":" + port + "/restconf/data/Cisco-IOS-XE-native:native/interface"
headers = {
'Content-Type': 'application/yang-data+json',
'Accept': 'application/yang-data+json'
}
response = requests.request("GET", url, headers=headers, auth=(username, password), verify=False)
print(response.json())
for type in response.json()['Cisco-IOS-XE-native:interface']:
for interface in response.json()['Cisco-IOS-XE-native:interface'][type]:
print(f"{type}{interface['name']}")
url = f"https://{host}:{port}/restconf/data/Cisco-IOS-XE-native:native/hostname"
response = requests.request("GET", url, headers=headers, auth=(username, password), verify=False)
print(response.json())
payload = "{\"hostname\": \"TestName2\"}"
url = f"https://{host}:{port}/restconf/data/Cisco-IOS-XE-native:native/hostname"
response = requests.request("PUT", url, headers=headers, data=payload, auth=(username, password), verify=False)
print(response)
url = f"https://{host}:{port}/restconf/data/Cisco-IOS-XE-native:native/hostname"
response = requests.request("GET", url, headers=headers, auth=(username, password), verify=False)
print(response.json())