summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelie <elie>2015-01-01 11:45:34 +0000
committerelie <elie>2015-01-01 11:45:34 +0000
commit497c6bb78acf1ff357d2cd915a1fa129868fddd5 (patch)
tree3042ad8eb61914c8c3bb64909e49492908b88d06
parent16dbdefb16dbabbc3d9edb0c16d57e09a22d62a1 (diff)
downloadpysnmp-497c6bb78acf1ff357d2cd915a1fa129868fddd5.tar.gz
oneliner GETBULK Command Generator now strips possible excessive OIDs
off the bottom of returned var-binds table
-rw-r--r--CHANGES2
-rw-r--r--examples/v3arch/oneliner/manager/cmdgen/getbulk-v2c.py4
-rw-r--r--pysnmp/entity/rfc3413/oneliner/cmdgen.py74
3 files changed, 39 insertions, 41 deletions
diff --git a/CHANGES b/CHANGES
index 06b4957..034d18f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -32,6 +32,8 @@ Revision 4.2.6rc0
rebuilt on top of these new optimized versions keeping all the legacy
for compatibility reasons. These classes no more keep references to
SnmpEngine what makes them reusable with many SnmpEngine class instances.
+- Oneliner GETBULK Command Generator now strips possible excessive OIDs
+ off the bottom of returned var-binds table.
- Built-in debugging is now based on Python logging module.
- Example on a single Transport Dispatcher use with multiple SnmpEngine's
in oneliner AsyncCommandGenerator & AsyncNotificationOriginator based
diff --git a/examples/v3arch/oneliner/manager/cmdgen/getbulk-v2c.py b/examples/v3arch/oneliner/manager/cmdgen/getbulk-v2c.py
index d6c974c..1aa138b 100644
--- a/examples/v3arch/oneliner/manager/cmdgen/getbulk-v2c.py
+++ b/examples/v3arch/oneliner/manager/cmdgen/getbulk-v2c.py
@@ -18,8 +18,8 @@ errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.bulkCmd(
cmdgen.CommunityData('public'),
cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
0, 25,
- '1.3.6.1.2.1.2.2.1.2',
- '1.3.6.1.2.1.2.2.1.3',
+ '1.3.6.1.2.1.2.2',
+ '1.3.6.1.2.1.2.3',
)
if errorIndication:
diff --git a/pysnmp/entity/rfc3413/oneliner/cmdgen.py b/pysnmp/entity/rfc3413/oneliner/cmdgen.py
index 1e91042..d6d37e7 100644
--- a/pysnmp/entity/rfc3413/oneliner/cmdgen.py
+++ b/pysnmp/entity/rfc3413/oneliner/cmdgen.py
@@ -703,10 +703,10 @@ class CommandGenerator:
nonRepeaters, maxRepetitions, *varNames, **kwargs):
def __cbFun(sendRequestHandle, errorIndication,
errorStatus, errorIndex, varBindTable, cbCtx):
- (self, varBindHead, varBindTotalTable, appReturn) = cbCtx
+ (self, varBindHead, nullVarBinds, varBindTotalTable, appReturn) = cbCtx
if (ignoreNonIncreasingOid or \
- hasattr(self, 'ignoreNonIncreasingOid') and \
- self.ignoreNonIncreasingOid ) and \
+ hasattr(self, 'ignoreNonIncreasingOid') and \
+ self.ignoreNonIncreasingOid ) and \
errorIndication and \
isinstance(errorIndication, errind.OidNotIncreasing):
errorIndication = None
@@ -717,69 +717,65 @@ class CommandGenerator:
appReturn['varBindTable'] = varBindTable
return
else:
- while varBindTable:
- if len(varBindTable[-1]) != len(varBindHead):
- # Fix possibly non-rectangular table
- del varBindTable[-1]
- else:
- break
-
- varBindTableRow = varBindTable and varBindTable[-1] or varBindTable
+ stopFlag = False
+ if not lexicographicMode: # cut possible extra OIDs
+ stopFlag = True
+ for i in xrange(len(varBindTable)):
+ stopFlag = True
+ if len(varBindTable[i]) != len(varBindHead):
+ varBindTable = i and varBindTable[:i-1] or []
+ break
+ for j in xrange(len(varBindTable[i])): # dichotomy?
+ name, val = varBindTable[i][j]
+ if nullVarBinds[j]:
+ varBindTable[i][j] = name, rfc1905.endOfMibView
+ continue
+ stopFlag = False
+ if not isinstance(val, univ.Null):
+ if not varBindHead[j].isPrefixOf(name):
+ varBindTable[i][j] = name, rfc1905.endOfMibView
+ nullVarBinds[j] = True
+ if stopFlag:
+ varBindTable = i and varBindTable[:i-1] or []
+ break
- for idx in range(len(varBindTableRow)):
- name, val = varBindTableRow[idx]
- if not isinstance(val, univ.Null):
- if lexicographicMode or \
- hasattr(self, 'lexicographicMode') and \
- self.lexicographicMode: # obsolete
- if varBindHead[idx] <= name:
- break
- else:
- if varBindHead[idx].isPrefixOf(name):
- break
- else:
- appReturn['errorIndication'] = errorIndication
- appReturn['errorStatus'] = errorStatus
- appReturn['errorIndex'] = errorIndex
- appReturn['varBindTable'] = varBindTotalTable
- return
+ varBindTotalTable.extend(varBindTable)
- varBindTotalTable.extend(varBindTable) # XXX out of table
- # rows possible
+ appReturn['errorIndication'] = errorIndication
+ appReturn['errorStatus'] = errorStatus
+ appReturn['errorIndex'] = errorIndex
+ appReturn['varBindTable'] = varBindTotalTable
if maxCalls[0] > 0:
maxCalls[0] -= 1
if maxCalls[0] == 0:
- appReturn['errorIndication'] = errorIndication
- appReturn['errorStatus'] = errorStatus
- appReturn['errorIndex'] = errorIndex
- appReturn['varBindTable'] = varBindTotalTable
return
if maxRows and len(varBindTotalTable) >= maxRows or \
hasattr(self, 'maxRows') and self.maxRows and \
len(varBindTotalTable) >= self.maxRows: # obsolete
- appReturn['errorIndication'] = errorIndication
- appReturn['errorStatus'] = errorStatus
- appReturn['errorIndex'] = errorIndex
if hasattr(self, 'maxRows'):
appReturn['varBindTable'] = varBindTotalTable[:self.maxRows]
else:
appReturn['varBindTable'] = varBindTotalTable[:maxRows]
return
- return 1 # continue table retrieval
+ return not stopFlag # continue table retrieval
lookupNames = kwargs.get('lookupNames', False)
lookupValues = kwargs.get('lookupValues', False)
contextEngineId = kwargs.get('contextEngineId')
contextName = kwargs.get('contextName', null)
lexicographicMode = kwargs.get('lexicographicMode', False)
+ if not lexicographicMode: # obsolete
+ if hasattr(self, 'lexicographicMode') and self.lexicographicMode:
+ lexicographicMode = True
maxRows = kwargs.get('maxRows', 0)
maxCalls = [ kwargs.get('maxCalls', 0) ]
ignoreNonIncreasingOid = kwargs.get('ignoreNonIncreasingOid', False)
varBindHead = [ univ.ObjectIdentifier(x[0]) for x in self.__asynCmdGen.makeReadVarBinds(varNames) ]
+ nullVarBinds = [ False ] * len(varBindHead)
appReturn = {}
@@ -788,7 +784,7 @@ class CommandGenerator:
transportTarget,
nonRepeaters, maxRepetitions,
varNames,
- (__cbFun, (self, varBindHead, [], appReturn)),
+ (__cbFun, (self, varBindHead, nullVarBinds, [], appReturn)),
lookupNames, lookupValues,
contextEngineId, contextName
)