-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathget_interfaces.py
62 lines (51 loc) · 1.52 KB
/
get_interfaces.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
import requests
import urllib3
import sys
from tabulate import tabulate
# HOST = '172.16.30.68'
# PORT = '443'
# USER = 'cisco'
# PASS = 'cisco'
# HOST = 'ios-xe-mgmt.cisco.com'
# PORT = '9443'
# USER = 'root'
# PASS = 'D_Vay!_10&'
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
def get_interfaces():
url = "https://{h}:{p}/restconf/data/Cisco-IOS-XE-interfaces-oper:interfaces".format(h=HOST, p=PORT)
headers = {'Content-Type': 'application/yang-data+json',
'Accept': 'application/yang-data+json'}
response = requests.get(url, auth=(USER, PASS), headers=headers, verify=False)
return response.json()
def main():
interfaces = get_interfaces()
# print(interfaces)
headers = ["Name",
"Description",
"VRF",
"Status",
"IN-DIS",
"IN-ERR",
"OUT-ERR",
"IN-DIS",
"IP Address",
"IN-PKTS",
"OUT-PKTS"]
table = list()
for item in interfaces['Cisco-IOS-XE-interfaces-oper:interfaces']['interface']:
tr =[item['name'],
item['description'],
# item['ipv4'],
item['vrf'],
item['admin-status'],
item['statistics']['in-discards'],
item['statistics']['in-errors'],
item['statistics']['out-discards'],
item['statistics']['out-errors'],
item['v4-protocol-stats']['in-pkts'],
item['v4-protocol-stats']['out-pkts']]
table.append(tr)
# print(tr)
print(tabulate(table, headers, tablefmt="fancy_grid"))
if __name__ == '__main__':
sys.exit(main())