diff options
Diffstat (limited to 'pysnmp/entity')
-rw-r--r-- | pysnmp/entity/config.py | 100 | ||||
-rw-r--r-- | pysnmp/entity/engine.py | 24 | ||||
-rw-r--r-- | pysnmp/entity/rfc3413/cmdgen.py | 20 | ||||
-rw-r--r-- | pysnmp/entity/rfc3413/cmdrsp.py | 18 | ||||
-rw-r--r-- | pysnmp/entity/rfc3413/config.py | 10 | ||||
-rw-r--r-- | pysnmp/entity/rfc3413/context.py | 10 | ||||
-rw-r--r-- | pysnmp/entity/rfc3413/ntforg.py | 40 | ||||
-rw-r--r-- | pysnmp/entity/rfc3413/ntfrcv.py | 12 |
8 files changed, 119 insertions, 115 deletions
diff --git a/pysnmp/entity/config.py b/pysnmp/entity/config.py index 2ea0ea59..e89a102a 100644 --- a/pysnmp/entity/config.py +++ b/pysnmp/entity/config.py @@ -17,48 +17,52 @@ from pysnmp import error # A shortcut to popular constants # Transports -snmpUDPDomain = udp.snmpUDPDomain -snmpUDP6Domain = udp6.snmpUDP6Domain +SNMP_UDP_DOMAIN = udp.SNMP_UDP_DOMAIN +SNMP_UDP6_DOMAIN = udp6.SNMP_UDP6_DOMAIN # Auth protocol -usmHMACMD5AuthProtocol = hmacmd5.HmacMd5.serviceID -usmHMACSHAAuthProtocol = hmacsha.HmacSha.serviceID -usmHMAC128SHA224AuthProtocol = hmacsha2.HmacSha2.sha224ServiceID -usmHMAC192SHA256AuthProtocol = hmacsha2.HmacSha2.sha256ServiceID -usmHMAC256SHA384AuthProtocol = hmacsha2.HmacSha2.sha384ServiceID -usmHMAC384SHA512AuthProtocol = hmacsha2.HmacSha2.sha512ServiceID - -usmNoAuthProtocol = noauth.NoAuth.serviceID +USM_AUTH_HMAC96_MD5 = hmacmd5.HmacMd5.SERVICE_ID +USM_AUTH_HMAC96_SHA = hmacsha.HmacSha.SERVICE_ID +USM_AUTH_HMAC128_SHA224 = hmacsha2.HmacSha2.SHA224_SERVICE_ID +USM_AUTH_HMAC192_SHA256 = hmacsha2.HmacSha2.SHA256_SERVICE_ID +USM_AUTH_HMAC256_SHA384 = hmacsha2.HmacSha2.SHA384_SERVICE_ID +USM_AUTH_HMAC384_SHA512 = hmacsha2.HmacSha2.SHA512_SERVICE_ID + +USM_AUTH_NONE = noauth.NoAuth.SERVICE_ID """No authentication service""" # Privacy protocol -usmDESPrivProtocol = des.Des.serviceID -usm3DESEDEPrivProtocol = des3.Des3.serviceID -usmAesCfb128Protocol = aes.Aes.serviceID -usmAesBlumenthalCfb192Protocol = aes192.AesBlumenthal192.serviceID # semi-standard but not widely used -usmAesBlumenthalCfb256Protocol = aes256.AesBlumenthal256.serviceID # semi-standard but not widely used -usmAesCfb192Protocol = aes192.Aes192.serviceID # non-standard but used by many vendors -usmAesCfb256Protocol = aes256.Aes256.serviceID # non-standard but used by many vendors -usmNoPrivProtocol = nopriv.NoPriv.serviceID - -# Auth services -authServices = {hmacmd5.HmacMd5.serviceID: hmacmd5.HmacMd5(), - hmacsha.HmacSha.serviceID: hmacsha.HmacSha(), - hmacsha2.HmacSha2.sha224ServiceID: hmacsha2.HmacSha2(hmacsha2.HmacSha2.sha224ServiceID), - hmacsha2.HmacSha2.sha256ServiceID: hmacsha2.HmacSha2(hmacsha2.HmacSha2.sha256ServiceID), - hmacsha2.HmacSha2.sha384ServiceID: hmacsha2.HmacSha2(hmacsha2.HmacSha2.sha384ServiceID), - hmacsha2.HmacSha2.sha512ServiceID: hmacsha2.HmacSha2(hmacsha2.HmacSha2.sha512ServiceID), - noauth.NoAuth.serviceID: noauth.NoAuth()} - -# Privacy services -privServices = {des.Des.serviceID: des.Des(), - des3.Des3.serviceID: des3.Des3(), - aes.Aes.serviceID: aes.Aes(), - aes192.AesBlumenthal192.serviceID: aes192.AesBlumenthal192(), - aes256.AesBlumenthal256.serviceID: aes256.AesBlumenthal256(), - aes192.Aes192.serviceID: aes192.Aes192(), # non-standard - aes256.Aes256.serviceID: aes256.Aes256(), # non-standard - nopriv.NoPriv.serviceID: nopriv.NoPriv()} +USM_PRIV_CBC56_DES = des.Des.SERVICE_ID +USM_PRIV_CBC168_3DES = des3.Des3.SERVICE_ID +USM_PRIV_CFB128_AES = aes.Aes.SERVICE_ID +USM_PRIV_CFB192_AES = aes192.Aes192.SERVICE_ID # non-standard but used by many vendors +USM_PRIV_CFB256_AES = aes256.Aes256.SERVICE_ID # non-standard but used by many vendors +USM_PRIV_CFB192_AES_BLUMENTHAL = aes192.AesBlumenthal192.SERVICE_ID # semi-standard but not widely used +USM_PRIV_CFB256_AES_BLUMENTHAL = aes256.AesBlumenthal256.SERVICE_ID # semi-standard but not widely used + +USM_PRIV_NONE = nopriv.NoPriv.SERVICE_ID + +AUTH_SERVICES = { + hmacmd5.HmacMd5.SERVICE_ID: hmacmd5.HmacMd5(), + hmacsha.HmacSha.SERVICE_ID: hmacsha.HmacSha(), + hmacsha2.HmacSha2.SHA224_SERVICE_ID: hmacsha2.HmacSha2(hmacsha2.HmacSha2.SHA224_SERVICE_ID), + hmacsha2.HmacSha2.SHA256_SERVICE_ID: hmacsha2.HmacSha2(hmacsha2.HmacSha2.SHA256_SERVICE_ID), + hmacsha2.HmacSha2.SHA384_SERVICE_ID: hmacsha2.HmacSha2(hmacsha2.HmacSha2.SHA384_SERVICE_ID), + hmacsha2.HmacSha2.SHA512_SERVICE_ID: hmacsha2.HmacSha2(hmacsha2.HmacSha2.SHA512_SERVICE_ID), + noauth.NoAuth.SERVICE_ID: noauth.NoAuth() +} + +PRIV_SERVICES = { + des.Des.SERVICE_ID: des.Des(), + des3.Des3.SERVICE_ID: des3.Des3(), + aes.Aes.SERVICE_ID: aes.Aes(), + aes192.AesBlumenthal192.SERVICE_ID: aes192.AesBlumenthal192(), + aes256.AesBlumenthal256.SERVICE_ID: aes256.AesBlumenthal256(), + aes192.Aes192.SERVICE_ID: aes192.Aes192(), # non-standard + aes256.Aes256.SERVICE_ID: aes256.Aes256(), # non-standard + nopriv.NoPriv.SERVICE_ID: nopriv.NoPriv() +} + # This module uses Management Instrumentation subsystem in purely # synchronous manner. The assumption is that the Management @@ -133,8 +137,8 @@ def __cookV3UserInfo(snmpEngine, securityName, securityEngineId): def addV3User(snmpEngine, userName, - authProtocol=usmNoAuthProtocol, authKey=None, - privProtocol=usmNoPrivProtocol, privKey=None, + authProtocol=USM_AUTH_NONE, authKey=None, + privProtocol=USM_PRIV_NONE, privKey=None, securityEngineId=None, securityName=None): mibBuilder = snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder @@ -166,21 +170,21 @@ def addV3User(snmpEngine, userName, ) # Localize keys - if authProtocol in authServices: - hashedAuthPassphrase = authServices[authProtocol].hashPassphrase( + if authProtocol in AUTH_SERVICES: + hashedAuthPassphrase = AUTH_SERVICES[authProtocol].hashPassphrase( authKey and authKey or null ) - localAuthKey = authServices[authProtocol].localizeKey( + localAuthKey = AUTH_SERVICES[authProtocol].localizeKey( hashedAuthPassphrase, snmpEngineID ) else: raise error.PySnmpError('Unknown auth protocol %s' % (authProtocol,)) - if privProtocol in privServices: - hashedPrivPassphrase = privServices[privProtocol].hashPassphrase( + if privProtocol in PRIV_SERVICES: + hashedPrivPassphrase = PRIV_SERVICES[privProtocol].hashPassphrase( authProtocol, privKey and privKey or null ) - localPrivKey = privServices[privProtocol].localizeKey( + localPrivKey = PRIV_SERVICES[privProtocol].localizeKey( authProtocol, hashedPrivPassphrase, snmpEngineID ) else: @@ -318,13 +322,13 @@ def addTargetAddr(snmpEngine, addrName, transportDomain, transportAddress, (snmpTargetAddrEntry, snmpSourceAddrEntry, tblIdx) = __cookTargetAddrInfo(snmpEngine, addrName) - if transportDomain[:len(snmpUDPDomain)] == snmpUDPDomain: + if transportDomain[:len(SNMP_UDP_DOMAIN)] == SNMP_UDP_DOMAIN: SnmpUDPAddress, = mibBuilder.importSymbols('SNMPv2-TM', 'SnmpUDPAddress') transportAddress = SnmpUDPAddress(transportAddress) if sourceAddress is None: sourceAddress = ('0.0.0.0', 0) sourceAddress = SnmpUDPAddress(sourceAddress) - elif transportDomain[:len(snmpUDP6Domain)] == snmpUDP6Domain: + elif transportDomain[:len(SNMP_UDP6_DOMAIN)] == SNMP_UDP6_DOMAIN: TransportAddressIPv6, = mibBuilder.importSymbols('TRANSPORT-ADDRESS-MIB', 'TransportAddressIPv6') transportAddress = TransportAddressIPv6(transportAddress) if sourceAddress is None: @@ -365,7 +369,7 @@ def addTransport(snmpEngine, transportDomain, transport): 'Transport %r is not compatible with dispatcher %r' % (transport, snmpEngine.transportDispatcher)) else: snmpEngine.registerTransportDispatcher( - transport.protoTransportDispatcher() + transport.PROTO_TRANSPORT_DISPATCHER() ) # here we note that we have created transportDispatcher automatically snmpEngine.setUserContext(automaticTransportDispatcher=0) diff --git a/pysnmp/entity/engine.py b/pysnmp/entity/engine.py index 11abec6e..8c4e363a 100644 --- a/pysnmp/entity/engine.py +++ b/pysnmp/entity/engine.py @@ -64,21 +64,21 @@ class SnmpEngine(object): else: self.msgAndPduDsp = msgAndPduDsp self.messageProcessingSubsystems = { - SnmpV1MessageProcessingModel.messageProcessingModelID: + SnmpV1MessageProcessingModel.MESSAGE_PROCESSING_MODEL_ID: SnmpV1MessageProcessingModel(), - SnmpV2cMessageProcessingModel.messageProcessingModelID: + SnmpV2cMessageProcessingModel.MESSAGE_PROCESSING_MODEL_ID: SnmpV2cMessageProcessingModel(), - SnmpV3MessageProcessingModel.messageProcessingModelID: + SnmpV3MessageProcessingModel.MESSAGE_PROCESSING_MODEL_ID: SnmpV3MessageProcessingModel() } self.securityModels = { - SnmpV1SecurityModel.securityModelID: SnmpV1SecurityModel(), - SnmpV2cSecurityModel.securityModelID: SnmpV2cSecurityModel(), - SnmpUSMSecurityModel.securityModelID: SnmpUSMSecurityModel() + SnmpV1SecurityModel.SECURITY_MODEL_ID: SnmpV1SecurityModel(), + SnmpV2cSecurityModel.SECURITY_MODEL_ID: SnmpV2cSecurityModel(), + SnmpUSMSecurityModel.SECURITY_MODEL_ID: SnmpUSMSecurityModel() } self.accessControlModel = { - void.Vacm.accessModelID: void.Vacm(), - rfc3415.Vacm.accessModelID: rfc3415.Vacm() + void.Vacm.ACCESS_MODEL_ID: void.Vacm(), + rfc3415.Vacm.ACCESS_MODEL_ID: rfc3415.Vacm() } self.transportDispatcher = None @@ -102,7 +102,7 @@ class SnmpEngine(object): origSnmpEngineID.syntax = origSnmpEngineID.syntax.clone(snmpEngineID) self.snmpEngineID = origSnmpEngineID.syntax - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'SnmpEngine: using custom SNMP Engine ID: %s' % self.snmpEngineID.prettyPrint()) # Attempt to make some of snmp Engine settings persistent. @@ -110,7 +110,7 @@ class SnmpEngine(object): persistentPath = os.path.join(tempfile.gettempdir(), '__pysnmp', self.snmpEngineID.prettyPrint()) - debug.logger & debug.flagApp and debug.logger('SnmpEngine: using persistent directory: %s' % persistentPath) + debug.logger & debug.FLAG_APP and debug.logger('SnmpEngine: using persistent directory: %s' % persistentPath) if not os.path.exists(persistentPath): try: @@ -135,10 +135,10 @@ class SnmpEngine(object): os.close(fd) shutil.move(fn, f) except Exception as exc: - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'SnmpEngine: could not stored SNMP Engine Boots: %s' % exc) else: - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'SnmpEngine: stored SNMP Engine Boots: %s' % snmpEngineBoots.syntax.prettyPrint()) def __repr__(self): diff --git a/pysnmp/entity/rfc3413/cmdgen.py b/pysnmp/entity/rfc3413/cmdgen.py index 59503d52..9ca9b50b 100644 --- a/pysnmp/entity/rfc3413/cmdgen.py +++ b/pysnmp/entity/rfc3413/cmdgen.py @@ -46,7 +46,7 @@ class CommandGenerator(object): # 3.1.3 if statusInformation: - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'processResponsePdu: sendPduHandle %s, statusInformation %s' % (sendPduHandle, statusInformation)) errorIndication = statusInformation['errorIndication'] @@ -59,7 +59,7 @@ class CommandGenerator(object): origRetries += 1 if origRetries > origRetryCount or origDiscoveryRetries > self.__options.get('discoveryRetries', 4): - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'processResponsePdu: sendPduHandle %s, retry count %d exceeded' % (sendPduHandle, origRetries)) cbFun(snmpEngine, origSendRequestHandle, errorIndication, None, cbCtx) return @@ -94,7 +94,7 @@ class CommandGenerator(object): except StatusInformation as exc: statusInformation = exc - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'processResponsePdu: origSendRequestHandle %s, _sendPdu() failed with %r' % ( sendPduHandle, statusInformation)) cbFun(snmpEngine, origSendRequestHandle, @@ -108,7 +108,7 @@ class CommandGenerator(object): origContextEngineId and origContextEngineId != contextEngineId or origContextName and origContextName != contextName or origPduVersion != pduVersion): - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'processResponsePdu: sendPduHandle %s, request/response data mismatch' % sendPduHandle) cbFun(snmpEngine, origSendRequestHandle, @@ -121,7 +121,7 @@ class CommandGenerator(object): # 3.1.2 if v2c.apiPDU.getRequestID(PDU) != v2c.apiPDU.getRequestID(origPdu): - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'processResponsePdu: sendPduHandle %s, request-id/response-id mismatch' % sendPduHandle) cbFun(snmpEngine, origSendRequestHandle, 'badResponse', None, cbCtx) @@ -176,7 +176,7 @@ class CommandGenerator(object): retryCount, 0, 0 ) - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'sendPdu: sendPduHandle %s, timeout %d*10 ms/%d ticks, retry 0 of %d' % ( sendPduHandle, timeout, timeoutInTicks, retryCount)) @@ -273,7 +273,7 @@ class NextCommandGenerator(NextCommandGeneratorSingleRun): v2c.apiPDU.getErrorStatus(PDU), v2c.apiPDU.getErrorIndex(PDU, muteErrors=True), varBindTable, cbCtx): - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'processResponseVarBinds: sendRequestHandle %s, app says to stop walking' % sendRequestHandle) return # app says enough @@ -292,7 +292,7 @@ class NextCommandGenerator(NextCommandGeneratorSingleRun): except StatusInformation as exc: statusInformation = exc - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'sendVarBinds: sendPduHandle %s: sendPdu() failed with %r' % (sendRequestHandle, statusInformation)) cbFun(snmpEngine, sendRequestHandle, statusInformation['errorIndication'], @@ -356,7 +356,7 @@ class BulkCommandGenerator(BulkCommandGeneratorSingleRun): v2c.apiBulkPDU.getErrorStatus(PDU), v2c.apiBulkPDU.getErrorIndex(PDU, muteErrors=True), varBindTable, cbCtx): - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'processResponseVarBinds: sendRequestHandle %s, app says to stop walking' % sendRequestHandle) return # app says enough @@ -375,7 +375,7 @@ class BulkCommandGenerator(BulkCommandGeneratorSingleRun): except StatusInformation as exc: statusInformation = exc - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'processResponseVarBinds: sendPduHandle %s: _sendPdu() failed with %r' % ( sendRequestHandle, statusInformation)) cbFun(snmpEngine, sendRequestHandle, diff --git a/pysnmp/entity/rfc3413/cmdrsp.py b/pysnmp/entity/rfc3413/cmdrsp.py index 461ba235..52951a4b 100644 --- a/pysnmp/entity/rfc3413/cmdrsp.py +++ b/pysnmp/entity/rfc3413/cmdrsp.py @@ -15,7 +15,7 @@ from pysnmp import debug # 3.2 class CommandResponderBase(object): - acmID = 3 # default MIB access control method to use + ACM_ID = 3 # default MIB access control method to use SUPPORTED_PDU_TYPES = () SMI_ERROR_MAP = { pysnmp.smi.error.TooBigError: 'tooBig', @@ -75,7 +75,7 @@ class CommandResponderBase(object): v2c.apiPDU.setErrorIndex(PDU, errorIndex) v2c.apiPDU.setVarBinds(PDU, varBinds) - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'sendVarBinds: stateReference %s, errorStatus %s, errorIndex %s, varBinds %s' % ( stateReference, errorStatus, errorIndex, varBinds) ) @@ -117,7 +117,7 @@ class CommandResponderBase(object): ) except error.StatusInformation as exc: - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'sendPdu: stateReference %s, statusInformation %s' % (stateReference, exc)) snmpSilentDrops, = snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder.importSymbols('__SNMPv2-MIB', 'snmpSilentDrops') @@ -140,8 +140,8 @@ class CommandResponderBase(object): origPdu = None # 3.2.1 - if (PDU.tagSet not in rfc3411.readClassPDUs and - PDU.tagSet not in rfc3411.writeClassPDUs): + if (PDU.tagSet not in rfc3411.READ_CLASS_PDUS and + PDU.tagSet not in rfc3411.WRITE_CLASS_PDUS): raise error.ProtocolError('Unexpected PDU class %s' % PDU.tagSet) # 3.2.2 --> no-op @@ -160,7 +160,7 @@ class CommandResponderBase(object): # 3.2.5 varBinds = v2c.apiPDU.getVarBinds(PDU) - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'processPdu: stateReference %s, varBinds %s' % (stateReference, varBinds)) self.initiateMgmtOperation(snmpEngine, stateReference, contextName, PDU) @@ -194,7 +194,7 @@ class CommandResponderBase(object): context['pduType']) try: - snmpEngine.accessControlModel[cls.acmID].isAccessAllowed( + snmpEngine.accessControlModel[cls.ACM_ID].isAccessAllowed( snmpEngine, securityModel, securityName, securityLevel, viewType, contextName, name ) @@ -202,7 +202,7 @@ class CommandResponderBase(object): # Map ACM errors onto SMI ones except error.StatusInformation as exc: statusInformation = exc - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( '__verifyAccess: name %s, statusInformation %s' % (name, statusInformation)) errorIndication = statusInformation['errorIndication'] # 3.2.5... @@ -469,7 +469,7 @@ class BulkCommandResponder(NextCommandResponder): if R: M = min(M, self.maxVarBinds // R) - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'initiateMgmtOperation: N %d, M %d, R %d' % (N, M, R)) mgmtFun = self._getMgmtFun(contextName) diff --git a/pysnmp/entity/rfc3413/config.py b/pysnmp/entity/rfc3413/config.py index 144aa486..7689824b 100644 --- a/pysnmp/entity/rfc3413/config.py +++ b/pysnmp/entity/rfc3413/config.py @@ -63,20 +63,20 @@ def getTargetAddr(snmpEngine, snmpTargetAddrName): transport = snmpEngine.transportDispatcher.getTransport(snmpTargetAddrTDomain) - if snmpTargetAddrTDomain[:len(config.snmpUDPDomain)] == config.snmpUDPDomain: + if snmpTargetAddrTDomain[:len(config.SNMP_UDP_DOMAIN)] == config.SNMP_UDP_DOMAIN: SnmpUDPAddress, = snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder.importSymbols('SNMPv2-TM', 'SnmpUDPAddress') - snmpTargetAddrTAddress = transport.addressType( + snmpTargetAddrTAddress = transport.ADDRESS_TYPE( SnmpUDPAddress(snmpTargetAddrTAddress) ).setLocalAddress(SnmpUDPAddress(snmpSourceAddrTAddress)) - elif snmpTargetAddrTDomain[:len(config.snmpUDP6Domain)] == config.snmpUDP6Domain: + elif snmpTargetAddrTDomain[:len(config.SNMP_UDP6_DOMAIN)] == config.SNMP_UDP6_DOMAIN: TransportAddressIPv6, = snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder.importSymbols( 'TRANSPORT-ADDRESS-MIB', 'TransportAddressIPv6') - snmpTargetAddrTAddress = transport.addressType( + snmpTargetAddrTAddress = transport.ADDRESS_TYPE( TransportAddressIPv6(snmpTargetAddrTAddress) ).setLocalAddress(TransportAddressIPv6(snmpSourceAddrTAddress)) elif snmpTargetAddrTDomain[:len(config.snmpLocalDomain)] == config.snmpLocalDomain: - snmpTargetAddrTAddress = transport.addressType( + snmpTargetAddrTAddress = transport.ADDRESS_TYPE( snmpTargetAddrTAddress ) diff --git a/pysnmp/entity/rfc3413/context.py b/pysnmp/entity/rfc3413/context.py index 3975e670..7d3c3262 100644 --- a/pysnmp/entity/rfc3413/context.py +++ b/pysnmp/entity/rfc3413/context.py @@ -19,7 +19,7 @@ class SnmpContext(object): self.contextEngineId = snmpEngineId.syntax else: self.contextEngineId = snmpEngineId.syntax.clone(contextEngineId) - debug.logger & debug.flagIns and debug.logger('SnmpContext: contextEngineId \"%r\"' % (self.contextEngineId,)) + debug.logger & debug.FLAG_INS and debug.logger('SnmpContext: contextEngineId \"%r\"' % (self.contextEngineId,)) self.contextNames = { null: snmpEngine.msgAndPduDsp.mibInstrumController # Default name } @@ -30,7 +30,7 @@ class SnmpContext(object): raise error.PySnmpError( 'Duplicate contextName %s' % contextName ) - debug.logger & debug.flagIns and debug.logger( + debug.logger & debug.FLAG_INS and debug.logger( 'registerContextName: registered contextName %r, mibInstrum %r' % (contextName, mibInstrum)) if mibInstrum is None: self.contextNames[contextName] = self.contextNames[null] @@ -40,18 +40,18 @@ class SnmpContext(object): def unregisterContextName(self, contextName): contextName = univ.OctetString(contextName).asOctets() if contextName in self.contextNames: - debug.logger & debug.flagIns and debug.logger( + debug.logger & debug.FLAG_INS and debug.logger( 'unregisterContextName: unregistered contextName %r' % contextName) del self.contextNames[contextName] def getMibInstrum(self, contextName=null): contextName = univ.OctetString(contextName).asOctets() if contextName not in self.contextNames: - debug.logger & debug.flagIns and debug.logger('getMibInstrum: contextName %r not registered' % contextName) + debug.logger & debug.FLAG_INS and debug.logger('getMibInstrum: contextName %r not registered' % contextName) raise error.PySnmpError( 'Missing contextName %s' % contextName ) else: - debug.logger & debug.flagIns and debug.logger( + debug.logger & debug.FLAG_INS and debug.logger( 'getMibInstrum: contextName %r, mibInstum %r' % (contextName, self.contextNames[contextName])) return self.contextNames[contextName] diff --git a/pysnmp/entity/rfc3413/ntforg.py b/pysnmp/entity/rfc3413/ntforg.py index 263dbb79..0c686635 100644 --- a/pysnmp/entity/rfc3413/ntforg.py +++ b/pysnmp/entity/rfc3413/ntforg.py @@ -19,7 +19,7 @@ getNextHandle = nextid.Integer(0x7fffffff) class NotificationOriginator(object): - acmID = 3 # default MIB access control method to use + ACM_ID = 3 # default MIB access control method to use def __init__(self, **options): self.__pendingReqs = {} @@ -46,7 +46,7 @@ class NotificationOriginator(object): snmpEngine.transportDispatcher.jobFinished(id(self)) if statusInformation: - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'processResponsePdu: sendRequestHandle %s, sendPduHandle %s statusInformation %s' % ( sendRequestHandle, sendPduHandle, statusInformation)) @@ -60,7 +60,7 @@ class NotificationOriginator(object): origRetries += 1 if origRetries > origRetryCount or origDiscoveryRetries > self.__options.get('discoveryRetries', 4): - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'processResponsePdu: sendRequestHandle %s, sendPduHandle %s retry count %d exceeded' % ( sendRequestHandle, sendPduHandle, origRetries)) cbFun(snmpEngine, sendRequestHandle, errorIndication, None, cbCtx) @@ -89,7 +89,7 @@ class NotificationOriginator(object): ) except error.StatusInformation as exc: statusInformation = exc - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'processResponsePdu: sendRequestHandle %s: sendPdu() failed with %r ' % ( sendRequestHandle, statusInformation)) cbFun(snmpEngine, sendRequestHandle, @@ -98,7 +98,7 @@ class NotificationOriginator(object): snmpEngine.transportDispatcher.jobStarted(id(self)) - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'processResponsePdu: sendRequestHandle %s, sendPduHandle %s, timeout %d, retry %d of %d' % ( sendRequestHandle, sendPduHandle, origTimeout, origRetries, origRetryCount)) @@ -136,7 +136,7 @@ class NotificationOriginator(object): pduVersion = 1 # 3.3.5 - if reqPDU.tagSet in rfc3411.confirmedClassPDUs: + if reqPDU.tagSet in rfc3411.CONFIRMED_CLASS_PDUS: # Convert timeout in seconds into timeout in timer ticks timeoutInTicks = float(timeout) / 100 / snmpEngine.transportDispatcher.getTimerResolution() @@ -151,7 +151,7 @@ class NotificationOriginator(object): self.processResponsePdu, (sendRequestHandle, cbFun, cbCtx) ) - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'sendPdu: sendPduHandle %s, timeout %d' % (sendPduHandle, timeout)) # 3.3.6b @@ -171,7 +171,7 @@ class NotificationOriginator(object): sendRequestHandle = None - debug.logger & debug.flagApp and debug.logger('sendPdu: message sent') + debug.logger & debug.FLAG_APP and debug.logger('sendPdu: message sent') return sendRequestHandle @@ -181,12 +181,12 @@ class NotificationOriginator(object): self.__pendingNotifications[notificationHandle].remove(sendRequestHandle) - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'processResponseVarBinds: notificationHandle %s, sendRequestHandle %s, errorIndication %s, pending requests %s' % ( notificationHandle, sendRequestHandle, errorIndication, self.__pendingNotifications[notificationHandle])) if not self.__pendingNotifications[notificationHandle]: - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'processResponseVarBinds: notificationHandle %s, sendRequestHandle %s -- completed' % ( notificationHandle, sendRequestHandle)) del self.__pendingNotifications[notificationHandle] @@ -202,7 +202,7 @@ class NotificationOriginator(object): # def sendVarBinds(self, snmpEngine, notificationTarget, contextEngineId, contextName, varBinds=(), cbFun=None, cbCtx=None): - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'sendVarBinds: notificationTarget %s, contextEngineId %s, contextName "%s", varBinds %s' % ( notificationTarget, contextEngineId or '<default>', contextName, varBinds)) @@ -216,7 +216,7 @@ class NotificationOriginator(object): notificationHandle = getNextHandle() - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'sendVarBinds: notificationHandle %s, notifyTag %s, notifyType %s' % ( notificationHandle, notifyTag, notifyType)) @@ -245,7 +245,7 @@ class NotificationOriginator(object): sendRequestHandle = -1 - debug.logger & debug.flagApp and debug.logger('sendVarBinds: final varBinds %s' % (varBinds,)) + debug.logger & debug.FLAG_APP and debug.logger('sendVarBinds: final varBinds %s' % (varBinds,)) for targetAddrName in config.getTargetNames(snmpEngine, notifyTag): (transportDomain, transportAddress, timeout, @@ -261,7 +261,7 @@ class NotificationOriginator(object): # (filterSubtree, filterMask, # filterType) = config.getNotifyFilter(filterProfileName) - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'sendVarBinds: notificationHandle %s, notifyTag %s yields: transportDomain %s, transportAddress %r, securityModel %s, securityName %s, securityLevel %s' % ( notificationHandle, notifyTag, transportDomain, transportAddress, securityModel, securityName, securityLevel)) @@ -270,16 +270,16 @@ class NotificationOriginator(object): if varName in (sysUpTime.name, snmpTrapOID.name): continue try: - snmpEngine.accessControlModel[self.acmID].isAccessAllowed( + snmpEngine.accessControlModel[self.ACM_ID].isAccessAllowed( snmpEngine, securityModel, securityName, securityLevel, 'notify', contextName, varName ) - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'sendVarBinds: ACL succeeded for OID %s securityName %s' % (varName, securityName)) except error.StatusInformation: - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'sendVarBinds: ACL denied access for OID %s securityName %s, droppping notification' % ( varName, securityName)) return @@ -305,7 +305,7 @@ class NotificationOriginator(object): except error.StatusInformation as exc: statusInformation = exc - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'sendVarBinds: sendRequestHandle %s: sendPdu() failed with %r' % ( sendRequestHandle, statusInformation)) if notificationHandle not in self.__pendingNotifications or \ @@ -318,7 +318,7 @@ class NotificationOriginator(object): cbCtx) return notificationHandle - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'sendVarBinds: notificationHandle %s, sendRequestHandle %s, timeout %d' % ( notificationHandle, sendRequestHandle, timeout)) @@ -327,7 +327,7 @@ class NotificationOriginator(object): self.__pendingNotifications[notificationHandle] = set() self.__pendingNotifications[notificationHandle].add(sendRequestHandle) - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'sendVarBinds: notificationHandle %s, sendRequestHandle %s, notification(s) sent' % ( notificationHandle, sendRequestHandle)) diff --git a/pysnmp/entity/rfc3413/ntfrcv.py b/pysnmp/entity/rfc3413/ntfrcv.py index 9e3fcc24..c286ec54 100644 --- a/pysnmp/entity/rfc3413/ntfrcv.py +++ b/pysnmp/entity/rfc3413/ntfrcv.py @@ -53,11 +53,11 @@ class NotificationReceiver(object): errorIndex = 0 varBinds = v2c.apiPDU.getVarBinds(PDU) - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'processPdu: stateReference %s, varBinds %s' % (stateReference, varBinds)) # 3.4 - if PDU.tagSet in rfc3411.confirmedClassPDUs: + if PDU.tagSet in rfc3411.CONFIRMED_CLASS_PDUS: # 3.4.1 --> no-op rspPDU = v2c.apiPDU.getResponse(PDU) @@ -67,7 +67,7 @@ class NotificationReceiver(object): v2c.apiPDU.setErrorIndex(rspPDU, errorIndex) v2c.apiPDU.setVarBinds(rspPDU, varBinds) - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'processPdu: stateReference %s, confirm PDU %s' % (stateReference, rspPDU.prettyPrint())) # Agent-side API complies with SMIv2 @@ -85,18 +85,18 @@ class NotificationReceiver(object): stateReference, statusInformation) except error.StatusInformation as exc: - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'processPdu: stateReference %s, statusInformation %s' % (stateReference, exc)) snmpSilentDrops, = snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder.importSymbols('__SNMPv2-MIB', 'snmpSilentDrops') snmpSilentDrops.syntax += 1 - elif PDU.tagSet in rfc3411.unconfirmedClassPDUs: + elif PDU.tagSet in rfc3411.UNCONFIRMED_CLASS_PDUS: pass else: raise error.ProtocolError('Unexpected PDU class %s' % PDU.tagSet) - debug.logger & debug.flagApp and debug.logger( + debug.logger & debug.FLAG_APP and debug.logger( 'processPdu: stateReference %s, user cbFun %s, cbCtx %s, varBinds %s' % ( stateReference, self.__cbFun, self.__cbCtx, varBinds)) |