Skip to content

Commit

Permalink
cleaned up sync API legacy.
Browse files Browse the repository at this point in the history
  • Loading branch information
lextm committed Jul 14, 2024
1 parent 37cc8ef commit 21ab5a8
Show file tree
Hide file tree
Showing 22 changed files with 85 additions and 170 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ PySNMP is designed in a layered fashion. Top-level and easiest to use API is kno
*hlapi*. Here's a quick example on how to SNMP GET:

```python
from pysnmp.hlapi import *
from pysnmp.hlapi.asyncio import *
from pysnmp.smi.rfc1902 import ObjectIdentity, ObjectType

with Slim(1) as slim:
errorIndication, errorStatus, errorIndex, varBinds = slim.get(
errorIndication, errorStatus, errorIndex, varBinds = await slim.get(
'public',
'demo.pysnmp.com',
161,
Expand All @@ -114,11 +114,11 @@ with Slim(1) as slim:
This is how to send SNMP TRAP:

```python
from pysnmp.hlapi import *
from pysnmp.hlapi.asyncio import *


snmpEngine = SnmpEngine()
errorIndication, errorStatus, errorIndex, varBinds = sendNotification(
errorIndication, errorStatus, errorIndex, varBinds = await sendNotification(
snmpEngine,
CommunityData('public', mpModel=0),
UdpTransportTarget(('demo.pysnmp.com', 162)),
Expand Down
76 changes: 38 additions & 38 deletions docs/source/docs/pysnmp-hlapi-tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ Creating SNMP Engine
--------------------

SNMP engine is a central, umbrella object in PySNMP. All PySNMP
operations involve :py:class:`~pysnmp.hlapi.SnmpEngine` class
operations involve :py:class:`~pysnmp.hlapi.asyncio.SnmpEngine` class
instance. PySNMP app can run multiple independent SNMP engines each
guided by its own *SnmpEngine* object.

.. code-block:: python
>>> from pysnmp.hlapi import *
>>> from pysnmp.hlapi.asyncio import *
>>>
>>> SnmpEngine()
SnmpEngine(snmpEngineID=OctetString(hexValue='80004fb80567'))
SnmpEngine(snmpEngineID=<SnmpEngineID value object, tagSet <TagSet object, tags 0:0:4>, subtypeSpec <ConstraintsIntersection object, consts <ValueSizeConstraint object, consts 0, 65535>, <ValueSizeConstraint object, consts 5, 32>>, encoding iso-8859-1, payload [0x80004fb8054d61...6c6f63611bb6c040]>)
SNMP engine has unique identifier that can be assigned automatically
or administratively. This identifier is used in SNMP protocol
Expand All @@ -33,7 +33,7 @@ operations.
.. warning::

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

Making SNMP Query
Expand All @@ -47,7 +47,7 @@ corresponding functions.

.. code-block:: python
>>> from pysnmp.hlapi import *
>>> from pysnmp.hlapi.asyncio import *
>>> [ x for x in dir() if 'Cmd' in x]
['bulkCmd', 'getCmd', 'nextCmd', 'setCmd']
>>> getCmd
Expand All @@ -68,7 +68,7 @@ object.

.. code-block:: python
>>> from pysnmp.hlapi import *
>>> from pysnmp.hlapi.asyncio import *
>>>
>>> CommunityData('public', mpModel=0) # SNMPv1
CommunityData('public')
Expand All @@ -82,7 +82,7 @@ to SNMP engine LCD.

.. code-block:: python
>>> from pysnmp.hlapi import *
>>> from pysnmp.hlapi.asyncio import *
>>>
>>> UsmUserData('testuser', authKey='myauthkey')
UsmUserData(userName='testuser', authKey=<AUTHKEY>)
Expand All @@ -97,9 +97,9 @@ insecure, it's still the most popular SNMP version in use.

.. code-block:: python
>>> from pysnmp.hlapi import *
>>> from pysnmp.hlapi.asyncio import *
>>>
>>> g = getCmd(SnmpEngine(), CommunityData('public'),
>>> g = await getCmd(SnmpEngine(), CommunityData('public'),
...
Setting Transport and Target
Expand All @@ -114,9 +114,9 @@ SNMP LCD in form of properly initialized
.. code-block:: python
>>> from pysnmp.hlapi import *
>>> from pysnmp.hlapi.asyncio import *
>>>
>>> g = getCmd(SnmpEngine(),
>>> g = await getCmd(SnmpEngine(),
... CommunityData('public'),
... UdpTransportTarget(('demo.pysnmp.com', 161)),
...
Expand All @@ -137,9 +137,9 @@ For this example we will use the 'empty' context (default).
.. code-block:: python
>>> from pysnmp.hlapi import *
>>> from pysnmp.hlapi.asyncio import *
>>>
>>> g = getCmd(SnmpEngine(),
>>> g = await getCmd(SnmpEngine(),
... CommunityData('public'),
... UdpTransportTarget(('demo.pysnmp.com', 161)),
... ContextData(),
Expand Down Expand Up @@ -187,7 +187,7 @@ behaving like an OID.
.. code-block:: python
>>> from pysnmp.hlapi import *
>>> from pysnmp.hlapi.asyncio import *
>>>
>>> x = ObjectIdentity('SNMPv2-MIB', 'system')
>>> # ... calling MIB lookup ...
Expand All @@ -209,7 +209,7 @@ type instances. As a Python object it looks like a tuple of
.. code-block:: python
>>> from pysnmp.hlapi import *
>>> from pysnmp.hlapi.asyncio import *
>>> x = ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0), 'Linux i386 box'))
>>> # ... calling MIB lookup ...
>>> x[0].prettyPrint()
Expand Down Expand Up @@ -237,8 +237,8 @@ in `RFC3418`_ ``SNMPv2-MIB`` module.
.. code-block:: python
>>> from pysnmp.hlapi import *
>>> g = getCmd(SnmpEngine(),
>>> from pysnmp.hlapi.asyncio import *
>>> g = await getCmd(SnmpEngine(),
... CommunityData('public'),
... UdpTransportTarget(('demo.pysnmp.com', 161)),
... ContextData(),
Expand Down Expand Up @@ -270,9 +270,9 @@ out, response is awaited, received and parsed.
.. code-block:: python
>>> from pysnmp.hlapi import *
>>> from pysnmp.hlapi.asyncio import *
>>>
>>> g = getCmd(SnmpEngine(),
>>> g = await getCmd(SnmpEngine(),
... CommunityData('public'),
... UdpTransportTarget(('demo.pysnmp.com', 161)),
... ContextData(),
Expand Down Expand Up @@ -366,9 +366,9 @@ Let's read TCP-MIB::tcpConnectionState object for a TCP connection:
.. code-block:: python
>>> from pysnmp.hlapi import *
>>> from pysnmp.hlapi.asyncio import *
>>>
>>> g = getCmd(SnmpEngine(),
>>> g = await getCmd(SnmpEngine(),
... CommunityData('public'),
... UdpTransportTarget(('demo.pysnmp.com', 161)),
... ContextData(),
Expand All @@ -389,8 +389,8 @@ function.
.. code-block:: python
>>> from pysnmp.hlapi import *
>>> g = nextCmd(SnmpEngine(),
>>> from pysnmp.hlapi.asyncio import *
>>> g = await nextCmd(SnmpEngine(),
... CommunityData('public'),
... UdpTransportTarget(('demo.pysnmp.com', 161)),
... ContextData(),
Expand All @@ -414,10 +414,10 @@ API as *getNext()* for convenience.
.. code-block:: python
>>> from pysnmp.hlapi import *
>>> from pysnmp.hlapi.asyncio import *
>>>
>>> N, R = 0, 25
>>> g = bulkCmd(SnmpEngine(),
>>> g = await bulkCmd(SnmpEngine(),
... CommunityData('public'),
... UdpTransportTarget(('demo.pysnmp.com', 161)),
... ContextData(),
Expand All @@ -436,9 +436,9 @@ of MIB objects.
.. code-block:: python
>>> from pysnmp.hlapi import *
>>> from pysnmp.hlapi.asyncio import *
>>>
>>> g = nextCmd(SnmpEngine(),
>>> g = await nextCmd(SnmpEngine(),
... CommunityData('public'),
... UdpTransportTarget(('demo.pysnmp.com', 161)),
... ContextData(),
Expand All @@ -453,9 +453,9 @@ values in exactly the same order as they were in request message.
.. code-block:: python
>>> from pysnmp.hlapi import *
>>> from pysnmp.hlapi.asyncio import *
>>>
>>> g = getCmd(SnmpEngine(),
>>> g = await getCmd(SnmpEngine(),
... CommunityData('public'),
... UdpTransportTarget(('demo.pysnmp.com', 161)),
... ContextData(),
Expand All @@ -476,9 +476,9 @@ function.
.. code-block:: python
>>> from pysnmp.hlapi import *
>>> from pysnmp.hlapi.asyncio import *
>>>
>>> g = setCmd(SnmpEngine(),
>>> g = await setCmd(SnmpEngine(),
... CommunityData('public'),
... UdpTransportTarget(('demo.pysnmp.com', 161)),
... ContextData(),
Expand Down Expand Up @@ -523,7 +523,7 @@ From behavior standpoint, *NotificationType* looks like a sequence of
.. code-block:: python
>>> from pysnmp.hlapi import *
>>> from pysnmp.hlapi.asyncio import *
>>>
>>> x = NotificationType(ObjectIdentity('IF-MIB', 'linkUp'))
>>> # ... calling MIB lookup ...
Expand All @@ -540,9 +540,9 @@ or acknowledgement is sent.
.. code-block:: python
>>> from pysnmp.hlapi import *
>>> from pysnmp.hlapi.asyncio import *
>>>
>>> g = sendNotification(SnmpEngine(),
>>> g = await sendNotification(SnmpEngine(),
... CommunityData('public'),
... UdpTransportTarget(('demo.pysnmp.com', 162)),
... ContextData(),
Expand All @@ -558,9 +558,9 @@ well as for agent-to-manager.
.. code-block:: python
>>> from pysnmp.hlapi import *
>>> from pysnmp.hlapi.asyncio import *
>>>
>>> g = sendNotification(SnmpEngine(),
>>> g = await sendNotification(SnmpEngine(),
... CommunityData('public'),
... UdpTransportTarget(('demo.pysnmp.com', 162)),
... ContextData(),
Expand All @@ -584,13 +584,13 @@ object OIDs to current values.
.. code-block:: python
>>> from pysnmp.hlapi import *
>>> from pysnmp.hlapi.asyncio import *
>>>
>>> mib = {ObjectIdentifier('1.3.6.1.2.1.2.2.1.1.123'): 123,
... ObjectIdentifier('1.3.6.1.2.1.2.2.1.7.123'): 'testing',
... ObjectIdentifier('1.3.6.1.2.1.2.2.1.8.123'): 'up'}
>>>
>>> g = sendNotification(SnmpEngine(),
>>> g = await sendNotification(SnmpEngine(),
... CommunityData('public'),
... UdpTransportTarget(('demo.pysnmp.com', 162)),
... ContextData(),
Expand Down
4 changes: 1 addition & 3 deletions examples/hlapi/asyncio/agent/ntforg/v3-inform.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
""" #

import asyncio
from pysnmp.hlapi import *
from pysnmp.hlapi.asyncio.ntforg import sendNotification
from pysnmp.hlapi.asyncio.transport import UdpTransportTarget
from pysnmp.hlapi.asyncio import *


async def run():
Expand Down
69 changes: 0 additions & 69 deletions pysnmp/hlapi/__init__.py

This file was deleted.

9 changes: 6 additions & 3 deletions pysnmp/hlapi/asyncio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
# This file is part of pysnmp software.
#
# Copyright (c) 2005-2020, Ilya Etingof <[email protected]>
# Copyright (c) 2022-2024, LeXtudio Inc. <[email protected]>
# License: https://www.pysnmp.com/pysnmp/license.html
#
from pysnmp.proto.rfc1902 import *
from pysnmp.proto.rfc1905 import NoSuchInstance, NoSuchObject, EndOfMibView
from pysnmp.smi.rfc1902 import *
from pysnmp.entity.engine import *
from pysnmp.hlapi.auth import *
from pysnmp.hlapi.context import *
from pysnmp.hlapi.asyncio.transport import *
from pysnmp.hlapi.asyncio.auth import *
from pysnmp.hlapi.asyncio.context import *
from pysnmp.hlapi.asyncio.cmdgen import *
from pysnmp.hlapi.asyncio.ntforg import *
from pysnmp.hlapi.asyncio.slim import *
from pysnmp.hlapi.asyncio.transport import *
Loading

0 comments on commit 21ab5a8

Please sign in to comment.