summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelie <elie>2010-11-14 23:17:39 +0000
committerelie <elie>2010-11-14 23:17:39 +0000
commit0f77f8e91bab9c0e2c760c01e20d75878b79b481 (patch)
tree548a02dd61ec013007657052167c1e80dcd33d04
parent4723092cd66ab6bb352db17b7ae5c0182df54884 (diff)
downloadpysnmp-0f77f8e91bab9c0e2c760c01e20d75878b79b481.tar.gz
* getVarBindTable() does not filter SNMP exception values anymore
* getVarBindTable() of v1 API now returns Null instead of None * GETNEXT/GETBULK apps now track EOM condition automatically
-rw-r--r--CHANGES10
-rw-r--r--examples/v1arch/manager/nextgen.py5
-rw-r--r--examples/v3arch/manager/bulkgen.py19
-rw-r--r--examples/v3arch/manager/nextgen.py17
-rw-r--r--pysnmp/entity/rfc3413/cmdgen.py36
-rw-r--r--pysnmp/entity/rfc3413/oneliner/cmdgen.py4
-rw-r--r--pysnmp/proto/api/v1.py6
-rw-r--r--pysnmp/proto/api/v2c.py22
8 files changed, 63 insertions, 56 deletions
diff --git a/CHANGES b/CHANGES
index b6e0aed..3da7f43 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,15 @@
Revision 4.1.15a
----------------
+- End-of-MIB condition detection reworked what caused backward
+ incompatibility at v1arch GETNEXT API. Previous pysnmp versions
+ used value = None in var-binds as returned by getVarBindTable()
+ API method. This version uses rfc1905 exception values (v2c/v3)
+ or pyasn1 Null (v1).
+ Built-in GETNEXT/GETBULK apps now do not require user to track
+ end-of-mib conditions anymore -- this is now done automatically.
+- SNMP exception values now exported from rfc1905 module, and made
+ pretty printable.
- Lexicographic walking mode is now supported at oneliner CommandGenerator.
- ContextEngineId&ContextName parameters passing implemented at
v3arch oneliner API.
@@ -9,7 +18,6 @@ Revision 4.1.15a
collide within an administrative domain.
- MibTableColumn instances now build value-to-column-instance map
to speedup by-value search.
-- SNMP exception values now exported from rfc1905 module, and made printable.
- Fix to Next/Bulk CommandGenerators to catch a non-increasing OID
error condition (what prevents looping).
- Fix to Opaque value tagging at rfc1155.Opaque type.
diff --git a/examples/v1arch/manager/nextgen.py b/examples/v1arch/manager/nextgen.py
index 08c4575..14dcebd 100644
--- a/examples/v1arch/manager/nextgen.py
+++ b/examples/v1arch/manager/nextgen.py
@@ -7,6 +7,7 @@ from time import time
# Protocol version to use
pMod = api.protoModules[api.protoVersion1]
+#pMod = api.protoModules[api.protoVersion2c]
# SNMP table header
headVars = [ pMod.ObjectIdentifier((1,3,6)) ]
@@ -46,14 +47,12 @@ def cbRecvFun(transportDispatcher, transportDomain, transportAddress,
# Report SNMP table
for tableRow in varBindTable:
for name, val in tableRow:
- if val is None:
- continue
print 'from: %s, %s = %s' % (
transportAddress, name.prettyPrint(), val.prettyPrint()
)
# Stop on EOM
for oid, val in varBindTable[-1]:
- if val is not None:
+ if not isinstance(val, pMod.Null):
break
else:
transportDispatcher.jobFinished(1)
diff --git a/examples/v3arch/manager/bulkgen.py b/examples/v3arch/manager/bulkgen.py
index 4ebeb8a..9c7eb75 100644
--- a/examples/v3arch/manager/bulkgen.py
+++ b/examples/v3arch/manager/bulkgen.py
@@ -36,21 +36,16 @@ def cbFun(sendRequesthandle, errorIndication, errorStatus, errorIndex,
varBindTable, cbCtx):
if errorIndication:
print errorIndication
- return
+ return # stop on error
if errorStatus:
- print errorStatus.prettyPrint()
- return
+ print '%s at %s\n' % (
+ errorStatus.prettyPrint(),
+ errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'
+ )
+ return # stop on error
for varBindRow in varBindTable:
for oid, val in varBindRow:
- if val is None:
- print oid.prettyPrint()
- else:
- print '%s = %s' % (oid.prettyPrint(), val.prettyPrint())
- for oid, val in varBindTable[-1]:
- if val is not None:
- break
- else:
- return # stop on end-of-table
+ print '%s = %s' % (oid.prettyPrint(), val.prettyPrint())
return 1 # continue walking
cmdgen.BulkCommandGenerator().sendReq(
diff --git a/examples/v3arch/manager/nextgen.py b/examples/v3arch/manager/nextgen.py
index f0b8878..9e9a502 100644
--- a/examples/v3arch/manager/nextgen.py
+++ b/examples/v3arch/manager/nextgen.py
@@ -40,19 +40,14 @@ def cbFun(sendRequestHandle, errorIndication, errorStatus, errorIndex,
# SNMPv1 response may contain noSuchName error *and* SNMPv2c exception,
# so we ignore noSuchName error here
if errorStatus and errorStatus != 2:
- print errorStatus.prettyPrint()
- return
+ print '%s at %s\n' % (
+ errorStatus.prettyPrint(),
+ errorIndex and varBindTable[-1][int(errorIndex)-1] or '?'
+ )
+ return # stop on error
for varBindRow in varBindTable:
for oid, val in varBindRow:
- if val is None:
- print oid.prettyPrint()
- else:
- print '%s = %s' % (oid.prettyPrint(), val.prettyPrint())
- for oid, val in varBindTable[-1]:
- if val is not None:
- break
- else:
- return # stop on end-of-table
+ print '%s = %s' % (oid.prettyPrint(), val.prettyPrint())
return 1 # continue walking
cmdgen.NextCommandGenerator().sendReq(
diff --git a/pysnmp/entity/rfc3413/cmdgen.py b/pysnmp/entity/rfc3413/cmdgen.py
index cdc8e17..ea7f21d 100644
--- a/pysnmp/entity/rfc3413/cmdgen.py
+++ b/pysnmp/entity/rfc3413/cmdgen.py
@@ -3,6 +3,7 @@ from pysnmp.proto import rfc1157, rfc1905, api
from pysnmp.entity.rfc3413 import config
from pysnmp.proto.proxy import rfc2576
from pysnmp import error, nextid, debug
+from pyasn1.type import univ
getNextHandle = nextid.Integer(0x7fffffff)
@@ -14,6 +15,7 @@ def getVersionSpecifics(snmpVersion):
return pduVersion, api.protoModules[pduVersion]
class CommandGeneratorBase:
+ _null = univ.Null('')
def __init__(self):
self.__pendingReqs = {}
@@ -423,13 +425,13 @@ class NextCommandGenerator(CommandGeneratorBase):
):
varBindTable = pMod.apiPDU.getVarBindTable(PDU, rspPDU)
- if not varBindTable:
- errorIndication = 'emptyResponse'
- elif pMod.apiPDU.getErrorStatus(rspPDU):
+ if pMod.apiPDU.getErrorStatus(rspPDU):
errorIndication = None
+ elif not varBindTable:
+ errorIndication = 'emptyResponse'
else:
if map(lambda (o,v): o, pMod.apiPDU.getVarBinds(PDU)) < \
- map(lambda (o,v): v is None and (9,) or o,varBindTable[-1]):
+ map(lambda (o,v): isinstance(v, univ.Null) and (9,) or o,varBindTable[-1]):
errorIndication = None
else:
debug.logger & debug.flagApp and debug.logger('_handleResponse: sendRequestHandle %s, OID(s) not increasing!' % sendRequestHandle)
@@ -441,10 +443,16 @@ class NextCommandGenerator(CommandGeneratorBase):
varBindTable, cbCtx):
debug.logger & debug.flagApp and debug.logger('_handleResponse: sendRequestHandle %s, app says to stop walking' % sendRequestHandle)
return # app says enough
-
+
+ for o, v in varBindTable[-1]:
+ if not isinstance(v, univ.Null):
+ break
+ else:
+ return # no more objects available
+
pMod.apiPDU.setRequestID(PDU, pMod.getNextRequestID())
pMod.apiPDU.setVarBinds(
- PDU, map(lambda (x,y),n=pMod.Null(''): (x,n), varBindTable[-1])
+ PDU, map(lambda (x,y): (x,self._null), varBindTable[-1])
)
self._sendPdu(
@@ -545,13 +553,13 @@ class BulkCommandGenerator(CommandGeneratorBase):
):
varBindTable = pMod.apiBulkPDU.getVarBindTable(PDU, rspPDU)
- if not varBindTable:
+ if pMod.apiBulkPDU.getErrorStatus(rspPDU):
+ errorIndication = None
+ elif not varBindTable:
errorIndication = 'emptyResponse'
- elif pMod.apiBulkPDU.getErrorStatus(rspPDU):
- errorIndication = None
else:
if map(lambda (o,v): o, pMod.apiBulkPDU.getVarBinds(PDU)) < \
- map(lambda (o,v): v is None and (9,) or o,varBindTable[-1]):
+ map(lambda (o,v): isinstance(v, univ.Null) and (9,) or o,varBindTable[-1]):
errorIndication = None
else:
debug.logger & debug.flagApp and debug.logger('_handleResponse: sendRequestHandle %s, OID(s) not increasing!' % sendRequestHandle)
@@ -566,8 +574,14 @@ class BulkCommandGenerator(CommandGeneratorBase):
pMod.apiBulkPDU.setRequestID(PDU, pMod.getNextRequestID())
+ for o, v in varBindTable[-1]:
+ if not isinstance(v, univ.Null):
+ break
+ else:
+ return # no more objects available
+
pMod.apiBulkPDU.setVarBinds(
- PDU, map(lambda (x,y),n=pMod.Null(''): (x,n), varBindTable[-1])
+ PDU, map(lambda (x,y): (x,self._null), varBindTable[-1])
)
self._sendPdu(
diff --git a/pysnmp/entity/rfc3413/oneliner/cmdgen.py b/pysnmp/entity/rfc3413/oneliner/cmdgen.py
index 08a8d01..ff9a4d3 100644
--- a/pysnmp/entity/rfc3413/oneliner/cmdgen.py
+++ b/pysnmp/entity/rfc3413/oneliner/cmdgen.py
@@ -389,7 +389,7 @@ class CommandGenerator(AsynCommandGenerator):
for idx in range(len(varBindTableRow)):
name, val = varBindTableRow[idx]
# XXX extra rows
- if val is not None:
+ if not isinstance(val, univ.Null):
if self.lexicographicMode:
if varBindHead[idx] <= name:
break
@@ -441,7 +441,7 @@ class CommandGenerator(AsynCommandGenerator):
varBindTableRow = varBindTable[-1]
for idx in range(len(varBindTableRow)):
name, val = varBindTableRow[idx]
- if val is not None:
+ if not isinstance(val, univ.Null):
if self.lexicographicMode:
if varBindHead[idx] <= name:
break
diff --git a/pysnmp/proto/api/v1.py b/pysnmp/proto/api/v1.py
index fdc458a..dac8971 100644
--- a/pysnmp/proto/api/v1.py
+++ b/pysnmp/proto/api/v1.py
@@ -41,6 +41,8 @@ apiVarBind = VarBindAPI()
getNextRequestID = nextid.Integer(0xffff)
class PDUAPI:
+ _null = univ.Null('')
+
def setDefaults(self, pdu):
pdu.setComponentByPosition(0, getNextRequestID())
pdu.setComponentByPosition(1, 0)
@@ -99,7 +101,9 @@ class PDUAPI:
def getVarBindTable(self, reqPDU, rspPDU):
if apiPDU.getErrorStatus(rspPDU) == 2:
- return [ map(lambda (x,y): (x, None), apiPDU.getVarBinds(reqPDU)) ]
+ return [
+ map(lambda (x,y): (x, self._null), apiPDU.getVarBinds(reqPDU))
+ ]
else:
return [ apiPDU.getVarBinds(rspPDU) ]
diff --git a/pysnmp/proto/api/v2c.py b/pysnmp/proto/api/v2c.py
index 6868452..2d8dc30 100644
--- a/pysnmp/proto/api/v2c.py
+++ b/pysnmp/proto/api/v2c.py
@@ -1,6 +1,5 @@
from pysnmp.proto import rfc1902, rfc1905, error
from pysnmp.proto.api import v1
-from pysnmp.smi import exval
from pyasn1.type import univ, namedtype, namedval
# Shortcuts to SNMP types
@@ -50,20 +49,19 @@ class PDUAPI(v1.PDUAPI):
return rspPDU
def getVarBindTable(self, reqPDU, rspPDU):
- varBinds = []
- for oid, val in apiPDU.getVarBinds(rspPDU):
- if exval.endOfMib.isSameTypeWith(val):
- val = None
- varBinds.append((oid, val))
- return [ varBinds ]
+ return [ apiPDU.getVarBinds(rspPDU) ]
def setEndOfMibError(self, pdu, errorIndex):
varBindList = self.getVarBindList(pdu)
- varBindList[errorIndex-1].setComponentByPosition(1, exval.endOfMib)
+ varBindList[errorIndex-1].setComponentByPosition(
+ 1, rfc1905.endOfMibView
+ )
def setNoSuchInstanceError(self, pdu, errorIndex):
varBindList = self.getVarBindList(pdu)
- varBindList[errorIndex-1].setComponentByPosition(1,exval.noSuchInstance)
+ varBindList[errorIndex-1].setComponentByPosition(
+ 1, rfc1905.noSuchInstance
+ )
apiPDU = PDUAPI()
@@ -99,12 +97,6 @@ class BulkPDUAPI(PDUAPI):
elif N:
varBindTable.append(rspVarBinds[:N])
- for varBindRow in varBindTable:
- for idx in range(len(varBindRow)):
- oid, val = varBindRow[idx]
- if exval.endOfMib.isSameTypeWith(val):
- varBindRow[idx] = (oid, None)
-
return varBindTable
apiBulkPDU = BulkPDUAPI()