ExtremeSwitching (EXOS)

Expand all | Collapse all

Modify port Vlan ID with PySnmp

  • 1.  Modify port Vlan ID with PySnmp

    Posted 07-03-2017 05:32
    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?


  • 2.  RE: Modify port Vlan ID with PySnmp

    Posted 07-04-2017 04:23
    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)


  • 3.  RE: Modify port Vlan ID with PySnmp

    Posted 07-05-2017 19:31
    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.


  • 4.  RE: Modify port Vlan ID with PySnmp

    Posted 07-06-2017 04:31
    Glad to help.