summaryrefslogtreecommitdiff
path: root/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py')
-rw-r--r--examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py58
1 files changed, 29 insertions, 29 deletions
diff --git a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py
index 124a26fa..22d165df 100644
--- a/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py
+++ b/examples/hlapi/asyncore/sync/manager/cmdgen/custom-contextengineid.py
@@ -10,35 +10,35 @@
# * to an Agent at demo.snmplabs.com:161
# * setting SNMPv2-MIB::sysName.0 to new value (type taken from MIB)
#
-from pysnmp.entity.rfc3413.oneliner import cmdgen
+from pysnmp.entity.rfc3413.oneliner.cmdgen import *
from pysnmp.proto import rfc1902
-cmdGen = cmdgen.CommandGenerator()
-
-errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd(
- cmdgen.UsmUserData(
- 'usr-md5-des', 'authkey1', 'privkey1',
- securityEngineId=rfc1902.OctetString(
- hexValue='80004fb805636c6f75644dab22cc'
- )
- ),
- cmdgen.UdpTransportTarget(('demo.snmplabs.com', 161)),
- cmdgen.ObjectType(
- cmdgen.ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1),
- 'new system name'
- )
-)
-
-# Check for errors and print out results
-if errorIndication:
- print(errorIndication)
-else:
- if errorStatus:
- print('%s at %s' % (
- errorStatus.prettyPrint(),
- errorIndex and varBinds[int(errorIndex)-1][0] or '?'
- )
- )
+for errorIndication, \
+ errorStatus, errorIndex, \
+ varBinds in setCmd(SnmpEngine(),
+ UsmUserData(
+ 'usr-md5-des', 'authkey1', 'privkey1',
+ securityEngineId=rfc1902.OctetString(
+ hexValue='80004fb805636c6f75644dab22cc'
+ )
+ ),
+ UdpTransportTarget(('demo.snmplabs.com', 161)),
+ ContextData(),
+ ObjectType(
+ ObjectIdentity('SNMPv2-MIB', 'sysORDescr', 1),
+ 'new system name'
+ )):
+ # Check for errors and print out results
+ if errorIndication:
+ print(errorIndication)
else:
- for name, val in varBinds:
- print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
+ if errorStatus:
+ print('%s at %s' % (
+ errorStatus.prettyPrint(),
+ errorIndex and varBinds[int(errorIndex)-1][0] or '?'
+ )
+ )
+ else:
+ for varBind in varBinds:
+ print(' = '.join([ x.prettyPrint() for x in varBind ]))
+ break