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 71f4fbc
Show file tree
Hide file tree
Showing 169 changed files with 1,611 additions and 1,486 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()
4 changes: 2 additions & 2 deletions examples/hlapi/v1arch/asyncio/agent/ntforg/default-v1-trap.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
async def run():
snmpDispatcher = SnmpDispatcher()

iterator = await sendNotification(
iterator = await send_notification(
snmpDispatcher,
CommunityData("public", mpModel=0),
await UdpTransportTarget.create(("demo.pysnmp.com", 162)),
Expand All @@ -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 @@ -22,7 +22,7 @@


async def sendone(snmpDispatcher, hostname, notifyType):
iterator = await sendNotification(
iterator = await send_notification(
snmpDispatcher,
CommunityData("public"),
await UdpTransportTarget.create((hostname, 162)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def run(varBinds):
snmpDispatcher = SnmpDispatcher()

while True:
iterator = await bulkCmd(
iterator = await bulk_cmd(
snmpDispatcher,
CommunityData("public"),
await UdpTransportTarget.create(("demo.pysnmp.com", 161)),
Expand All @@ -52,10 +52,10 @@ async def run(varBinds):
print(" = ".join([x.prettyPrint() for x in varBind]))

varBinds = varBindTable
if isEndOfMib(varBinds):
if is_end_of_mib(varBinds):
break

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


asyncio.run(run([ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr"))]))
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


async def getone(snmpDispatcher, hostname):
iterator = await getCmd(
iterator = await get_cmd(
snmpDispatcher,
CommunityData("public"),
await UdpTransportTarget.create(hostname),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


async def getone(snmpDispatcher, hostname):
iterator = await getCmd(
iterator = await get_cmd(
snmpDispatcher,
CommunityData("public"),
await UdpTransportTarget.create(hostname),
Expand Down
4 changes: 2 additions & 2 deletions examples/hlapi/v1arch/asyncio/manager/cmdgen/v1-get.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
async def run():
snmpDispatcher = SnmpDispatcher()

iterator = await getCmd(
iterator = await get_cmd(
snmpDispatcher,
CommunityData("public", mpModel=0),
await UdpTransportTarget.create(("demo.pysnmp.com", 161)),
Expand All @@ -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())
4 changes: 2 additions & 2 deletions examples/hlapi/v3arch/asyncio/agent/ntforg/default-v1-trap.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

async def run():
snmpEngine = SnmpEngine()
errorIndication, errorStatus, errorIndex, varBinds = await sendNotification(
errorIndication, errorStatus, errorIndex, varBinds = await send_notification(
snmpEngine,
CommunityData("public", mpModel=0),
await UdpTransportTarget.create(("demo.pysnmp.com", 162)),
Expand All @@ -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 @@ -48,7 +48,7 @@ async def run():
errorStatus,
errorIndex,
varBindTable,
) = await sendNotification(
) = await send_notification(
snmpEngine,
authData,
transportTarget,
Expand All @@ -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 @@ -43,7 +43,7 @@ async def run():
snmpEngine = SnmpEngine()

for authData, transportTarget, contextData in TARGETS:
await sendNotification(
await send_notification(
snmpEngine,
authData,
transportTarget,
Expand All @@ -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,21 +56,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()
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(
errorIndication, errorStatus, errorIndex, varBinds = await send_notification(
snmpEngine,
authData,
transportTarget,
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())
6 changes: 3 additions & 3 deletions examples/hlapi/v3arch/asyncio/agent/ntforg/send-trap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
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

errorIndication, errorStatus, errorIndex, varBinds = await sendNotification(
errorIndication, errorStatus, errorIndex, varBinds = await send_notification(
snmpEngine,
CommunityData("public", mpModel=0),
await UdpTransportTarget.create(("demo.pysnmp.com", 162)),
Expand All @@ -28,7 +28,7 @@ async def run():
if errorIndication:
print(errorIndication)

snmpEngine.closeDispatcher()
snmpEngine.close_dispatcher()


asyncio.run(run())
Loading

0 comments on commit 71f4fbc

Please sign in to comment.