-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssh_multiple_switches_and_vlan_netmiko.py
64 lines (58 loc) · 1.74 KB
/
ssh_multiple_switches_and_vlan_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
''' ssh and create vlan on cisco switch using python and netmiko '''
# Author: Anubhavsingh Sawdagur
# Created Date: 11 Febuary 2019
from netmiko import ConnectHandler
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",
}
ALL_DEVICES = [IOU_L2_S1, IOU_L2_S2, IOU_L2_S3, IOU_L2_S4, IOU_L2_S5]
for DEVICE in ALL_DEVICES:
NET_CONNECT = ConnectHandler(**DEVICE)
print("Connected to " + DEVICE["ip"])
OUTPUT = NET_CONNECT.send_command("sh ip int br")
print(OUTPUT)
# for n in range(2, 6):
# VLAN = "interface vlan " + str(n)
# GOTO_VLAN = "vlan " + str(n)
# VLAN_NAME = "name Python_Vlan_" + str(n)
# CONFIG_COMMAND = [VLAN, GOTO_VLAN, VLAN_NAME]
# OUTPUT = NET_CONNECT.send_config_set(CONFIG_COMMAND)
# print(OUTPUT)
# To remove created Loopback interfaces
# -----------------------
for n in range(2, 6):
VLAN = "no interface vlan " + str(n)
GOTO_VLAN = "no vlan " + str(n)
CONFIG_COMMAND = [VLAN, GOTO_VLAN]
OUTPUT = NET_CONNECT.send_config_set(CONFIG_COMMAND)
print(OUTPUT)
# -----------------------
OUTPUT = NET_CONNECT.send_command("sh vlan")
print(OUTPUT)