Fix hlapi LCD to include `contextName` (#217)
Fixed hlapi LCD configurator to include `contextName`. Prior to this fix sending SNMPv3 TRAP with non-default `contextName` would fail. This change modifies the signature of the internal LCD methods.master
parent
9ebd0c0fab
commit
4994111b2b
|
@ -66,6 +66,8 @@ Revision 4.4.7, released 2018-11-XX
|
|||
the stack frames (ultimately shown in traceback/debugger)
|
||||
- Fixed hlapi/v3arch transport target caching to ensure transport targets
|
||||
are different even if just timeout/retries options differ
|
||||
- Fixed hlapi LCD configurator to include `contextName`. Prior to this fix
|
||||
sending SNMPv3 TRAP with non-default `contextName` would fail.
|
||||
|
||||
Revision 4.4.6, released 2018-09-13
|
||||
-----------------------------------
|
||||
|
|
|
@ -578,12 +578,13 @@ def addVacmUser(snmpEngine, securityModel, securityName, securityLevel,
|
|||
|
||||
|
||||
def delVacmUser(snmpEngine, securityModel, securityName, securityLevel,
|
||||
readSubTree=(), writeSubTree=(), notifySubTree=()):
|
||||
readSubTree=(), writeSubTree=(), notifySubTree=(),
|
||||
contextName=null):
|
||||
(groupName, securityLevel, readView, writeView,
|
||||
notifyView) = __cookVacmUserInfo(snmpEngine, securityModel,
|
||||
securityName, securityLevel)
|
||||
delVacmGroup(snmpEngine, securityModel, securityName)
|
||||
delVacmAccess(snmpEngine, groupName, null, securityModel, securityLevel)
|
||||
delVacmAccess(snmpEngine, groupName, contextName, securityModel, securityLevel)
|
||||
if readSubTree:
|
||||
delVacmView(
|
||||
snmpEngine, readView, readSubTree
|
||||
|
@ -597,7 +598,6 @@ def delVacmUser(snmpEngine, securityModel, securityName, securityLevel,
|
|||
snmpEngine, notifyView, notifySubTree
|
||||
)
|
||||
|
||||
|
||||
# Notification target setup
|
||||
|
||||
def __cookNotificationTargetInfo(snmpEngine, notificationName, paramsName,
|
||||
|
|
|
@ -145,7 +145,8 @@ def getCmd(snmpEngine, authData, transportTarget, contextData,
|
|||
(errorIndication, errorStatus, errorIndex, varBindsUnmade)
|
||||
)
|
||||
|
||||
addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
|
||||
addrName, paramsName = lcd.configure(
|
||||
snmpEngine, authData, transportTarget, contextData.contextName)
|
||||
|
||||
future = asyncio.Future()
|
||||
|
||||
|
@ -250,7 +251,8 @@ def setCmd(snmpEngine, authData, transportTarget, contextData,
|
|||
(errorIndication, errorStatus, errorIndex, varBindsUnmade)
|
||||
)
|
||||
|
||||
addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
|
||||
addrName, paramsName = lcd.configure(
|
||||
snmpEngine, authData, transportTarget, contextData.contextName)
|
||||
|
||||
future = asyncio.Future()
|
||||
|
||||
|
@ -361,7 +363,8 @@ def nextCmd(snmpEngine, authData, transportTarget, contextData,
|
|||
(errorIndication, errorStatus, errorIndex, varBindsUnmade)
|
||||
)
|
||||
|
||||
addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
|
||||
addrName, paramsName = lcd.configure(
|
||||
snmpEngine, authData, transportTarget, contextData.contextName)
|
||||
|
||||
future = asyncio.Future()
|
||||
|
||||
|
@ -501,7 +504,8 @@ def bulkCmd(snmpEngine, authData, transportTarget, contextData,
|
|||
(errorIndication, errorStatus, errorIndex, varBindsUnmade)
|
||||
)
|
||||
|
||||
addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
|
||||
addrName, paramsName = lcd.configure(
|
||||
snmpEngine, authData, transportTarget, contextData.contextName)
|
||||
|
||||
future = asyncio.Future()
|
||||
|
||||
|
|
|
@ -152,8 +152,8 @@ def sendNotification(snmpEngine, authData, transportTarget, contextData,
|
|||
)
|
||||
|
||||
notifyName = lcd.configure(
|
||||
snmpEngine, authData, transportTarget, notifyType
|
||||
)
|
||||
snmpEngine, authData, transportTarget, notifyType,
|
||||
contextData.contextName)
|
||||
|
||||
future = asyncio.Future()
|
||||
|
||||
|
|
|
@ -121,7 +121,8 @@ def getCmd(snmpEngine, authData, transportTarget, contextData,
|
|||
snmpEngine.cache, varBinds, lookupMib
|
||||
), cbCtx)
|
||||
|
||||
addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
|
||||
addrName, paramsName = lcd.configure(
|
||||
snmpEngine, authData, transportTarget, contextData.contextName)
|
||||
|
||||
return cmdgen.GetCommandGenerator().sendVarBinds(
|
||||
snmpEngine, addrName, contextData.contextEngineId,
|
||||
|
@ -232,7 +233,8 @@ def setCmd(snmpEngine, authData, transportTarget, contextData,
|
|||
snmpEngine.cache, varBinds, lookupMib
|
||||
), cbCtx)
|
||||
|
||||
addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
|
||||
addrName, paramsName = lcd.configure(
|
||||
snmpEngine, authData, transportTarget, contextData.contextName)
|
||||
|
||||
return cmdgen.SetCommandGenerator().sendVarBinds(
|
||||
snmpEngine, addrName, contextData.contextEngineId,
|
||||
|
@ -343,7 +345,9 @@ def nextCmd(snmpEngine, authData, transportTarget, contextData,
|
|||
varBindTable],
|
||||
cbCtx)
|
||||
|
||||
addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
|
||||
addrName, paramsName = lcd.configure(
|
||||
snmpEngine, authData, transportTarget, contextData.contextName)
|
||||
|
||||
return cmdgen.NextCommandGenerator().sendVarBinds(
|
||||
snmpEngine, addrName,
|
||||
contextData.contextEngineId, contextData.contextName,
|
||||
|
@ -483,7 +487,8 @@ def bulkCmd(snmpEngine, authData, transportTarget, contextData,
|
|||
[vbProcessor.unmakeVarBinds(snmpEngine.cache, varBindTableRow, lookupMib) for varBindTableRow in
|
||||
varBindTable], cbCtx)
|
||||
|
||||
addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
|
||||
addrName, paramsName = lcd.configure(
|
||||
snmpEngine, authData, transportTarget, contextData.contextName)
|
||||
|
||||
return cmdgen.BulkCommandGenerator().sendVarBinds(
|
||||
snmpEngine, addrName, contextData.contextEngineId,
|
||||
|
|
|
@ -162,7 +162,7 @@ def sendNotification(snmpEngine, authData, transportTarget, contextData,
|
|||
)
|
||||
|
||||
notifyName = lcd.configure(snmpEngine, authData, transportTarget,
|
||||
notifyType)
|
||||
notifyType, contextData.contextName)
|
||||
|
||||
return ntforg.NotificationOriginator().sendVarBinds(
|
||||
snmpEngine, notifyName,
|
||||
|
|
|
@ -8,6 +8,8 @@ from pysnmp.entity import config
|
|||
from pysnmp import nextid, error
|
||||
from pysnmp.hlapi.v3arch.auth import *
|
||||
|
||||
from pyasn1.compat.octets import null
|
||||
|
||||
__all__ = ['CommandGeneratorLcdConfigurator',
|
||||
'NotificationOriginatorLcdConfigurator']
|
||||
|
||||
|
@ -24,17 +26,17 @@ class AbstractLcdConfigurator(object):
|
|||
snmpEngine.setUserContext(**{cacheId: cache})
|
||||
return cache
|
||||
|
||||
def configure(self, snmpEngine, authData, transportTarget, *options):
|
||||
def configure(self, snmpEngine, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def unconfigure(self, snmpEngine, authData=None):
|
||||
def unconfigure(self, snmpEngine, *args, **kwargs):
|
||||
pass
|
||||
|
||||
|
||||
class CommandGeneratorLcdConfigurator(AbstractLcdConfigurator):
|
||||
cacheKeys = ['auth', 'parm', 'tran', 'addr']
|
||||
|
||||
def configure(self, snmpEngine, authData, transportTarget, *options):
|
||||
def configure(self, snmpEngine, authData, transportTarget, contextName, **options):
|
||||
cache = self._getCache(snmpEngine)
|
||||
if isinstance(authData, CommunityData):
|
||||
if authData.communityIndex not in cache['auth']:
|
||||
|
@ -117,7 +119,7 @@ class CommandGeneratorLcdConfigurator(AbstractLcdConfigurator):
|
|||
|
||||
return addrName, paramsName
|
||||
|
||||
def unconfigure(self, snmpEngine, authData=None):
|
||||
def unconfigure(self, snmpEngine, authData=None, contextName=null, **options):
|
||||
cache = self._getCache(snmpEngine)
|
||||
if authData:
|
||||
if isinstance(authData, CommunityData):
|
||||
|
@ -198,9 +200,9 @@ class NotificationOriginatorLcdConfigurator(AbstractLcdConfigurator):
|
|||
cacheKeys = ['auth', 'name']
|
||||
_cmdGenLcdCfg = CommandGeneratorLcdConfigurator()
|
||||
|
||||
def configure(self, snmpEngine, authData, transportTarget, *options):
|
||||
def configure(self, snmpEngine, authData, transportTarget, notifyType,
|
||||
contextName, **options):
|
||||
cache = self._getCache(snmpEngine)
|
||||
notifyType = options and options[0] or 'trap'
|
||||
notifyName = None
|
||||
|
||||
# Create matching transport tags if not given by user. Not good!
|
||||
|
@ -211,7 +213,8 @@ class NotificationOriginatorLcdConfigurator(AbstractLcdConfigurator):
|
|||
if isinstance(authData, CommunityData) and not authData.tag:
|
||||
authData.tag = transportTarget.tagList.split()[0]
|
||||
|
||||
addrName, paramsName = self._cmdGenLcdCfg.configure(snmpEngine, authData, transportTarget)
|
||||
addrName, paramsName = self._cmdGenLcdCfg.configure(
|
||||
snmpEngine, authData, transportTarget, contextName, **options)
|
||||
tagList = transportTarget.tagList.split()
|
||||
if not tagList:
|
||||
tagList = ['']
|
||||
|
@ -230,7 +233,7 @@ class NotificationOriginatorLcdConfigurator(AbstractLcdConfigurator):
|
|||
notifyType
|
||||
)
|
||||
cache['name'][notifyNameKey] = notifyName, paramsName, 1
|
||||
authDataKey = authData.securityName, authData.securityModel
|
||||
authDataKey = authData.securityName, authData.securityModel, authData.securityLevel, contextName
|
||||
if authDataKey in cache['auth']:
|
||||
authDataX, subTree, useCount = cache['auth'][authDataKey]
|
||||
cache['auth'][authDataKey] = authDataX, subTree, useCount + 1
|
||||
|
@ -240,23 +243,24 @@ class NotificationOriginatorLcdConfigurator(AbstractLcdConfigurator):
|
|||
authData.securityModel,
|
||||
authData.securityName,
|
||||
authData.securityLevel,
|
||||
(), (), subTree)
|
||||
(), (), subTree, contextName=contextName)
|
||||
cache['auth'][authDataKey] = authData, subTree, 1
|
||||
|
||||
return notifyName
|
||||
|
||||
def unconfigure(self, snmpEngine, authData=None):
|
||||
def unconfigure(self, snmpEngine, authData=None, contextName=null, **options):
|
||||
cache = self._getCache(snmpEngine)
|
||||
if authData:
|
||||
authDataKey = authData.securityName, authData.securityModel
|
||||
authDataKey = authData.securityName, authData.securityModel, authData.securityLevel, contextName
|
||||
if authDataKey in cache['auth']:
|
||||
authDataKeys = (authDataKey,)
|
||||
else:
|
||||
raise error.PySnmpError('Unknown authData %s' % (authData,))
|
||||
else:
|
||||
authDataKeys = tuple(cache['auth'].keys())
|
||||
authDataKeys = tuple(cache['auth'])
|
||||
|
||||
addrNames, paramsNames = self._cmdGenLcdCfg.unconfigure(snmpEngine, authData)
|
||||
addrNames, paramsNames = self._cmdGenLcdCfg.unconfigure(
|
||||
snmpEngine, authData, contextName, **options)
|
||||
|
||||
notifyAndParamsNames = [(cache['name'][x], x) for x in cache['name'].keys() if x[0] in paramsNames]
|
||||
|
||||
|
|
|
@ -128,7 +128,8 @@ def getCmd(snmpEngine, authData, transportTarget, contextData,
|
|||
else:
|
||||
deferred.callback((errorStatus, errorIndex, varBindsUnmade))
|
||||
|
||||
addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
|
||||
addrName, paramsName = lcd.configure(
|
||||
snmpEngine, authData, transportTarget, contextData.contextName)
|
||||
|
||||
deferred = Deferred()
|
||||
|
||||
|
@ -244,7 +245,8 @@ def setCmd(snmpEngine, authData, transportTarget, contextData,
|
|||
else:
|
||||
deferred.callback((errorStatus, errorIndex, varBindsUnmade))
|
||||
|
||||
addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
|
||||
addrName, paramsName = lcd.configure(
|
||||
snmpEngine, authData, transportTarget, contextData.contextName)
|
||||
|
||||
deferred = Deferred()
|
||||
|
||||
|
@ -374,7 +376,8 @@ def nextCmd(snmpEngine, authData, transportTarget, contextData,
|
|||
else:
|
||||
deferred.callback((errorStatus, errorIndex, varBindsUnmade))
|
||||
|
||||
addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
|
||||
addrName, paramsName = lcd.configure(
|
||||
snmpEngine, authData, transportTarget, contextData.contextName)
|
||||
|
||||
deferred = Deferred()
|
||||
|
||||
|
@ -532,7 +535,8 @@ def bulkCmd(snmpEngine, authData, transportTarget, contextData,
|
|||
else:
|
||||
deferred.callback((errorStatus, errorIndex, varBindsUnmade))
|
||||
|
||||
addrName, paramsName = lcd.configure(snmpEngine, authData, transportTarget)
|
||||
addrName, paramsName = lcd.configure(
|
||||
snmpEngine, authData, transportTarget, contextData.contextName)
|
||||
|
||||
deferred = Deferred()
|
||||
|
||||
|
|
|
@ -166,9 +166,8 @@ def sendNotification(snmpEngine, authData, transportTarget, contextData,
|
|||
else:
|
||||
deferred.callback((errorStatus, errorIndex, varBindsUnmade))
|
||||
|
||||
notifyName = lcd.configure(
|
||||
snmpEngine, authData, transportTarget, notifyType
|
||||
)
|
||||
notifyName = lcd.configure(snmpEngine, authData, transportTarget,
|
||||
notifyType, contextData.contextName)
|
||||
|
||||
def __trapFun(deferred):
|
||||
deferred.callback((0, 0, []))
|
||||
|
|
Loading…
Reference in New Issue