-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1b.py
92 lines (69 loc) · 2.22 KB
/
1b.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
88
89
90
91
92
#from jnpr.junos import Device
#from jnpr.junos.op.ethport import EthPortTable
#from jnpr.junos.op.arp import ArpTable
#from jnpr.junos.op.routes import RouteTable
from pprint import pprint
import napalm
from my_devices import cisco3, arista1
#from jnpr_devices import srx2
#from jnpr.junos.utils.config import Config
#from jnpr.junos.exception import LockError
#from lxml import etree
def connect(device):
driver = napalm.get_network_driver(device['driver'])
device = driver(hostname=device['hostname'], username=device['username'], password=device['password'] )
device.open()
return device
print()
'''
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()