diff options
author | elie <elie> | 2005-07-25 15:48:53 +0000 |
---|---|---|
committer | elie <elie> | 2005-07-25 15:48:53 +0000 |
commit | bf7b90f2ac782e67561df5cc9b0243b5e5be9a8a (patch) | |
tree | db3df65a2c846c5e07acd2aae40e7dfbb899a031 | |
parent | 142bac928b174d3231de0dfb0e8261be100ae3c5 (diff) | |
download | pysnmp-bf7b90f2ac782e67561df5cc9b0243b5e5be9a8a.tar.gz |
converted to transport dispatcher's "jobs" facility
-rw-r--r-- | examples/v3arch/manager/bulkgen.py | 24 | ||||
-rw-r--r-- | examples/v3arch/manager/getgen.py | 35 | ||||
-rw-r--r-- | examples/v3arch/manager/nextgen.py | 22 | ||||
-rw-r--r-- | examples/v3arch/manager/setgen.py | 44 |
4 files changed, 59 insertions, 66 deletions
diff --git a/examples/v3arch/manager/bulkgen.py b/examples/v3arch/manager/bulkgen.py index ccbb1da..3219906 100644 --- a/examples/v3arch/manager/bulkgen.py +++ b/examples/v3arch/manager/bulkgen.py @@ -1,5 +1,5 @@ from pysnmp.entity import engine, config -from pysnmp.entity.rfc3413 import cmdgen, error +from pysnmp.entity.rfc3413 import cmdgen from pysnmp.carrier.asynsock.dgram import udp snmpEngine = engine.SnmpEngine() @@ -29,26 +29,24 @@ config.addSocketTransport( def cbFun(sendRequesthandle, errorIndication, errorStatus, errorIndex, varBindTable, cbCtx): - if errorIndication or errorStatus: - raise error.ApplicationReturn( - errorIndication=errorIndication, - errorStatus=errorStatus - ) + if errorIndication: + print errorIndication + return + if errorStatus: + print errorStatus + return for varBindRow in varBindTable: for oid, val in varBindRow: - print '%s = %s' % (oid, val) - + print '%s = %s' % (oid, val) for oid, val in varBindTable[-1]: if val is not None: break else: - raise error.ApplicationReturn() + return # stop on end-of-table + return 1 # continue walking cmdgen.BulkCommandGenerator().sendReq( snmpEngine, 'myRouter', 0, 25, (((1,3,6,1,2,1,1), None),), cbFun ) -try: - snmpEngine.transportDispatcher.runDispatcher() -except error.ApplicationReturn, applicationReturn: - print applicationReturn +snmpEngine.transportDispatcher.runDispatcher() diff --git a/examples/v3arch/manager/getgen.py b/examples/v3arch/manager/getgen.py index 623eebf..5a2aaaf 100644 --- a/examples/v3arch/manager/getgen.py +++ b/examples/v3arch/manager/getgen.py @@ -1,6 +1,6 @@ from pysnmp.entity import engine, config from pysnmp.carrier.asynsock.dgram import udp -from pysnmp.entity.rfc3413 import cmdgen, error +from pysnmp.entity.rfc3413 import cmdgen snmpEngine = engine.SnmpEngine() @@ -29,24 +29,23 @@ config.addSocketTransport( def cbFun(sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx): - raise error.ApplicationReturn( - errorIndication=errorIndication, - errorStatus=errorStatus, - errorIndex=errorIndex, - varBinds=varBinds - ) + cbCtx['errorIndication'] = errorIndication + cbCtx['errorStatus'] = errorStatus + cbCtx['errorIndex'] = errorIndex + cbCtx['varBinds'] = varBinds + +# Used to pass data from callback function +cbCtx = {} cmdgen.GetCommandGenerator().sendReq( - snmpEngine, 'myRouter', (((1,3,6,1,2,1,1,1,0), None),), cbFun + snmpEngine, 'myRouter', (((1,3,6,1,2,1,1,1,0), None),), cbFun, cbCtx ) -try: - snmpEngine.transportDispatcher.runDispatcher() -except error.ApplicationReturn, applicationReturn: - if applicationReturn['errorIndication']: - print applicationReturn['errorIndication'] - elif applicationReturn['errorStatus']: - print repr(applicationReturn['errorStatus']) - else: - for oid, val in applicationReturn['varBinds']: - print '%s = %s' % (oid, val) +snmpEngine.transportDispatcher.runDispatcher() +if cbCtx['errorIndication']: + print cbCtx['errorIndication'] +elif cbCtx['errorStatus']: + print repr(cbCtx['errorStatus']) +else: + for oid, val in cbCtx['varBinds']: + print '%s = %s' % (oid, val) diff --git a/examples/v3arch/manager/nextgen.py b/examples/v3arch/manager/nextgen.py index 7263843..38cd206 100644 --- a/examples/v3arch/manager/nextgen.py +++ b/examples/v3arch/manager/nextgen.py @@ -1,6 +1,6 @@ from pysnmp.entity import engine, config from pysnmp.carrier.asynsock.dgram import udp -from pysnmp.entity.rfc3413 import cmdgen, error +from pysnmp.entity.rfc3413 import cmdgen snmpEngine = engine.SnmpEngine() @@ -29,26 +29,24 @@ config.addSocketTransport( def cbFun(sendRequestHandle, errorIndication, errorStatus, errorIndex, varBindTable, cbCtx): - if errorIndication or errorStatus: - raise error.ApplicationReturn( - errorIndication=errorIndication, - errorStatus=errorStatus - ) + if errorIndication: + print errorIndication + return + if errorStatus: + print errorStatus + return for varBindRow in varBindTable: for oid, val in varBindRow: print '%s = %s' % (oid, val) - for oid, val in varBindTable[-1]: if val is not None: break else: - raise error.ApplicationReturn() + return # stop on end-of-table + return 1 # continue walking cmdgen.NextCommandGenerator().sendReq( snmpEngine, 'myRouter', (((1,3,6,1,2,1,1), None),), cbFun ) -try: - snmpEngine.transportDispatcher.runDispatcher() -except error.ApplicationReturn, applicationReturn: - print applicationReturn +snmpEngine.transportDispatcher.runDispatcher() diff --git a/examples/v3arch/manager/setgen.py b/examples/v3arch/manager/setgen.py index b82d373..5ede14d 100644 --- a/examples/v3arch/manager/setgen.py +++ b/examples/v3arch/manager/setgen.py @@ -1,6 +1,6 @@ from pysnmp.entity import engine, config from pysnmp.carrier.asynsock.dgram import udp -from pysnmp.entity.rfc3413 import cmdgen, error +from pysnmp.entity.rfc3413 import cmdgen from pysnmp.proto import rfc1902 snmpEngine = engine.SnmpEngine() @@ -13,7 +13,7 @@ config.addV3User(snmpEngine, 'test-user', 'authkey1', 'md5', 'privkey1', 'des') # Transport params #config.addTargetParams(snmpEngine, 'myParams', 'test-user', 'authPriv') -config.addTargetParams(snmpEngine, 'myParams', 'test-agent', 'noAuthNoPriv', 2, 1) +config.addTargetParams(snmpEngine, 'myParams', 'test-agent', 'noAuthNoPriv', 0) # Transport addresses config.addTargetAddr( @@ -30,28 +30,26 @@ config.addSocketTransport( def cbFun(sendRequestHandle, errorIndication, errorStatus, errorIndex, varBinds, cbCtx): - raise error.ApplicationReturn( - errorIndication=errorIndication, - errorStatus=errorStatus, - errorIndex=errorIndex, - varBinds=varBinds - ) - + cbCtx['errorIndication'] = errorIndication + cbCtx['errorStatus'] = errorStatus + cbCtx['errorIndex'] = errorIndex + cbCtx['varBinds'] = varBinds + +cbCtx = {} + cmdgen.SetCommandGenerator().sendReq( snmpEngine, 'myRouter', - (((1,3,6,1,2,1,1,1,0), rfc1902.OctetString('Grinch')),), cbFun + (((1,3,6,1,2,1,1,1,0), rfc1902.OctetString('Grinch')),), cbFun, cbCtx ) -try: - snmpEngine.transportDispatcher.runDispatcher() -except error.ApplicationReturn, applicationReturn: - if applicationReturn['errorIndication']: - print applicationReturn['errorIndication'] - elif applicationReturn['errorStatus']: - print '%s at %s' % ( - repr(applicationReturn['errorStatus']), - applicationReturn['varBinds'][int(applicationReturn['errorIndex'])-1] - ) - else: - for o, v in applicationReturn['varBinds']: - print '%s = %s' % (o, v) +snmpEngine.transportDispatcher.runDispatcher() +if cbCtx['errorIndication']: + print cbCtx['errorIndication'] +elif cbCtx['errorStatus']: + print '%s at %s' % ( + repr(cbCtx['errorStatus']), + cbCtx['varBinds'][int(cbCtx['errorIndex'])-1] + ) +else: + for o, v in cbCtx['varBinds']: + print '%s = %s' % (o, v) |