-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenterasys24p_config.py
54 lines (41 loc) · 1.55 KB
/
enterasys24p_config.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
from telnetlib import Telnet
def wait_for_prompt(tn):
print(tn.read_until(b"#")) # <-- print feedback from the switch
def enterasys24p_config(switch, config, access_password, new_password):
with Telnet(switch["ip"]) as tn:
tn.read_until(b"Username:")
tn.write(b"admin\n")
tn.read_until(b"Password:")
tn.write(access_password.encode()+b"\n")
wait_for_prompt(tn)
tn.write(b"configure\n")
wait_for_prompt(tn)
tn.write(b"username admin password 0 "+new_password.encode()+b"\n")
wait_for_prompt(tn)
tn.write(b"snmp-server\n")
wait_for_prompt(tn)
tn.write(b"snmp-server community hotlinemontreal ro\n")
wait_for_prompt(tn)
ports = config["ports"]
for port, config in [(p, ports[p]) for p in ports]:
tn.write(b"interface ethernet 1/" + port.encode() + b"\n")
wait_for_prompt(tn)
tn.write(b"switchport native vlan 1\n") # Clear VLANs
tn.write(b"no switchport allowed vlan\n")
wait_for_prompt(tn)
tn.write(b"switchport allowed vlan add " + str(config["untagged"]).encode() + b" untagged\n")
wait_for_prompt(tn)
tn.write(b"switchport native vlan " + str(config["untagged"]).encode() + b"\n")
wait_for_prompt(tn)
for tagged_vlan in config["tagged"]:
tn.write(b"switchport allowed vlan add " + str(tagged_vlan).encode() + b" tagged\n")
wait_for_prompt(tn)
tn.write(b"exit\n")
wait_for_prompt(tn)
tn.write(b"end\n")
wait_for_prompt(tn)
print("saving configuration")
tn.write(b"copy running-config startup-config\n")
tn.read_until(b"[startup]")
tn.write(b"\n")
wait_for_prompt(tn)