Header Only - DO NOT REMOVE - Extreme Networks

Modify port Vlan ID with PySnmp


Userlevel 1
Hi, im trying to modify the vlan id of port 24 on slot 2 (2:24) which as the ifindex of 152 according to snmpGet. I have been reading the documentation of PySnmp and from my point of view it is a bit vague, probably because i dont have yet a deep knowledge of programming and also on how SNMP is structured.

Using the script provided from pysnmp documentation im unable to configure port 2:24 vlan ID. Im getting the following error:

pysnmp.smi.error.SmiError: No symbol SNMPv2-SMI::mib-2.17.7.1.4.5.1.1 at [/code]my code:

from pysnmp.hlapi import *
g = setCmd(SnmpEngine(),
CommunityData(MyComm),
UdpTransportTarget(MyIP, 161)),
ContextData(),
ObjectType(ObjectIdentity('SNMPv2-SMI', 'mib-2.17.7.1.4.5.1.1', 152), '201'))
next(g)[/code]
Can someone help me?

3 replies

Userlevel 6
It seems pysnmp cannot find the mib, try using the oid. Below an example with a get.

def SNMPGet(oid,host,community):
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
cmdgen.CommunityData(community),
cmdgen.UdpTransportTarget((host, 161)),
cmdgen.MibVariable(oid)
)

# Check for errors and print out results
if errorIndication:
print(errorIndication)
else:
if errorStatus:
print('%s at %s' % (
errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex)-1] or '?'
)
)
else:
for name, val in varBinds:
return val.prettyPrint()

portInOctets=SNMPGet('1.3.6.1.2.1.31.1.1.1.6.1001',iphost,args.community)
Userlevel 1
Hi, Oscar. Hope you are doing well, thanks for the reply. I was finally able to set the vlan Id via pySNMP with a different piece of code.
from pysnmp.entity.rfc3413.oneliner import cmdgen
from pysnmp.proto import rfc1902
errorIndication, errorStatus, errorIndex, varBinds = cmdgen.CommandGenerator().setCmd(
cmdgen.CommunityData('my-agent', My_Community, 1),
cmdgen.UdpTransportTarget(('192.168.20.10', 161)),
((1,3,6,1,2,1,17,7,1,4,5,1,1,1), rfc1902.Gauge32('201'))
)
print errorIndication
print errorStatus [/code]output form the switch:

* (pacman) EXOS-VM.36 # sh port 1 vid
Untagged
Port /Tagged VID(s)
-------- -------- ------------------------------------------------------------
1 Untagged 201

Thanks for trying to help.
Userlevel 6
Glad to help.

Reply