-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
78 lines (63 loc) · 2.1 KB
/
main.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
from netmiko import ConnectHandler
from netmiko_mock import NetmikoMock # import for direct use
from netmiko_mock import NetmikoMock as ConnectHandler # temporary overwrite import to use NetmikoMock as ConnectHandler
# Use device object to retrive command output.
device = ConnectHandler(
device_type="cisco_wlc_ssh",
host="10.10.10.1",
username="admin",
password="admin"
)
device.open()
command = "show red det"
output = device.send_command(command, use_textfsm=True)
device.disconnect()
print("=" * 50 + device.platform + "=" * 50)
print(output)
print("=" * (100 + len(device.platform)))
# Or use context manager, so you don't need to worry about opening and closing connection.
with ConnectHandler(
device_type="alcatel_sros",
host="10.10.10.2",
username="admin",
password="admin"
) as device:
command = "show router interfaces"
output = device.send_command(command, use_textfsm=True)
print("=" * 50 + device.platform + "=" * 50)
print(output)
print("=" * (100 + len(device.platform)))
with ConnectHandler(
device_type="cisco_ios",
host="10.10.10.3",
username="admin",
password="admin"
) as device:
command = "show ver"
output = device.send_command(command) # raw command
print("=" * 50 + device.platform + "=" * 50)
print(output.splitlines()[0]) # just first line
print("=" * (100 + len(device.platform)))
with ConnectHandler(
device_type="juniper_junos",
host="10.10.10.4",
username="admin",
password="admin"
) as device:
command = "show interfaces"
output = device.send_command(command, use_textfsm=True)
print("=" * 50 + device.platform + "=" * 50)
print(output)
print("=" * (100 + len(device.platform)))
# Use NetmikoMock directly, you can change later for ConnectHandler
with NetmikoMock(
device_type="arista_eos",
host="10.10.10.5",
username="admin",
password="admin"
) as device:
command = "show int desc"
output = device.send_command(command, use_textfsm=True)
print("=" * 50 + device.platform + "=" * 50)
print(output)
print("=" * (100 + len(device.platform)))