Skip to content

Commit

Permalink
Reimplemented walkCmd/bulkWalkCmd.
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Sep 12, 2024
1 parent 1e34ed1 commit 4f92f1f
Show file tree
Hide file tree
Showing 10 changed files with 497 additions and 252 deletions.
52 changes: 1 addition & 51 deletions pysnmp/entity/rfc3413/cmdgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pysnmp import debug, error, nextid
from pysnmp.entity.engine import SnmpEngine
from pysnmp.entity.rfc3413 import config
from pysnmp.proto import errind, rfc1905
from pysnmp.proto import errind
from pysnmp.proto.api import v2c
from pysnmp.proto.error import StatusInformation
from pysnmp.proto.proxy import rfc2576
Expand Down Expand Up @@ -568,16 +568,6 @@ def processResponseVarBinds(
errorIndication, varBinds = None, ()
elif not varBindTable:
errorIndication, varBinds = errind.emptyResponse, ()
else:
errorIndication, varBinds = v2c.apiBulkPDU.getNextVarBinds(
varBindTable[-1], v2c.apiPDU.getVarBinds(reqPDU)
)
nonRepeaters = v2c.apiBulkPDU.getNonRepeaters(reqPDU)
if nonRepeaters:
varBinds = (
v2c.apiBulkPDU.getVarBinds(reqPDU)[: int(nonRepeaters)]
+ varBinds[int(nonRepeaters) :]
)

if not cbFun(
snmpEngine,
Expand All @@ -596,43 +586,3 @@ def processResponseVarBinds(

if not varBinds:
return # no more objects available

v2c.apiBulkPDU.setRequestID(reqPDU, v2c.getNextRequestID())
v2c.apiBulkPDU.setVarBinds(reqPDU, varBinds)

try:
self.sendPdu(
snmpEngine,
targetName,
contextEngineId,
contextName,
reqPDU,
self.processResponseVarBinds,
(
targetName,
nonRepeaters,
maxRepetitions,
contextEngineId,
contextName,
reqPDU,
cbFun,
cbCtx,
),
)

except StatusInformation:
statusInformation = sys.exc_info()[1]
debug.logger & debug.FLAG_APP and debug.logger(
"processResponseVarBinds: sendPduHandle {}: _sendPdu() failed with {!r}".format(
sendRequestHandle, statusInformation
)
)
cbFun(
snmpEngine,
sendRequestHandle,
statusInformation["errorIndication"],
0,
0,
(),
cbCtx,
) # type: ignore
7 changes: 3 additions & 4 deletions pysnmp/hlapi/v1arch/asyncio/cmdgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# License: https://www.pysnmp.com/pysnmp/license.html
#
from pysnmp.hlapi.v1arch.auth import *
from pysnmp.hlapi.varbinds import *
from pysnmp.hlapi import varbinds
from pysnmp.hlapi.v1arch.asyncio.transport import *
from pysnmp.smi.rfc1902 import *
from pysnmp.proto import api
Expand All @@ -14,9 +14,8 @@

__all__ = ["getCmd", "nextCmd", "setCmd", "bulkCmd", "isEndOfMib"]

VB_PROCESSOR = CommandGeneratorVarBinds()

isEndOfMib = lambda varBinds: not api.v2c.apiPDU.getNextVarBinds(varBinds)[1]
VB_PROCESSOR = varbinds.CommandGeneratorVarBinds()
isEndOfMib = varbinds.isEndOfMib


async def getCmd(snmpDispatcher, authData, transportTarget, *varBinds, **options):
Expand Down
Loading

0 comments on commit 4f92f1f

Please sign in to comment.