diff options
Diffstat (limited to 'examples/v3arch/asyncore/proxy')
4 files changed, 28 insertions, 20 deletions
diff --git a/examples/v3arch/asyncore/proxy/command/ipv6-to-ipv4-conversion.py b/examples/v3arch/asyncore/proxy/command/ipv6-to-ipv4-conversion.py index 2d7e0b3b..2abb1c51 100644 --- a/examples/v3arch/asyncore/proxy/command/ipv6-to-ipv4-conversion.py +++ b/examples/v3arch/asyncore/proxy/command/ipv6-to-ipv4-conversion.py @@ -79,6 +79,7 @@ config.addV1System(snmpEngine, '0-distant-area', 'public', transportTag='remote' config.addTargetParams( snmpEngine, 'distant-agent-auth', '0-distant-area', 'noAuthNoPriv', 1 ) + config.addTargetAddr( snmpEngine, 'distant-agent', udp.DOMAIN_NAME, ('104.236.166.95', 161), @@ -90,13 +91,13 @@ config.addContext(snmpEngine, '') class CommandResponder(cmdrsp.CommandResponderBase): - cmdGenMap = { + CMDGEN_MAP = { v2c.GetRequestPDU.tagSet: cmdgen.GetCommandGenerator(), v2c.SetRequestPDU.tagSet: cmdgen.SetCommandGenerator(), v2c.GetNextRequestPDU.tagSet: cmdgen.NextCommandGeneratorSingleRun(), v2c.GetBulkRequestPDU.tagSet: cmdgen.BulkCommandGeneratorSingleRun() } - SUPPORTED_PDU_TYPES = cmdGenMap.keys() # This app will handle these PDUs + SUPPORTED_PDU_TYPES = tuple(CMDGEN_MAP) # This app will handle these PDUs # SNMP request relay def handleMgmtOperation(self, snmpEngine, stateReference, contextName, @@ -104,12 +105,13 @@ class CommandResponder(cmdrsp.CommandResponderBase): cbCtx = stateReference, PDU contextEngineId = None # address authoritative SNMP Engine try: - self.cmdGenMap[PDU.tagSet].sendPdu( + self.CMDGEN_MAP[PDU.tagSet].sendPdu( snmpEngine, 'distant-agent', contextEngineId, contextName, PDU, self.handleResponsePdu, cbCtx ) + except error.PySnmpError: self.handleResponsePdu( snmpEngine, stateReference, 'error', None, cbCtx @@ -139,6 +141,6 @@ snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish # Run I/O dispatcher which would receive queries and send responses try: snmpEngine.transportDispatcher.runDispatcher() -except: + +finally: snmpEngine.transportDispatcher.closeDispatcher() - raise diff --git a/examples/v3arch/asyncore/proxy/command/v2c-to-v1-conversion.py b/examples/v3arch/asyncore/proxy/command/v2c-to-v1-conversion.py index 69916cb0..b56e7734 100644 --- a/examples/v3arch/asyncore/proxy/command/v2c-to-v1-conversion.py +++ b/examples/v3arch/asyncore/proxy/command/v2c-to-v1-conversion.py @@ -89,13 +89,13 @@ config.addContext(snmpEngine, '') class CommandResponder(cmdrsp.CommandResponderBase): - cmdGenMap = { + CMDGEN_MAP = { v2c.GetRequestPDU.tagSet: cmdgen.GetCommandGenerator(), v2c.SetRequestPDU.tagSet: cmdgen.SetCommandGenerator(), v2c.GetNextRequestPDU.tagSet: cmdgen.NextCommandGeneratorSingleRun(), v2c.GetBulkRequestPDU.tagSet: cmdgen.BulkCommandGeneratorSingleRun() } - SUPPORTED_PDU_TYPES = cmdGenMap.keys() # This app will handle these PDUs + SUPPORTED_PDU_TYPES = tuple(CMDGEN_MAP) # This app will handle these PDUs # SNMP request relay def handleMgmtOperation(self, snmpEngine, stateReference, contextName, @@ -103,12 +103,13 @@ class CommandResponder(cmdrsp.CommandResponderBase): cbCtx = stateReference, PDU contextEngineId = None # address authoritative SNMP Engine try: - self.cmdGenMap[PDU.tagSet].sendPdu( + self.CMDGEN_MAP[PDU.tagSet].sendPdu( snmpEngine, 'distant-agent', contextEngineId, contextName, PDU, self.handleResponsePdu, cbCtx ) + except error.PySnmpError: self.handleResponsePdu( snmpEngine, stateReference, 'error', None, cbCtx @@ -138,6 +139,6 @@ snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish # Run I/O dispatcher which would receive queries and send responses try: snmpEngine.transportDispatcher.runDispatcher() -except: + +finally: snmpEngine.transportDispatcher.closeDispatcher() - raise diff --git a/examples/v3arch/asyncore/proxy/command/v2c-to-v3-conversion.py b/examples/v3arch/asyncore/proxy/command/v2c-to-v3-conversion.py index 3e370e3c..46e3738f 100644 --- a/examples/v3arch/asyncore/proxy/command/v2c-to-v3-conversion.py +++ b/examples/v3arch/asyncore/proxy/command/v2c-to-v3-conversion.py @@ -78,6 +78,7 @@ config.addV3User( config.addTargetParams( snmpEngine, 'distant-agent-auth', 'usr-md5-none', 'authNoPriv' ) + config.addTargetAddr( snmpEngine, 'distant-agent', udp.DOMAIN_NAME + (2,), ('104.236.166.95', 161), @@ -89,26 +90,28 @@ config.addContext(snmpEngine, '') class CommandResponder(cmdrsp.CommandResponderBase): - cmdGenMap = { + CMDGEN_MAP = { v2c.GetRequestPDU.tagSet: cmdgen.GetCommandGenerator(), v2c.SetRequestPDU.tagSet: cmdgen.SetCommandGenerator(), v2c.GetNextRequestPDU.tagSet: cmdgen.NextCommandGeneratorSingleRun(), v2c.GetBulkRequestPDU.tagSet: cmdgen.BulkCommandGeneratorSingleRun() } - SUPPORTED_PDU_TYPES = cmdGenMap.keys() # This app will handle these PDUs + SUPPORTED_PDU_TYPES = tuple(CMDGEN_MAP) # This app will handle these PDUs # SNMP request relay def handleMgmtOperation(self, snmpEngine, stateReference, contextName, PDU, acInfo): cbCtx = stateReference, PDU contextEngineId = None # address authoritative SNMP Engine + try: - self.cmdGenMap[PDU.tagSet].sendPdu( + self.CMDGEN_MAP[PDU.tagSet].sendPdu( snmpEngine, 'distant-agent', contextEngineId, contextName, PDU, self.handleResponsePdu, cbCtx ) + except error.PySnmpError: self.handleResponsePdu( snmpEngine, stateReference, 'error', None, cbCtx @@ -138,6 +141,6 @@ snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish # Run I/O dispatcher which would receive queries and send responses try: snmpEngine.transportDispatcher.runDispatcher() -except: + +finally: snmpEngine.transportDispatcher.closeDispatcher() - raise diff --git a/examples/v3arch/asyncore/proxy/command/v3-to-v2c-conversion.py b/examples/v3arch/asyncore/proxy/command/v3-to-v2c-conversion.py index 4794f49c..5a2443f3 100644 --- a/examples/v3arch/asyncore/proxy/command/v3-to-v2c-conversion.py +++ b/examples/v3arch/asyncore/proxy/command/v3-to-v2c-conversion.py @@ -92,13 +92,14 @@ config.addContext(snmpEngine, '') class CommandResponder(cmdrsp.CommandResponderBase): - cmdGenMap = { + CMDGEN_MAP = { v2c.GetRequestPDU.tagSet: cmdgen.GetCommandGenerator(), v2c.SetRequestPDU.tagSet: cmdgen.SetCommandGenerator(), v2c.GetNextRequestPDU.tagSet: cmdgen.NextCommandGeneratorSingleRun(), v2c.GetBulkRequestPDU.tagSet: cmdgen.BulkCommandGeneratorSingleRun() } - SUPPORTED_PDU_TYPES = cmdGenMap.keys() # This app will handle these PDUs + + SUPPORTED_PDU_TYPES = tuple(CMDGEN_MAP) # This app will handle these PDUs # SNMP request relay def handleMgmtOperation(self, snmpEngine, stateReference, contextName, @@ -106,12 +107,13 @@ class CommandResponder(cmdrsp.CommandResponderBase): cbCtx = stateReference, PDU contextEngineId = None # address authoritative SNMP Engine try: - self.cmdGenMap[PDU.tagSet].sendPdu( + self.CMDGEN_MAP[PDU.tagSet].sendPdu( snmpEngine, 'distant-agent', contextEngineId, contextName, PDU, self.handleResponsePdu, cbCtx ) + except error.PySnmpError: self.handleResponsePdu( snmpEngine, stateReference, 'error', None, cbCtx @@ -139,6 +141,6 @@ snmpEngine.transportDispatcher.jobStarted(1) # this job would never finish # Run I/O dispatcher which would receive queries and send responses try: snmpEngine.transportDispatcher.runDispatcher() -except: + +finally: snmpEngine.transportDispatcher.closeDispatcher() - raise |