-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssh_config_routers_and_switches_netmiko.py
83 lines (74 loc) · 2.1 KB
/
ssh_config_routers_and_switches_netmiko.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
''' ssh and configure cisco switch using python and netmiko '''
# Author: Anubhavsingh Sawdagur
# Created Date: 11 Febuary 2019
from netmiko import ConnectHandler
IOSV_L3_R1 = {
"device_type": "cisco_ios",
"ip": "192.168.44.110",
"username": "anubhav",
"password": "cisco",
}
IOSV_L3_R2 = {
"device_type": "cisco_ios",
"ip": "192.168.44.111",
"username": "anubhav",
"password": "cisco",
}
IOU_L2_S1 = {
"device_type": "cisco_ios",
"ip": "192.168.44.121",
"username": "anubhav",
"password": "cisco",
}
IOU_L2_S2 = {
"device_type": "cisco_ios",
"ip": "192.168.44.122",
"username": "anubhav",
"password": "cisco",
}
IOU_L2_S3 = {
"device_type": "cisco_ios",
"ip": "192.168.44.123",
"username": "anubhav",
"password": "cisco",
}
IOU_L2_S4 = {
"device_type": "cisco_ios",
"ip": "192.168.44.124",
"username": "anubhav",
"password": "cisco",
}
IOU_L2_S5 = {
"device_type": "cisco_ios",
"ip": "192.168.44.125",
"username": "anubhav",
"password": "cisco",
}
with open("Networking\\Configurations\\IOSV_L3_Config.txt") as F:
L3_COMMANDS = F.read().splitlines()
print(L3_COMMANDS)
with open("Networking\\Configurations\\IOU_L2_Config.txt") as F:
L2_COMMANDS = F.read().splitlines()
print(L2_COMMANDS)
ALL_ROUTERS = [IOSV_L3_R1, IOSV_L3_R2]
for DEVICE in ALL_ROUTERS:
NET_CONNECT = ConnectHandler(**DEVICE)
print("Connected to " + DEVICE["ip"])
OUTPUT = NET_CONNECT.send_command("sh ip int br")
print(OUTPUT)
OUTPUT = NET_CONNECT.send_config_set(L3_COMMANDS)
print(OUTPUT)
OUTPUT = NET_CONNECT.send_command("sh ip int br")
print(OUTPUT)
ALL_SWITCHES = [IOU_L2_S1, IOU_L2_S2, IOU_L2_S3, IOU_L2_S4, IOU_L2_S5]
for DEVICE in ALL_SWITCHES:
NET_CONNECT = ConnectHandler(**DEVICE)
print("Connected to " + DEVICE["ip"])
OUTPUT = NET_CONNECT.send_command("sh ip int br")
print(OUTPUT)
OUTPUT = NET_CONNECT.send_command("sh vlan br")
print(OUTPUT)
OUTPUT = NET_CONNECT.send_config_set(L2_COMMANDS)
print(OUTPUT)
OUTPUT = NET_CONNECT.send_command("sh vlan br")
print(OUTPUT)