summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2016-03-31 00:04:43 +0200
committerIlya Etingof <etingof@gmail.com>2016-03-31 00:04:43 +0200
commit002bb632e888e90577c87111f99674be153f79d0 (patch)
tree528dffe86368b663806bf095c1d89e7498ae7dfe /examples
parente4c4e376316835e9eff0ac4df15ec29db7a7808b (diff)
downloadpysnmp-git-002bb632e888e90577c87111f99674be153f79d0.tar.gz
pep8 fixes
Diffstat (limited to 'examples')
-rw-r--r--examples/hlapi/twisted/agent/ntforg/default-v1-trap.py13
-rw-r--r--examples/hlapi/twisted/agent/ntforg/multiple-notifications-at-once.py19
-rw-r--r--examples/hlapi/twisted/manager/cmdgen/custom-timeout-and-retries.py14
-rw-r--r--examples/hlapi/twisted/manager/cmdgen/getbulk-to-eom.py18
-rw-r--r--examples/hlapi/twisted/manager/cmdgen/multiple-concurrent-queries.py14
-rw-r--r--examples/hlapi/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py23
-rw-r--r--examples/hlapi/twisted/manager/cmdgen/pull-whole-mib.py18
-rw-r--r--examples/hlapi/twisted/manager/cmdgen/v1-get.py14
-rw-r--r--examples/smi/agent/custom-managed-object.py10
9 files changed, 75 insertions, 68 deletions
diff --git a/examples/hlapi/twisted/agent/ntforg/default-v1-trap.py b/examples/hlapi/twisted/agent/ntforg/default-v1-trap.py
index 49eddb9b..e8b05451 100644
--- a/examples/hlapi/twisted/agent/ntforg/default-v1-trap.py
+++ b/examples/hlapi/twisted/agent/ntforg/default-v1-trap.py
@@ -23,17 +23,19 @@ Functionally similar to:
from twisted.internet.task import react
from pysnmp.hlapi.twisted import *
+
def success((errorStatus, errorIndex, varBinds), hostname):
if errorStatus:
print('%s: %s at %s' % (
- hostname,
- errorStatus.prettyPrint(),
- errorIndex and varBinds[int(errorIndex)-1][0] or '?'
- )
+ hostname,
+ errorStatus.prettyPrint(),
+ errorIndex and varBinds[int(errorIndex) - 1][0] or '?'
)
+ )
else:
for varBind in varBinds:
- print(' = '.join([ x.prettyPrint() for x in varBind ]))
+ print(' = '.join([x.prettyPrint() for x in varBind]))
+
def failure(errorIndication, hostname):
print('%s failure: %s' % (hostname, errorIndication))
@@ -57,4 +59,5 @@ def run(reactor, hostname):
d.addCallback(success, hostname).addErrback(failure, hostname)
return d
+
react(run, ['demo.snmplabs.com'])
diff --git a/examples/hlapi/twisted/agent/ntforg/multiple-notifications-at-once.py b/examples/hlapi/twisted/agent/ntforg/multiple-notifications-at-once.py
index 14b41091..fc6fbf3c 100644
--- a/examples/hlapi/twisted/agent/ntforg/multiple-notifications-at-once.py
+++ b/examples/hlapi/twisted/agent/ntforg/multiple-notifications-at-once.py
@@ -26,17 +26,16 @@ from twisted.internet.defer import DeferredList
from twisted.internet.task import react
from pysnmp.hlapi.twisted import *
+
def success((errorStatus, errorIndex, varBinds), hostname):
if errorStatus:
- print('%s: %s at %s' % (
- hostname,
- errorStatus.prettyPrint(),
- errorIndex and varBinds[int(errorIndex)-1][0] or '?'
- )
- )
+ print('%s: %s at %s' % (hostname,
+ errorStatus.prettyPrint(),
+ errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
else:
for varBind in varBinds:
- print(' = '.join([ x.prettyPrint() for x in varBind ]))
+ print(' = '.join([x.prettyPrint() for x in varBind]))
+
def failure(errorIndication, hostname):
print('%s failure: %s' % (hostname, errorIndication))
@@ -60,13 +59,15 @@ def sendone(reactor, snmpEngine, hostname, notifyType):
d.addCallback(success, hostname).addErrback(failure, hostname)
return d
+
def sendall(reactor, destinations):
snmpEngine = SnmpEngine()
return DeferredList(
- [ sendone(reactor, snmpEngine, hostname, notifyType)
- for hostname, notifyType in destinations ]
+ [sendone(reactor, snmpEngine, hostname, notifyType)
+ for hostname, notifyType in destinations]
)
+
react(sendall, [[('demo.snmplabs.com', 'trap'),
('demo.snmplabs.com', 'inform')]])
diff --git a/examples/hlapi/twisted/manager/cmdgen/custom-timeout-and-retries.py b/examples/hlapi/twisted/manager/cmdgen/custom-timeout-and-retries.py
index 19dfadda..f0419fa7 100644
--- a/examples/hlapi/twisted/manager/cmdgen/custom-timeout-and-retries.py
+++ b/examples/hlapi/twisted/manager/cmdgen/custom-timeout-and-retries.py
@@ -18,17 +18,16 @@ Functionally similar to:
from twisted.internet.task import react
from pysnmp.hlapi.twisted import *
+
def success((errorStatus, errorIndex, varBinds), hostname):
if errorStatus:
- print('%s: %s at %s' % (
- hostname,
- errorStatus.prettyPrint(),
- errorIndex and varBinds[int(errorIndex)-1][0] or '?'
- )
- )
+ print('%s: %s at %s' % (hostname,
+ errorStatus.prettyPrint(),
+ errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
else:
for varBind in varBinds:
- print(' = '.join([ x.prettyPrint() for x in varBind ]))
+ print(' = '.join([x.prettyPrint() for x in varBind]))
+
def failure(errorIndication, hostname):
print('%s failure: %s' % (hostname, errorIndication))
@@ -48,4 +47,5 @@ def getSysDescr(reactor, hostname):
return d
+
react(getSysDescr, ['demo.snmplabs.com'])
diff --git a/examples/hlapi/twisted/manager/cmdgen/getbulk-to-eom.py b/examples/hlapi/twisted/manager/cmdgen/getbulk-to-eom.py
index 47ede70b..e2b3ebb7 100644
--- a/examples/hlapi/twisted/manager/cmdgen/getbulk-to-eom.py
+++ b/examples/hlapi/twisted/manager/cmdgen/getbulk-to-eom.py
@@ -13,32 +13,31 @@ Send a series of SNMP GETBULK requests using the following options:
Functionally similar to:
-| $ snmpbulkwalk -v3 -lnoAuthNoPriv -u usr-none-none -Cn0 -Cr50 \
-| demo.snmplabs.com SNMPv2-MIB::system
+| $ snmpbulkwalk -v3 -lnoAuthNoPriv -u usr-none-none -Cn0 -Cr50 demo.snmplabs.com SNMPv2-MIB::system
"""#
from twisted.internet.task import react
from pysnmp.hlapi.twisted import *
+
def success((errorStatus, errorIndex, varBindTable), reactor, snmpEngine):
if errorStatus:
- print('%s: %s at %s' % (
- hostname,
- errorStatus.prettyPrint(),
- errorIndex and varBindTable[0][int(errorIndex)-1][0] or '?'
- )
- )
+ print('%s: %s at %s' % (hostname,
+ errorStatus.prettyPrint(),
+ errorIndex and varBindTable[0][int(errorIndex) - 1][0] or '?'))
else:
for varBindRow in varBindTable:
for varBind in varBindRow:
- print(' = '.join([ x.prettyPrint() for x in varBind ]))
+ print(' = '.join([x.prettyPrint() for x in varBind]))
if not isEndOfMib(varBindTable[-1]):
return getbulk(reactor, snmpEngine, *varBindTable[-1])
+
def failure(errorIndication):
print(errorIndication)
+
def getbulk(reactor, snmpEngine, varBinds):
d = bulkCmd(snmpEngine,
UsmUserData('usr-none-none'),
@@ -49,4 +48,5 @@ def getbulk(reactor, snmpEngine, varBinds):
d.addCallback(success, reactor, snmpEngine).addErrback(failure)
return d
+
react(getbulk, [SnmpEngine(), ObjectType(ObjectIdentity('SNMPv2-MIB', 'system'))])
diff --git a/examples/hlapi/twisted/manager/cmdgen/multiple-concurrent-queries.py b/examples/hlapi/twisted/manager/cmdgen/multiple-concurrent-queries.py
index 86a616ba..042c8e33 100644
--- a/examples/hlapi/twisted/manager/cmdgen/multiple-concurrent-queries.py
+++ b/examples/hlapi/twisted/manager/cmdgen/multiple-concurrent-queries.py
@@ -21,17 +21,16 @@ from twisted.internet.defer import DeferredList
from twisted.internet.task import react
from pysnmp.hlapi.twisted import *
+
def success((errorStatus, errorIndex, varBinds), hostname):
if errorStatus:
- print('%s: %s at %s' % (
- hostname,
- errorStatus.prettyPrint(),
- errorIndex and varBinds[int(errorIndex)-1][0] or '?'
- )
- )
+ print('%s: %s at %s' % (hostname,
+ errorStatus.prettyPrint(),
+ errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
else:
for varBind in varBinds:
- print(' = '.join([ x.prettyPrint() for x in varBind ]))
+ print(' = '.join([x.prettyPrint() for x in varBind]))
+
def failure(errorIndication, hostname):
print('%s failure: %s' % (hostname, errorIndication))
@@ -55,4 +54,5 @@ def getSystem(reactor, hostname):
getScalar(ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysLocation', 0)))]
)
+
react(getSystem, ['demo.snmplabs.com'])
diff --git a/examples/hlapi/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py b/examples/hlapi/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py
index 30d710b5..179d205f 100644
--- a/examples/hlapi/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py
+++ b/examples/hlapi/twisted/manager/cmdgen/pull-mibs-from-multiple-agents-at-once.py
@@ -19,25 +19,25 @@ from twisted.internet.defer import DeferredList
from twisted.internet.task import react
from pysnmp.hlapi.twisted import *
+
def success((errorStatus, errorIndex, varBindTable), reactor, snmpEngine, hostname):
if errorStatus:
- print('%s: %s at %s' % (
- hostname,
- errorStatus.prettyPrint(),
- errorIndex and varBindTable[0][int(errorIndex)-1][0] or '?'
- )
- )
+ print('%s: %s at %s' % (hostname,
+ errorStatus.prettyPrint(),
+ errorIndex and varBindTable[0][int(errorIndex) - 1][0] or '?'))
else:
for varBindRow in varBindTable:
for varBind in varBindRow:
- print(' = '.join([ x.prettyPrint() for x in varBind ]))
+ print(' = '.join([x.prettyPrint() for x in varBind]))
if not isEndOfMib(varBindTable[-1]):
return getbulk(reactor, snmpEngine, hostname, *varBindTable[-1])
+
def failure(errorIndication):
print(errorIndication)
+
def getbulk(reactor, snmpEngine, hostname, varBinds):
d = bulkCmd(snmpEngine,
UsmUserData('usr-md5-none', 'authkey1'),
@@ -48,14 +48,15 @@ def getbulk(reactor, snmpEngine, hostname, varBinds):
d.addCallback(success, reactor, snmpEngine, hostname).addErrback(failure)
return d
+
def getall(reactor, hostnames):
snmpEngine = SnmpEngine()
return DeferredList(
- [ getbulk(reactor, snmpEngine, hostname,
- ObjectType(ObjectIdentity('SNMPv2-MIB', 'system')))
- for hostname in hostnames ]
+ [getbulk(reactor, snmpEngine, hostname,
+ ObjectType(ObjectIdentity('SNMPv2-MIB', 'system')))
+ for hostname in hostnames]
)
-react(getall, [(('demo.snmplabs.com', 161), ('demo.snmplabs.com', 1161))])
+react(getall, [(('demo.snmplabs.com', 161), ('demo.snmplabs.com', 1161))])
diff --git a/examples/hlapi/twisted/manager/cmdgen/pull-whole-mib.py b/examples/hlapi/twisted/manager/cmdgen/pull-whole-mib.py
index 6df1668d..e7c7c5fe 100644
--- a/examples/hlapi/twisted/manager/cmdgen/pull-whole-mib.py
+++ b/examples/hlapi/twisted/manager/cmdgen/pull-whole-mib.py
@@ -12,32 +12,31 @@ Send a series of SNMP GETNEXT requests using the following options:
Functionally similar to:
-| $ snmpwalk -v3 -lauthPriv -u usr-md5-none -A authkey1 -X privkey1 \
-| demo.snmplabs.com IF-MIB::
+| $ snmpwalk -v3 -lauthPriv -u usr-md5-none -A authkey1 -X privkey1 demo.snmplabs.com IF-MIB::
"""#
from twisted.internet.task import react
from pysnmp.hlapi.twisted import *
+
def success((errorStatus, errorIndex, varBindTable), reactor, snmpEngine):
if errorStatus:
- print('%s: %s at %s' % (
- hostname,
- errorStatus.prettyPrint(),
- errorIndex and varBindTable[0][int(errorIndex)-1][0] or '?'
- )
- )
+ print('%s: %s at %s' % (hostname,
+ errorStatus.prettyPrint(),
+ errorIndex and varBindTable[0][int(errorIndex) - 1][0] or '?'))
else:
for varBindRow in varBindTable:
for varBind in varBindRow:
- print(' = '.join([ x.prettyPrint() for x in varBind ]))
+ print(' = '.join([x.prettyPrint() for x in varBind]))
if not isEndOfMib(varBindTable[-1]):
return getnext(reactor, snmpEngine, *varBindTable[-1])
+
def failure(errorIndication):
print(errorIndication)
+
def getnext(reactor, snmpEngine, varBinds):
d = nextCmd(snmpEngine,
UsmUserData('usr-md5-none', 'authkey1'),
@@ -47,4 +46,5 @@ def getnext(reactor, snmpEngine, varBinds):
d.addCallback(success, reactor, snmpEngine).addErrback(failure)
return d
+
react(getnext, [SnmpEngine(), ObjectType(ObjectIdentity('SNMPv2-MIB', 'system'))])
diff --git a/examples/hlapi/twisted/manager/cmdgen/v1-get.py b/examples/hlapi/twisted/manager/cmdgen/v1-get.py
index 051c58a8..6cb2f17e 100644
--- a/examples/hlapi/twisted/manager/cmdgen/v1-get.py
+++ b/examples/hlapi/twisted/manager/cmdgen/v1-get.py
@@ -18,17 +18,16 @@ Functionally similar to:
from twisted.internet.task import react
from pysnmp.hlapi.twisted import *
+
def success((errorStatus, errorIndex, varBinds), hostname):
if errorStatus:
- print('%s: %s at %s' % (
- hostname,
- errorStatus.prettyPrint(),
- errorIndex and varBinds[int(errorIndex)-1][0] or '?'
- )
- )
+ print('%s: %s at %s' % (hostname,
+ errorStatus.prettyPrint(),
+ errorIndex and varBinds[int(errorIndex) - 1][0] or '?'))
else:
for varBind in varBinds:
- print(' = '.join([ x.prettyPrint() for x in varBind ]))
+ print(' = '.join([x.prettyPrint() for x in varBind]))
+
def failure(errorIndication, hostname):
print('%s failure: %s' % (hostname, errorIndication))
@@ -46,4 +45,5 @@ def getSysDescr(reactor, hostname):
return d
+
react(getSysDescr, ['demo.snmplabs.com'])
diff --git a/examples/smi/agent/custom-managed-object.py b/examples/smi/agent/custom-managed-object.py
index 56fd15c8..87dea364 100644
--- a/examples/smi/agent/custom-managed-object.py
+++ b/examples/smi/agent/custom-managed-object.py
@@ -12,27 +12,29 @@ mibBuilder = builder.MibBuilder()
# A base class for a custom Managed Object
MibScalarInstance, = mibBuilder.importSymbols(
'SNMPv2-SMI', 'MibScalarInstance'
- )
+)
# Managed object specification
sysLocation, = mibBuilder.importSymbols('SNMPv2-MIB', 'sysLocation')
+
# Custom Managed Object
class MySysLocationInstance(MibScalarInstance):
# noinspection PyUnusedLocal
def readGet(self, name, *args):
# Just return a custom value
return name, self.syntax.clone('The Leaky Cauldron')
-
+
+
sysLocationInstance = MySysLocationInstance(
sysLocation.name, (0,), sysLocation.syntax
- )
+)
# Register Managed Object with a MIB tree
mibBuilder.exportSymbols(
# '__' prefixed MIB modules take precedence on indexing
'__MY-LOCATION-MIB', sysLocationInstance=sysLocationInstance
- )
+)
if __name__ == '__main__':
#