Skip to content

Commit

Permalink
Applied more PEP 8 renaming.
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Oct 12, 2024
1 parent d35ac07 commit 85d6c87
Show file tree
Hide file tree
Showing 154 changed files with 1,432 additions and 1,349 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[flake8]
import-order-style = smarkets
exclude = .git,__pycache__,docs/source/conf.py,old,build,dist,pysnmp/smi/mibs
ignore = D100, D401, E203, E722, E501, W503, F401, F403, RST210, RST213, RST304
ignore = D100, D401, E203, E722, E501, W503, F401, F403, N803, N806, RST210, RST213, RST304
2 changes: 1 addition & 1 deletion docs/source/docs/pysnmp-hlapi-tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ operations.
.. warning::

``SnmpEngine`` object allocates many resources under the hood, so make
sure to call its :py:meth:`~pysnmp.hlapi.v3arch.asyncio.SnmpEngine.closeDispatcher`
sure to call its :py:meth:`~pysnmp.hlapi.v3arch.asyncio.SnmpEngine.close_dispatcher`
method when you are done with it.

Making SNMP Query
Expand Down
26 changes: 13 additions & 13 deletions docs/source/faq/getting-peer-information.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
Getting peer address information
--------------------------------

Q. How do I find out peer transport address or security information within
Q. How do I find out peer transport address or security information within
my receiving app (CommandResponder or Notification Receiver)?

A. SNMP architecture forces you to distinguish communicating entities only
on the basis of their community names (SNMPv1/v2c) or
ContextEngineId/ContextName pair (SNMPv3).
In other words, if one SNMP Manager should anyhow differ from another,
then they should use distinct community names or SNMP contexts.
A. SNMP architecture forces you to distinguish communicating entities only
on the basis of their community names (SNMPv1/v2c) or
ContextEngineId/ContextName pair (SNMPv3).

In other words, if one SNMP Manager should anyhow differ from another,
then they should use distinct community names or SNMP contexts.
Transport information should never be used for the identification purposes,
as in some cases it proves to be unreliable (cases include NAT device or
as in some cases it proves to be unreliable (cases include NAT device or
a proxy in the middle, not to mention address spoofing).

As practice reveals, even perfect design does not always cope well with
the imperfect world. So we had to pinch a logic hole from the scope of an
SNMP app down to transport layer. Now with the
getTransportInfo(stateReference) method call you could get peer transport
As practice reveals, even perfect design does not always cope well with
the imperfect world. So we had to pinch a logic hole from the scope of an
SNMP app down to transport layer. Now with the
getTransportInfo(stateReference) method call you could get peer transport
information upon receiving its SNMP message.

.. code-block:: python
Expand All @@ -29,4 +29,4 @@ A. SNMP architecture forces you to distinguish communicating entities only
contextEngineId, contextName,
varBinds,
cbCtx):
transportDomain, transportAddress = snmpEngine.msgAndPduDsp.getTransportInfo(stateReference)
transportDomain, transportAddress = snmpEngine.message_dispatcher.getTransportInfo(stateReference)
52 changes: 25 additions & 27 deletions docs/source/faq/how-to-implement-agent-mib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ How to implement MIB at the Agent

Q. How to instantiate static MIB table at my SNMP Agent?

A. You need to create MibScalarInstance class instances and register
A. You need to create MibScalarInstance class instances and register
them with your Agent's SNMP engine (mibBuilder, more specifically).
Here's an example code for a IP-MIB table:

Expand All @@ -19,31 +19,29 @@ A. You need to create MibScalarInstance class instances and register
ipAddressIfIndex,
ipAddressType,
ipAddressPrefix,
ipAddressOrigin,
ipAddressStatus,
ipAddressCreated,
ipAddressLastChanged,
ipAddressRowStatus,
ipAddressStorageType ) = snmpEngine.msgAndPduDsp.mibInstrumController
.mibBuilder.importSymbols(
ipAddressOrigin,
ipAddressStatus,
ipAddressCreated,
ipAddressLastChanged,
ipAddressRowStatus,
ipAddressStorageType ) = snmpEngine.get_mib_builder().importSymbols(
'IP-MIB',
'ipAddressAddrType',
'ipAddressAddr',
'ipAddressIfIndex',
'ipAddressType',
'ipAddressAddr',
'ipAddressIfIndex',
'ipAddressType',
'ipAddressPrefix',
'ipAddressOrigin',
'ipAddressStatus',
'ipAddressCreated',
'ipAddressLastChanged',
'ipAddressRowStatus',
'ipAddressLastChanged',
'ipAddressRowStatus',
'ipAddressStorageType'
)
# Import MibScalarInstance
MibScalarInstance, = snmpEngine.msgAndPduDsp.mibInstrumController.
mibBuilder.importSymbols('SNMPv2-SMI', 'MibScalarInstance')
MibScalarInstance, = snmpEngine.get_mib_builder().importSymbols('SNMPv2-SMI', 'MibScalarInstance')
# Create table columns instances
Expand All @@ -52,19 +50,19 @@ A. You need to create MibScalarInstance class instances and register
ipAddressAddrType.syntax.clone(1)
)
_ipAddressAddr = MibScalarInstance(
ipAddressAddr.name, (1, 4, 1, 2, 3, 4),
ipAddressAddr.name, (1, 4, 1, 2, 3, 4),
ipAddressAddr.syntax.clone('1.2.3.4')
)
_ipAddressIfIndex = MibScalarInstance(
ipAddressIfIndex.name, (1, 4, 1, 2, 3, 4),
ipAddressIfIndex.name, (1, 4, 1, 2, 3, 4),
ipAddressIfIndex.syntax.clone(1)
)
_ipAddressType = MibScalarInstance(
ipAddressType.name, (1, 4, 1, 2, 3, 4),
ipAddressType.syntax.clone(1)
)
_ipAddressPrefix = MibScalarInstance(
ipAddressPrefix.name, (1, 4, 1, 2, 3, 4),
ipAddressPrefix.name, (1, 4, 1, 2, 3, 4),
ipAddressPrefix.syntax.clone((0,0))
)
_ipAddressOrigin = MibScalarInstance(
Expand All @@ -76,15 +74,15 @@ A. You need to create MibScalarInstance class instances and register
ipAddressStatus.syntax.clone(1)
)
_ipAddressCreated = MibScalarInstance(
ipAddressCreated.name, (1, 4, 1, 2, 3, 4),
ipAddressCreated.name, (1, 4, 1, 2, 3, 4),
ipAddressCreated.syntax.clone(800)
)
_ipAddressLastChanged = MibScalarInstance(
ipAddressLastChanged.name, (1, 4, 1, 2, 3, 4),
ipAddressLastChanged.name, (1, 4, 1, 2, 3, 4),
ipAddressLastChanged.syntax.clone(600)
)
_ipAddressRowStatus = MibScalarInstance(
ipAddressRowStatus.name, (1, 4, 1, 2, 3, 4),
ipAddressRowStatus.name, (1, 4, 1, 2, 3, 4),
ipAddressRowStatus.syntax.clone(1)
)
_ipAddressStorageType = MibScalarInstance(
Expand All @@ -93,7 +91,7 @@ A. You need to create MibScalarInstance class instances and register
)
# add anonymous column instances
snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder.exportSymbols(
snmpEngine.get_mib_builder().exportSymbols(
'_IP-MIB',
_ipAddressAddrType,
_ipAddressAddr,
Expand All @@ -110,11 +108,11 @@ A. You need to create MibScalarInstance class instances and register
# Command responder code would follow...
Keep in mind that the values of this table row will not change by
themselves. They basically hold a snapshot of a data set so your
application may have to update them somehow. For example, an app could
periodically lookup particular MibScalarInstance by OID at mibBuilder and
Keep in mind that the values of this table row will not change by
themselves. They basically hold a snapshot of a data set so your
application may have to update them somehow. For example, an app could
periodically lookup particular MibScalarInstance by OID at mibBuilder and
update its "syntax" attribute with a new value.

There are other ways for building MIB tables that represent dynamic
There are other ways for building MIB tables that represent dynamic
Managed Objects.
2 changes: 1 addition & 1 deletion docs/source/faq/oids-not-increasing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ A. The Agent you are talking to seems to be broken. The
for varBind in varBinds:
print(' = '.join([x.prettyPrint() for x in varBind])
snmpEngine.closeDispatcher()
snmpEngine.close_dispatcher()
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def run():
if errorIndication:
print(errorIndication)

snmpDispatcher.transportDispatcher.closeDispatcher()
snmpDispatcher.transportDispatcher.close_dispatcher()


asyncio.run(run())
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async def run(varBinds):
if isEndOfMib(varBinds):
break

snmpDispatcher.transportDispatcher.closeDispatcher()
snmpDispatcher.transportDispatcher.close_dispatcher()


asyncio.run(run([ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr"))]))
2 changes: 1 addition & 1 deletion examples/hlapi/v1arch/asyncio/manager/cmdgen/v1-get.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def run():
for varBind in varBinds:
print(" = ".join([x.prettyPrint() for x in varBind]))

snmpDispatcher.transportDispatcher.closeDispatcher()
snmpDispatcher.transportDispatcher.close_dispatcher()


asyncio.run(run())
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def run():
if errorIndication:
print(errorIndication)

snmpEngine.closeDispatcher()
snmpEngine.close_dispatcher()


asyncio.run(run())
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def run():
for name, val in varBindTable:
print(f"{name.prettyPrint()} = {val.prettyPrint()}")

snmpEngine.transportDispatcher.runDispatcher()
snmpEngine.transport_dispatcher.run_dispatcher()


asyncio.run(run())
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def run():
),
)

snmpEngine.transportDispatcher.runDispatcher()
snmpEngine.transport_dispatcher.run_dispatcher()


asyncio.run(run())
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,22 @@ async def run():
transportDispatcher = AsyncioDispatcher()

# Setup a custom data routing function to select snmpEngine by transportDomain
transportDispatcher.registerRoutingCbFun(lambda td, ta, d: ta[1] % 3 and "A" or "B")
transportDispatcher.register_routing_callback(
lambda td, ta, d: ta[1] % 3 and "A" or "B"
)

snmpEngineA = SnmpEngine()
snmpEngineA.registerTransportDispatcher(transportDispatcher, "A")
snmpEngineA.register_transport_dispatcher(transportDispatcher, "A")

snmpEngineB = SnmpEngine()
snmpEngineB.registerTransportDispatcher(transportDispatcher, "B")
snmpEngineB.register_transport_dispatcher(transportDispatcher, "B")

for authData, transportTarget, contextData in TARGETS:
# Pick one of the two SNMP engines
snmpEngine = (
transportTarget.getTransportInfo()[1][1] % 3 and snmpEngineA or snmpEngineB
transportTarget.get_transport_info()[1][1] % 3
and snmpEngineA
or snmpEngineB
)

errorIndication, errorStatus, errorIndex, varBinds = await sendNotification(
Expand Down Expand Up @@ -104,7 +108,7 @@ async def run():
for name, val in varBinds:
print(f"{name.prettyPrint()} = {val.prettyPrint()}")

transportDispatcher.runDispatcher()
transportDispatcher.run_dispatcher()


asyncio.run(run())
4 changes: 2 additions & 2 deletions examples/hlapi/v3arch/asyncio/agent/ntforg/send-trap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
async def run():
snmpEngine = SnmpEngine()
# Example of how you might update sysUpTime
mibBuilder = snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder
mibBuilder = snmpEngine.get_mib_builder()
(sysUpTime,) = mibBuilder.importSymbols("__SNMPv2-MIB", "sysUpTime")
sysUpTime.syntax = TimeTicks(12345) # Set uptime to 12345

Expand All @@ -28,7 +28,7 @@ async def run():
if errorIndication:
print(errorIndication)

snmpEngine.closeDispatcher()
snmpEngine.close_dispatcher()


asyncio.run(run())
2 changes: 1 addition & 1 deletion examples/hlapi/v3arch/asyncio/agent/ntforg/v3-inform.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async def run():
for varBind in varBinds:
print(" = ".join([x.prettyPrint() for x in varBind]))

snmpEngine.closeDispatcher()
snmpEngine.close_dispatcher()


asyncio.run(run())
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ async def run():
for varBind in varBindTable:
print(" = ".join([x.prettyPrint() for x in varBind]))

snmpEngine.transportDispatcher.runDispatcher()
snmpEngine.transport_dispatcher.run_dispatcher()


asyncio.run(run())
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def run():
for varBind in varBindTable:
print(" = ".join([x.prettyPrint() for x in varBind]))

snmpEngine.transportDispatcher.runDispatcher()
snmpEngine.transport_dispatcher.run_dispatcher()


asyncio.run(run())
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,25 @@ async def run():
transportDispatcher = AsyncioDispatcher()

# Setup a custom data routing function to select snmpEngine by transportDomain
transportDispatcher.registerRoutingCbFun(lambda td, ta, d: ta[1] % 3 and "A" or "B")
transportDispatcher.register_routing_callback(
lambda td, ta, d: ta[1] % 3 and "A" or "B"
)

snmpEngineA = SnmpEngine()
snmpEngineIDA = snmpEngineA.snmpEngineID
print("snmpEngineA ID: %s" % snmpEngineIDA.prettyPrint())
snmpEngineA.registerTransportDispatcher(transportDispatcher, "A")
snmpEngineA.register_transport_dispatcher(transportDispatcher, "A")

snmpEngineB = SnmpEngine()
snmpEngineIDB = snmpEngineB.snmpEngineID
print("snmpEngineB ID: %s" % snmpEngineIDB.prettyPrint())
snmpEngineB.registerTransportDispatcher(transportDispatcher, "B")
snmpEngineB.register_transport_dispatcher(transportDispatcher, "B")

for authData, transportTarget, varBinds in TARGETS:
snmpEngine = (
transportTarget.getTransportInfo()[1][1] % 3 and snmpEngineA or snmpEngineB
transportTarget.get_transport_info()[1][1] % 3
and snmpEngineA
or snmpEngineB
)

(errorIndication, errorStatus, errorIndex, varBindTable) = await getCmd(
Expand Down Expand Up @@ -117,7 +121,7 @@ async def run():
for varBind in varBindTable:
print(" = ".join([x.prettyPrint() for x in varBind]))

transportDispatcher.runDispatcher(5)
transportDispatcher.run_dispatcher(5)


asyncio.run(run())
2 changes: 1 addition & 1 deletion examples/hlapi/v3arch/asyncio/manager/cmdgen/v1-get.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async def run():
for varBind in varBinds:
print(" = ".join([x.prettyPrint() for x in varBind]))

snmpEngine.closeDispatcher()
snmpEngine.close_dispatcher()


asyncio.run(run())
2 changes: 1 addition & 1 deletion examples/smi/agent/custom-managed-object.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def readGet(self, varBind, **context):
varBinds = [((), None)]

while True:
varBinds = mibInstrum.readNextVars(*varBinds)
varBinds = mibInstrum.read_next_variables(*varBinds)
oid, val = varBinds[0]
if exval.endOfMib.isSameTypeWith(val):
break
Expand Down
Loading

0 comments on commit 85d6c87

Please sign in to comment.