-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2b.py
87 lines (66 loc) · 1.98 KB
/
2b.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from pprint import pprint
import napalm
from my_devices import cisco3, arista1
from my_functions import connect
#from lxml import etree
print()
device_list = [cisco3, arista1]
conn_dev =[]
for device in device_list:
conn_dev.append(connect(device))
for device in conn_dev:
print(device.hostname)
pprint(device.get_arp_table())
print(device.platform)
'''
def check_connected(device):
if device.connected:
print(f'connected :)')
return True
else:
print('cannot connect!!!')
return False
def gather_routes(device):
return RouteTable(device).get()
def gather_arp_table(device):
return ArpTable(device).get()
def print_output(device,RT,ARP):
print(device.facts['hostname'])
print(f'device: \n port:{device.port}\nusername: {device.user}')
print()
pprint(RT.items())
print()
pprint(ARP.items())
device = Device(**srx2)
print()
#with device.open() as dev:
device.open()
if check_connected(device):
device_cfg = Config(device)
print()
show_xml = device.rpc.get_software_information()
print(show_xml)
print()
print(etree.tostring(show_xml, encoding='unicode'))
print()
intf_xml = device.rpc.get_interface_information(interface_name="fe-0/0/7", terse=True, normalize=True)
print(etree.tostring(intf_xml, encoding='unicode', pretty_print=True))
# RT = gather_routes(device)
# device_cfg.load(path='StaticRoutes.cfg', format='text', merge=True)
# print(device_cfg.diff())
# device_cfg.commit()
# try:
# device_cfg.lock()
# print('locked successfully')
# print('stage conf using set command')
# device_cfg.load('set system host-name blablaba', format='set', merge=True)
# print(device_cfg.diff())
# print('rollback..')
# device_cfg.rollback()
# print(device_cfg.diff())
# except LockError:
# print('!already locked!')
# ARP = gather_arp_table(dev)
# print_output(dev,RT,ARP)
'''
print()