|
|
@@ -397,7 +397,7 @@ class SNMPSwitch(object): |
|
|
|
None else privProtocol |
|
|
|
self._auth = UsmUserData(*args, **kwargs) |
|
|
|
|
|
|
|
self._targ = UdpTransportTarget((host, 161)) |
|
|
|
self._targ = UdpTransportTarget((host, 161), timeout=10) |
|
|
|
|
|
|
|
def __repr__(self): # pragma: no cover |
|
|
|
return '<SNMPSwitch: auth=%s, targ=%s>' % (repr(self._auth), repr(self._targ)) |
|
|
@@ -536,9 +536,47 @@ class SNMPSwitch(object): |
|
|
|
return bytes(v).decode('utf-8') |
|
|
|
|
|
|
|
def createvlan(self, vlan, name): |
|
|
|
# createAndGo(4) |
|
|
|
self._set(('Q-BRIDGE-MIB', 'dot1qVlanStaticRowStatus', |
|
|
|
int(vlan)), 4) |
|
|
|
try: |
|
|
|
while True: |
|
|
|
try: |
|
|
|
status = self._get(('Q-BRIDGE-MIB', 'dot1qVlanStaticRowStatus', |
|
|
|
int(vlan))) |
|
|
|
except ValueError: |
|
|
|
status = 0 |
|
|
|
|
|
|
|
#print('got vlan', vlan, 'status:', status) |
|
|
|
# if status == 0, vlan does not exist. |
|
|
|
|
|
|
|
if status == 1: # active |
|
|
|
# vlan is active |
|
|
|
return |
|
|
|
|
|
|
|
elif status == 0: |
|
|
|
try: |
|
|
|
# createAndGo(4) |
|
|
|
self._set(('Q-BRIDGE-MIB', 'dot1qVlanStaticRowStatus', |
|
|
|
int(vlan)), 4) |
|
|
|
except ValueError: |
|
|
|
# need to use createAndWait(5) |
|
|
|
self._set(('Q-BRIDGE-MIB', 'dot1qVlanStaticRowStatus', |
|
|
|
int(vlan)), 5) |
|
|
|
|
|
|
|
elif status == 2: # notInService |
|
|
|
# should be able to be marked active(1) |
|
|
|
self._set(('Q-BRIDGE-MIB', 'dot1qVlanStaticRowStatus', |
|
|
|
int(vlan)), 1) |
|
|
|
elif status == 3: # notReady |
|
|
|
# Set itself, it'll be set more properly later |
|
|
|
# This is because a switch requires exact length |
|
|
|
mib = ('Q-BRIDGE-MIB', 'dot1qVlanStaticEgressPorts', int(vlan)) |
|
|
|
self._set(mib, self._get(mib)) |
|
|
|
else: |
|
|
|
raise ValueError('do not know how to handle status: %s' % status) |
|
|
|
except Exception: |
|
|
|
import traceback |
|
|
|
traceback.print_exc() |
|
|
|
raise |
|
|
|
|
|
|
|
self._set(('Q-BRIDGE-MIB', 'dot1qVlanStaticName', int(vlan)), |
|
|
|
name.encode('utf-8')) |
|
|
|
|
|
|
|