-
Notifications
You must be signed in to change notification settings - Fork 9
/
get_device.py
45 lines (32 loc) · 1.01 KB
/
get_device.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
import requests
import urllib3
import sys
from tabulate import tabulate
# HOST = '172.16.30.69'
# 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_info():
url = "https://{h}:{p}/restconf/data/Cisco-IOS-XE-native:native".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()
# print(response)
def main():
system = get_info().get("Cisco-IOS-XE-native:native")
# print(system)
headers = ["Hostname",
"Version"]
table = list()
hostname = system.get('hostname')
version = system.get('version')
table.append((hostname, version))
print(tabulate(table, headers, tablefmt="fancy_grid"))
if __name__ == '__main__':
sys.exit(main())