diff options
author | elie <elie> | 2014-06-17 15:21:27 +0000 |
---|---|---|
committer | elie <elie> | 2014-06-17 15:21:27 +0000 |
commit | 0489d99df137b5e5ee98d40ac421c2762737bc23 (patch) | |
tree | 317af391568534b47488c804c5c735856c3a31d6 | |
parent | d703289a12f1d6cdf15af88fcfe2d43ef8012bd9 (diff) | |
download | pysnmp-0489d99df137b5e5ee98d40ac421c2762737bc23.tar.gz |
.getMibViewController() impemented
-rw-r--r-- | pysnmp/entity/rfc3413/oneliner/cmdgen.py | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/pysnmp/entity/rfc3413/oneliner/cmdgen.py b/pysnmp/entity/rfc3413/oneliner/cmdgen.py index f2c348c..65bc2c7 100644 --- a/pysnmp/entity/rfc3413/oneliner/cmdgen.py +++ b/pysnmp/entity/rfc3413/oneliner/cmdgen.py @@ -29,7 +29,7 @@ nextID = nextid.Integer(0xffffffff) class AsyncCommandGenerator: _null = univ.Null('') - def _getCmdCache(self, snmpEngine): + def _getCache(self, snmpEngine): if 'cmdgen' not in snmpEngine.cache: snmpEngine.cache['cmdgen'] = { 'auth': {}, @@ -37,13 +37,17 @@ class AsyncCommandGenerator: 'tran': {}, 'addr': {}, } - if 'mibViewController' not in snmpEngine.cache['cmdgen']: - snmpEngine.cache['cmdgen']['mibViewController'] = view.MibViewController(snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder) - return snmpEngine.cache['cmdgen'] + def getMibViewController(self, snmpEngine): + if 'mibViewController' not in snmpEngine.cache: + snmpEngine.cache['mibViewController'] = view.MibViewController( + snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder + ) + return snmpEngine.cache['mibViewController'] + def cfgCmdGen(self, snmpEngine, authData, transportTarget): - cache = self._getCmdCache(snmpEngine) + cache = self._getCache(snmpEngine) if isinstance(authData, CommunityData): if authData.communityIndex not in cache['auth']: config.addV1System( @@ -124,7 +128,7 @@ class AsyncCommandGenerator: return addrName, paramsName def uncfgCmdGen(self, snmpEngine, authData=None): - cache = self._getCmdCache(snmpEngine) + cache = self._getCache(snmpEngine) if authData: if isinstance(authData, CommunityData): authDataKey = authData.communityIndex @@ -200,8 +204,7 @@ class AsyncCommandGenerator: return addrNames, paramsNames def makeVarBinds(self, snmpEngine, varBinds, oidOnly=False): - cache = self._getCmdCache(snmpEngine) - mibViewController = cache['mibViewController'] + mibViewController = self.getMibViewController(snmpEngine) __varBinds = [] for varName, varVal in varBinds: if isinstance(varName, MibVariable): @@ -228,8 +231,7 @@ class AsyncCommandGenerator: def unmakeVarBinds(self, snmpEngine, varBinds, lookupNames, lookupValues): if lookupNames or lookupValues: - cache = self._getCmdCache(snmpEngine) - mibViewController = cache['mibViewController'] + mibViewController = self.getMibViewController(snmpEngine) _varBinds = [] for name, value in varBinds: varName = MibVariable(name).resolveWithMib(mibViewController) @@ -254,7 +256,6 @@ class AsyncCommandGenerator: ) ] - # Async SNMP apps def getCmd(self, snmpEngine, authData, transportTarget, contextData, @@ -393,10 +394,7 @@ class AsynCommandGenerator: self.snmpEngine = snmpEngine self.__asyncCmdGen = AsyncCommandGenerator() - - # grab/create MibViewController from/for the real AsyncCommandGen - cache = self.__asyncCmdGen._getCmdCache(snmpEngine) - self.mibViewController = cache['mibViewController'] + self.mibViewController = self.__asyncCmdGen.getMibViewController(self.snmpEngine) def __del__(self): self.__asyncCmdGen.uncfgCmdGen(self.snmpEngine) |