diff options
author | Ilya Etingof <etingof@gmail.com> | 2018-10-13 20:21:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-13 20:21:31 +0200 |
commit | 534a5bb8108013c59706c4fb6d195aa332af5e13 (patch) | |
tree | 26683f3689386d7ca11216c952861e1184430eee /pysnmp/smi | |
parent | 12138b182c82981c5268a18b15178ed564be874f (diff) | |
download | pysnmp-git-534a5bb8108013c59706c4fb6d195aa332af5e13.tar.gz |
Convert to async MIB instrumentation API (#209)
MIB instrumentation API changed to allow for asynchronous
managed objects access. Although built-in SNMPv2-SMI objects
are still synchronous, the MIB instrumentation API is async
what allows users to replace default MIB instrumentation
with their own, potentially asynchronous.
CommandResponder refactored to facilitate asynchronous
MIB instrumentation routines. The `readVars`, `readNextVars`
and `writeVars` MIB controller methods return immediately and
deliver their results via a call back.
SMI/MIB managed objects API overhauled for simplicity and
flexibility breaking backward compatibility.
Diffstat (limited to 'pysnmp/smi')
-rw-r--r-- | pysnmp/smi/instrum.py | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/pysnmp/smi/instrum.py b/pysnmp/smi/instrum.py index 84902025..d84493ac 100644 --- a/pysnmp/smi/instrum.py +++ b/pysnmp/smi/instrum.py @@ -184,15 +184,25 @@ class MibInstrumController(AbstractMibInstrumController): # MIB instrumentation def flipFlopFsm(self, fsmTable, *varBinds, **context): - self.__indexMib() - debug.logger & debug.flagIns and debug.logger('flipFlopFsm: input var-binds %r' % (varBinds,)) + try: + fsmContext = context['fsmState'] + + except KeyError: + self.__indexMib() + + fsmContext = context['fsmState'] = dict(varBinds=[], state='start', status='ok') + + debug.logger & debug.flagIns and debug.logger('flipFlopFsm: input var-binds %r' % (varBinds,)) mibTree, = self.mibBuilder.importSymbols('SNMPv2-SMI', 'iso') - outputVarBinds = [] - state, status = 'start', 'ok' + outputVarBinds = fsmContext['varBinds'] + state = fsmContext['state'] + status = fsmContext['status'] + origExc = origTraceback = None + while True: k = state, status if k in fsmTable: @@ -237,7 +247,7 @@ class MibInstrumController(AbstractMibInstrumController): break else: debug.logger & debug.flagIns and debug.logger( - 'flipFlopFsm: fun %s suceeded for %s=%r' % (mgmtFun, name, val)) + 'flipFlopFsm: fun %s succeeded for %s=%r' % (mgmtFun, name, val)) if rval is not None: outputVarBinds.append((rval[0], rval[1])) @@ -252,13 +262,15 @@ class MibInstrumController(AbstractMibInstrumController): # (seems to be irrelevant on Py3 but just in case) del origTraceback - return outputVarBinds + cbFun = context.get('cbFun') + if cbFun: + cbFun(outputVarBinds, **context) def readVars(self, *varBinds, **context): - return self.flipFlopFsm(self.fsmReadVar, *varBinds, **context) + self.flipFlopFsm(self.fsmReadVar, *varBinds, **context) def readNextVars(self, *varBinds, **context): - return self.flipFlopFsm(self.fsmReadNextVar, *varBinds, **context) + self.flipFlopFsm(self.fsmReadNextVar, *varBinds, **context) def writeVars(self, *varBinds, **context): - return self.flipFlopFsm(self.fsmWriteVar, *varBinds, **context) + self.flipFlopFsm(self.fsmWriteVar, *varBinds, **context) |