-
Notifications
You must be signed in to change notification settings - Fork 1
/
enterasys48p.py
80 lines (59 loc) · 2.88 KB
/
enterasys48p.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
# OLD VERSION
# On utilise enterasys48p_config qui push la config directement sur les 48ports
# car cette version en telnet bugue
import telnetlib
class Enterasys48p:
def __init__(self, tn):
self.telnet = tn
def authenticate(self, username, password):
print("authenticating")
self.telnet.read_until(b"Username:")
self.telnet.write(username.encode()+b"\n")
self.telnet.read_until(b"Password:")
self.telnet.write(password.encode()+b"\n")
self.waitForPrompt()
def waitForPrompt(self):
print(self.telnet.read_until(b"->")) # <-- print feedback from the switch
#self.telnet.read_until(b"->")
def beforeVlan(self):
pass
def setInterface(self, selector):
pass
def clearVlan(self, selector, vlan):
# don't clear vlan on upstream, otherwise we loose the connection to the switch
if not "ge" in selector:
self.telnet.write(b"clear vlan egress " + str(vlan).encode() + b" " + str(selector).encode() + b"\n")
self.waitForPrompt()
self.telnet.write(b"clear vlan "+str(vlan).encode()+b"\n")
self.waitForPrompt()
self.telnet.write(b"set switch stack-port ethernet")
def setVlanUntagged(self, selector, vlan):
self.clearVlan(selector, vlan)
self.telnet.write(b"set vlan create " + str(vlan).encode() + b"\n")
self.waitForPrompt()
self.telnet.write(b"set vlan egress " + str(vlan).encode() + b" " + str(selector).encode() + b" untagged\n")
self.waitForPrompt()
def setVlanTagged(self, selector, vlan):
self.clearVlan(selector, vlan)
self.telnet.write(b"set vlan create " + str(vlan).encode() + b"\n")
self.waitForPrompt()
self.telnet.write(b"set vlan egress " + str(vlan).encode() + b" " + str(selector).encode() + b" tagged\n")
self.waitForPrompt()
def setNativeVlan(self, selector, vlan):
self.telnet.write(b"set port vlan " + str(selector).encode() + b" " + str(vlan).encode() + b" modify-egress\n")
self.waitForPrompt()
def unsetInterface(self):
pass
def afterVlan(self):
pass
def saveConfig(self):
self.telnet.write(b"save config\n")
self.waitForPrompt()
def activateSnmp(self, community):
self.beforeVlan()
self.telnet.write(b"set snmp community "+str(community).encode()+b" securityname "+str(community).encode()+b"nonvolatile \n")
self.waitForPrompt()
self.telnet.write(b"set snmp access "+str(community).encode()+b" security-model v2c read All notify All nonvolatile\n")
self.waitForPrompt()
self.telnet.write(b"set snmp group public user "+str(community).encode()+b" security-model v2c nonvolatile\n")
self.waitForPrompt()