diff --git a/README.md b/README.md index 919df21f..a698dd3f 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ snmpEngine = SnmpEngine() errorIndication, errorStatus, errorIndex, varBinds = await sendNotification( snmpEngine, CommunityData('public', mpModel=0), - UdpTransportTarget(('demo.pysnmp.com', 162)), + await UdpTransportTarget.create(('demo.pysnmp.com', 162)), ContextData(), "trap", NotificationType(ObjectIdentity("1.3.6.1.6.3.1.1.5.2")).addVarBinds( diff --git a/docs/source/docs/pysnmp-hlapi-tutorial.rst b/docs/source/docs/pysnmp-hlapi-tutorial.rst index 87d8db68..a3fb4a33 100644 --- a/docs/source/docs/pysnmp-hlapi-tutorial.rst +++ b/docs/source/docs/pysnmp-hlapi-tutorial.rst @@ -118,7 +118,7 @@ SNMP LCD in form of properly initialized >>> >>> g = await getCmd(SnmpEngine(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 161)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ... Addressing SNMP Context @@ -141,7 +141,7 @@ For this example we will use the 'empty' context (default). >>> >>> g = await getCmd(SnmpEngine(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 161)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ... ContextData(), ... @@ -240,7 +240,7 @@ in `RFC3418`_ ``SNMPv2-MIB`` module. >>> from pysnmp.hlapi.v3arch.asyncio import * >>> g = await getCmd(SnmpEngine(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 161)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ... ContextData(), ... ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0))) @@ -274,7 +274,7 @@ out, response is awaited, received and parsed. >>> >>> g = await getCmd(SnmpEngine(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 161)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ... ContextData(), ... ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysUpTime', 0))) >>> g @@ -370,7 +370,7 @@ Let's read TCP-MIB::tcpConnectionState object for a TCP connection: >>> >>> g = await getCmd(SnmpEngine(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 161)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ... ContextData(), ... ObjectType(ObjectIdentity('TCP-MIB', 'tcpConnectionState', ... 'ipv4', '195.218.254.105', 41511, @@ -392,7 +392,7 @@ function. >>> from pysnmp.hlapi.v3arch.asyncio import * >>> g = await nextCmd(SnmpEngine(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 161)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ... ContextData(), ... ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr'))) >>> g @@ -419,7 +419,7 @@ API as *getNext()* for convenience. >>> N, R = 0, 25 >>> g = await bulkCmd(SnmpEngine(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 161)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ... ContextData(), ... N, R, ... ObjectType(ObjectIdentity('1.3.6'))) @@ -440,7 +440,7 @@ of MIB objects. >>> >>> g = await nextCmd(SnmpEngine(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 161)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ... ContextData(), ... ObjectType(ObjectIdentity('IF-MIB', 'ifTable'))) >>> @@ -457,7 +457,7 @@ values in exactly the same order as they were in request message. >>> >>> g = await getCmd(SnmpEngine(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 161)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ... ContextData(), ... ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)), ... ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysUpTime', 0)) @@ -480,7 +480,7 @@ function. >>> >>> g = await setCmd(SnmpEngine(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 161)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ... ContextData(), ... ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0), 'Linux i386') ... ) @@ -544,7 +544,7 @@ or acknowledgement is sent. >>> >>> g = await sendNotification(SnmpEngine(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 162)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 162)), ... ContextData(), ... 'trap', ... NotificationType(ObjectIdentity('IF-MIB', 'linkUp'), instanceIndex=(123,)) @@ -562,7 +562,7 @@ well as for agent-to-manager. >>> >>> g = await sendNotification(SnmpEngine(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 162)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 162)), ... ContextData(), ... 'inform', ... NotificationType(ObjectIdentity('IF-MIB', 'linkUp'), instanceIndex=(123,)) @@ -592,7 +592,7 @@ object OIDs to current values. >>> >>> g = await sendNotification(SnmpEngine(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 162)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 162)), ... ContextData(), ... 'inform', ... NotificationType(ObjectIdentity('IF-MIB', 'linkUp'), instanceIndex=(123,), objects=mib) diff --git a/docs/source/faq/oids-not-increasing.rst b/docs/source/faq/oids-not-increasing.rst index 24f21533..56aec2a2 100644 --- a/docs/source/faq/oids-not-increasing.rst +++ b/docs/source/faq/oids-not-increasing.rst @@ -19,18 +19,18 @@ A. The Agent you are talking to seems to be broken. The If you have to work with a broken Agent and can terminate the GETNEXT/GETBULK command at some point, you can pass the - `ignoreNonIncreasingOid=True` keyword parameter to the `nextCmd()` or `bulkCmd()` + `ignoreNonIncreasingOid=True` keyword parameter to the `walkCmd()` or `bulkWalkCmd()` to disable OID verification at the Manager side. .. code-block:: python snmpEngine = SnmpEngine() - for (errorIndication, + async for (errorIndication, errorStatus, errorIndex, - varBinds) in nextCmd(snmpEngine, + varBinds) in walkCmd(snmpEngine, CommunityData('public'), - UdpTransportTarget(('demo.pysnmp.com', 161)), + await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ContextData(), ObjectType(ObjectIdentity('1.3.6')), ignoreNonIncreasingOid=True): diff --git a/docs/source/faq/snmp-data-constraints-verification-failure.rst b/docs/source/faq/snmp-data-constraints-verification-failure.rst index bfdeda88..6b2aad23 100644 --- a/docs/source/faq/snmp-data-constraints-verification-failure.rst +++ b/docs/source/faq/snmp-data-constraints-verification-failure.rst @@ -2,37 +2,37 @@ SNMP data constraints verification error ---------------------------------------- -Q. Will PySNMP Manager verify the values it sends to and receives from +Q. Will PySNMP Manager verify the values it sends to and receives from a distant Agent against local MIB constraints? A. Yes, it can do that. The Manager will verify the values you pass to SET request against a MIB if: - The values are not already PyASN1 objects but some basic Python types - (like integer or string). You tell PySNMP engine to load appropriate + The values are not already PyASN1 objects but some basic Python types + (like integer or string). You tell PySNMP engine to load appropriate MIB where it could lookup the constraints (via the use of MibVariable) So, the following code fragment makes PySNMP engine loading SNMPv2-MIB - and verifying that the 'new system name' value satisfies sysName + and verifying that the 'new system name' value satisfies sysName constraints (if any). .. code-block:: python - errorIndication, errorStatus, errorIndex, varBinds = cmdGen.setCmd( + errorIndication, errorStatus, errorIndex, varBinds = await cmdGen.setCmd( cmdgen.CommunityData('public'), - cmdgen.UdpTransportTarget(('localhost', 161)), + await cmdgen.UdpTransportTarget(('localhost', 161)), ( cmdgen.MibVariable('SNMPv2-MIB', 'sysName', 0), 'new system name' ) ) -To verify the response values, you should pass at least lookupValues flag -to CommandGenerator \*cmd() method you use. In the following example -PySNMP will make sure that Agent-supplied value for SNMPv2-MIB::sysName +To verify the response values, you should pass at least lookupValues flag +to CommandGenerator \*cmd() method you use. In the following example +PySNMP will make sure that Agent-supplied value for SNMPv2-MIB::sysName Managed Object satisfies MIB constraints (if any). .. code-block:: python - errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd( + errorIndication, errorStatus, errorIndex, varBinds = await cmdGen.getCmd( cmdgen.CommunityData('public'), - cmdgen.UdpTransportTarget(('localhost', 161)), + await cmdgen.UdpTransportTarget(('localhost', 161)), cmdgen.MibVariable('SNMPv2-MIB', 'sysName', 0), lookupValues=True ) diff --git a/examples/hlapi/v1arch/asyncio/agent/ntforg/default-v1-trap.py b/examples/hlapi/v1arch/asyncio/agent/ntforg/default-v1-trap.py index b40a09c0..c76dd303 100644 --- a/examples/hlapi/v1arch/asyncio/agent/ntforg/default-v1-trap.py +++ b/examples/hlapi/v1arch/asyncio/agent/ntforg/default-v1-trap.py @@ -30,7 +30,7 @@ async def run(): iterator = await sendNotification( snmpDispatcher, CommunityData("public", mpModel=0), - UdpTransportTarget(("demo.pysnmp.com", 162)), + await UdpTransportTarget.create(("demo.pysnmp.com", 162)), "trap", NotificationType(ObjectIdentity("1.3.6.1.6.3.1.1.5.2")) .loadMibs("SNMPv2-MIB") diff --git a/examples/hlapi/v1arch/asyncio/agent/ntforg/multiple-notifications-at-once.py b/examples/hlapi/v1arch/asyncio/agent/ntforg/multiple-notifications-at-once.py index 8ea12768..e11b8a55 100644 --- a/examples/hlapi/v1arch/asyncio/agent/ntforg/multiple-notifications-at-once.py +++ b/examples/hlapi/v1arch/asyncio/agent/ntforg/multiple-notifications-at-once.py @@ -25,7 +25,7 @@ async def sendone(snmpDispatcher, hostname, notifyType): iterator = await sendNotification( snmpDispatcher, CommunityData("public"), - UdpTransportTarget((hostname, 162)), + await UdpTransportTarget.create((hostname, 162)), notifyType, NotificationType(ObjectIdentity("1.3.6.1.6.3.1.1.5.2")) .loadMibs("SNMPv2-MIB") diff --git a/examples/hlapi/v1arch/asyncio/manager/cmdgen/getbulk-to-eom.py b/examples/hlapi/v1arch/asyncio/manager/cmdgen/getbulk-to-eom.py index cc7b1d8f..90eef8fa 100644 --- a/examples/hlapi/v1arch/asyncio/manager/cmdgen/getbulk-to-eom.py +++ b/examples/hlapi/v1arch/asyncio/manager/cmdgen/getbulk-to-eom.py @@ -28,7 +28,7 @@ async def run(varBinds): iterator = await bulkCmd( snmpDispatcher, CommunityData("public"), - UdpTransportTarget(("demo.pysnmp.com", 161)), + await UdpTransportTarget.create(("demo.pysnmp.com", 161)), 0, 50, *varBinds diff --git a/examples/hlapi/v1arch/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py b/examples/hlapi/v1arch/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py index 5b48d95a..6e9ce51c 100644 --- a/examples/hlapi/v1arch/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py +++ b/examples/hlapi/v1arch/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py @@ -25,7 +25,7 @@ async def getone(snmpDispatcher, hostname): iterator = await getCmd( snmpDispatcher, CommunityData("public"), - UdpTransportTarget(hostname), + await UdpTransportTarget.create(hostname), ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), ) diff --git a/examples/hlapi/v1arch/asyncio/manager/cmdgen/multiple-sequential-queries.py b/examples/hlapi/v1arch/asyncio/manager/cmdgen/multiple-sequential-queries.py index e728964d..951549b9 100644 --- a/examples/hlapi/v1arch/asyncio/manager/cmdgen/multiple-sequential-queries.py +++ b/examples/hlapi/v1arch/asyncio/manager/cmdgen/multiple-sequential-queries.py @@ -25,7 +25,7 @@ async def getone(snmpDispatcher, hostname): iterator = await getCmd( snmpDispatcher, CommunityData("public"), - UdpTransportTarget(hostname), + await UdpTransportTarget.create(hostname), ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), ) diff --git a/examples/hlapi/v1arch/asyncio/manager/cmdgen/v1-get.py b/examples/hlapi/v1arch/asyncio/manager/cmdgen/v1-get.py index 89bd7486..3b171599 100644 --- a/examples/hlapi/v1arch/asyncio/manager/cmdgen/v1-get.py +++ b/examples/hlapi/v1arch/asyncio/manager/cmdgen/v1-get.py @@ -25,7 +25,7 @@ async def run(): iterator = await getCmd( snmpDispatcher, CommunityData("public", mpModel=0), - UdpTransportTarget(("demo.pysnmp.com", 161)), + await UdpTransportTarget.create(("demo.pysnmp.com", 161)), ("1.3.6.1.2.1.1.1.0", None), ) diff --git a/examples/hlapi/v3arch/asyncio/agent/ntforg/default-v1-trap.py b/examples/hlapi/v3arch/asyncio/agent/ntforg/default-v1-trap.py index d1491c5d..b7b856de 100644 --- a/examples/hlapi/v3arch/asyncio/agent/ntforg/default-v1-trap.py +++ b/examples/hlapi/v3arch/asyncio/agent/ntforg/default-v1-trap.py @@ -29,7 +29,7 @@ async def run(): errorIndication, errorStatus, errorIndex, varBinds = await sendNotification( snmpEngine, CommunityData("public", mpModel=0), - UdpTransportTarget(("demo.pysnmp.com", 162)), + await UdpTransportTarget.create(("demo.pysnmp.com", 162)), ContextData(), "trap", NotificationType(ObjectIdentity("1.3.6.1.6.3.1.1.5.2")) diff --git a/examples/hlapi/v3arch/asyncio/agent/ntforg/multiple-notifications-at-once.py b/examples/hlapi/v3arch/asyncio/agent/ntforg/multiple-notifications-at-once.py index e3a7f249..082ba3c1 100644 --- a/examples/hlapi/v3arch/asyncio/agent/ntforg/multiple-notifications-at-once.py +++ b/examples/hlapi/v3arch/asyncio/agent/ntforg/multiple-notifications-at-once.py @@ -30,7 +30,7 @@ async def sendone(snmpEngine, hostname, notifyType): errorIndication, errorStatus, errorIndex, varBinds = await sendNotification( snmpEngine, CommunityData("public", tag=hostname), - UdpTransportTarget((hostname, 162), tagList=hostname), + await UdpTransportTarget.create((hostname, 162), tagList=hostname), ContextData(), notifyType, NotificationType(ObjectIdentity("1.3.6.1.6.3.1.1.5.2")) diff --git a/examples/hlapi/v3arch/asyncio/agent/ntforg/send-trap.py b/examples/hlapi/v3arch/asyncio/agent/ntforg/send-trap.py index cdb51c95..eea2234c 100644 --- a/examples/hlapi/v3arch/asyncio/agent/ntforg/send-trap.py +++ b/examples/hlapi/v3arch/asyncio/agent/ntforg/send-trap.py @@ -12,7 +12,7 @@ async def run(): errorIndication, errorStatus, errorIndex, varBinds = await sendNotification( snmpEngine, CommunityData("public", mpModel=0), - UdpTransportTarget(("demo.pysnmp.com", 162)), + await UdpTransportTarget.create(("demo.pysnmp.com", 162)), ContextData(), "trap", NotificationType( diff --git a/examples/hlapi/v3arch/asyncio/agent/ntforg/v3-inform.py b/examples/hlapi/v3arch/asyncio/agent/ntforg/v3-inform.py index bf39b71a..013c9ea6 100644 --- a/examples/hlapi/v3arch/asyncio/agent/ntforg/v3-inform.py +++ b/examples/hlapi/v3arch/asyncio/agent/ntforg/v3-inform.py @@ -21,7 +21,7 @@ async def run(): errorIndication, errorStatus, errorIndex, varBinds = await sendNotification( snmpEngine, UsmUserData("usr-md5-des", "authkey1", "privkey1"), - UdpTransportTarget(("demo.pysnmp.com", 162)), + await UdpTransportTarget.create(("demo.pysnmp.com", 162)), ContextData(), "inform", NotificationType(ObjectIdentity("1.3.6.1.6.3.1.1.5.2")) diff --git a/examples/hlapi/v3arch/asyncio/manager/cmdgen/custom-asn1-mib-search-path.py b/examples/hlapi/v3arch/asyncio/manager/cmdgen/custom-asn1-mib-search-path.py index 90bd43c6..78992017 100644 --- a/examples/hlapi/v3arch/asyncio/manager/cmdgen/custom-asn1-mib-search-path.py +++ b/examples/hlapi/v3arch/asyncio/manager/cmdgen/custom-asn1-mib-search-path.py @@ -24,7 +24,7 @@ async def run(): errorIndication, errorStatus, errorIndex, varBinds = await getCmd( snmpEngine, CommunityData("public"), - UdpTransportTarget(("demo.pysnmp.com", 161)), + await UdpTransportTarget.create(("demo.pysnmp.com", 161)), ContextData(), ObjectType( ObjectIdentity("IF-MIB", "ifInOctets", 1).addAsn1MibSource( diff --git a/examples/hlapi/v3arch/asyncio/manager/cmdgen/getbulk-to-eom.py b/examples/hlapi/v3arch/asyncio/manager/cmdgen/getbulk-to-eom.py index be8f9fd7..836ac7c2 100644 --- a/examples/hlapi/v3arch/asyncio/manager/cmdgen/getbulk-to-eom.py +++ b/examples/hlapi/v3arch/asyncio/manager/cmdgen/getbulk-to-eom.py @@ -27,7 +27,7 @@ async def run(varBinds): errorIndication, errorStatus, errorIndex, varBindTable = await bulkCmd( snmpEngine, UsmUserData("usr-none-none"), - UdpTransportTarget(("demo.pysnmp.com", 161)), + await UdpTransportTarget.create(("demo.pysnmp.com", 161)), ContextData(), 0, 50, diff --git a/examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py b/examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py index e7a5a935..76544c42 100644 --- a/examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py +++ b/examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-concurrent-queries-over-ipv4-and-ipv6.py @@ -25,7 +25,7 @@ async def getone(snmpEngine, hostname): errorIndication, errorStatus, errorIndex, varBinds = await getCmd( snmpEngine, CommunityData("public"), - UdpTransportTarget(hostname), + await UdpTransportTarget.create(hostname), ContextData(), ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), ) diff --git a/examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-sequential-queries.py b/examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-sequential-queries.py index 89a20caf..129066d2 100644 --- a/examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-sequential-queries.py +++ b/examples/hlapi/v3arch/asyncio/manager/cmdgen/multiple-sequential-queries.py @@ -25,7 +25,7 @@ async def getone(snmpEngine, hostname): errorIndication, errorStatus, errorIndex, varBinds = await getCmd( snmpEngine, CommunityData("public"), - UdpTransportTarget(hostname), + await UdpTransportTarget.create(hostname), ContextData(), ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), ) diff --git a/examples/hlapi/v3arch/asyncio/manager/cmdgen/usm-localized-keys.py b/examples/hlapi/v3arch/asyncio/manager/cmdgen/usm-localized-keys.py index e2bb87e6..0fc2e906 100644 --- a/examples/hlapi/v3arch/asyncio/manager/cmdgen/usm-localized-keys.py +++ b/examples/hlapi/v3arch/asyncio/manager/cmdgen/usm-localized-keys.py @@ -36,7 +36,7 @@ async def run_snmp_get(): privKeyType=USM_KEY_TYPE_LOCALIZED, securityEngineId=OctetString(hexValue="80004fb805636c6f75644dab22cc"), ), - UdpTransportTarget(("demo.pysnmp.com", 161)), + await UdpTransportTarget.create(("demo.pysnmp.com", 161)), ContextData(), ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), ) diff --git a/examples/hlapi/v3arch/asyncio/manager/cmdgen/usm-master-keys.py b/examples/hlapi/v3arch/asyncio/manager/cmdgen/usm-master-keys.py index 99b3382e..8d5ee456 100644 --- a/examples/hlapi/v3arch/asyncio/manager/cmdgen/usm-master-keys.py +++ b/examples/hlapi/v3arch/asyncio/manager/cmdgen/usm-master-keys.py @@ -33,7 +33,7 @@ async def run_snmp_get(): authKeyType=USM_KEY_TYPE_MASTER, privKeyType=USM_KEY_TYPE_MASTER, ), - UdpTransportTarget(("demo.pysnmp.com", 161)), + await UdpTransportTarget.create(("demo.pysnmp.com", 161)), ContextData(), ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), ) diff --git a/examples/hlapi/v3arch/asyncio/manager/cmdgen/usm-sha-aes128.py b/examples/hlapi/v3arch/asyncio/manager/cmdgen/usm-sha-aes128.py index 3276c44b..d4cdcea2 100644 --- a/examples/hlapi/v3arch/asyncio/manager/cmdgen/usm-sha-aes128.py +++ b/examples/hlapi/v3arch/asyncio/manager/cmdgen/usm-sha-aes128.py @@ -39,7 +39,7 @@ async def run(): authProtocol=USM_AUTH_HMAC96_SHA, privProtocol=USM_PRIV_CFB128_AES, ), - UdpTransportTarget(("demo.pysnmp.com", 161)), + await UdpTransportTarget.create(("demo.pysnmp.com", 161)), ContextData(), ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), ) diff --git a/pysnmp/hlapi/transport.py b/pysnmp/hlapi/transport.py index 840d1b10..38ea2700 100644 --- a/pysnmp/hlapi/transport.py +++ b/pysnmp/hlapi/transport.py @@ -26,18 +26,29 @@ class AbstractTransportTarget: def __init__( self, - transportAddr: Tuple, timeout: float = 1, retries: int = 5, tagList=null, ): - self.transportAddr = self._resolveAddr(transportAddr) self.timeout = timeout self.retries = retries self.tagList = tagList self.iface = None self.transport = None + if not hasattr(self, "transportAddr"): + raise Exception( + f"Please call .create() to construct {self.__class__.__name__} object" + ) + + @classmethod + async def create(cls, *args, **kwargs): + self = cls.__new__(cls) + transportAddr = args[0] + self.transportAddr = await self._resolveAddr(transportAddr) + self.__init__(*args[1:], **kwargs) + return self + def __repr__(self): return "{}({!r}, timeout={!r}, retries={!r}, tagList={!r})".format( self.__class__.__name__, @@ -81,5 +92,5 @@ def verifyDispatcherCompatibility(self, snmpEngine: SnmpEngine): ) ) - def _resolveAddr(self, transportAddr: Tuple) -> Tuple[str, int]: + async def _resolveAddr(self, transportAddr: Tuple) -> Tuple[str, int]: raise NotImplementedError() diff --git a/pysnmp/hlapi/v1arch/asyncio/cmdgen.py b/pysnmp/hlapi/v1arch/asyncio/cmdgen.py index fb98f9ca..e9d79778 100644 --- a/pysnmp/hlapi/v1arch/asyncio/cmdgen.py +++ b/pysnmp/hlapi/v1arch/asyncio/cmdgen.py @@ -90,7 +90,7 @@ class instances (if `lookupMib` is `True`) representing MIB variables ... errorIndication, errorStatus, errorIndex, varBinds = await getCmd( ... SnmpDispatcher(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 161)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ... ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)) ... ) ... print(errorIndication, errorStatus, errorIndex, varBinds) @@ -213,7 +213,7 @@ class instances (if `lookupMib` is `True`) representing MIB variables ... errorIndication, errorStatus, errorIndex, varBinds = await setCmd( ... SnmpDispatcher(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 161)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ... ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0), 'Linux i386') ... ) ... print(errorIndication, errorStatus, errorIndex, varBinds) @@ -339,7 +339,7 @@ async def nextCmd(snmpDispatcher, authData, transportTarget, *varBinds, **option ... errorIndication, errorStatus, errorIndex, varBinds = await nextCmd( ... SnmpDispatcher(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 161)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ... ContextData(), ... ObjectType(ObjectIdentity('SNMPv2-MIB', 'system')) ... ) @@ -499,7 +499,7 @@ async def bulkCmd( ... errorIndication, errorStatus, errorIndex, varBinds = await bulkCmd( ... SnmpDispatcher(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 161)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ... 0, 2, ... ObjectType(ObjectIdentity('SNMPv2-MIB', 'system')) ... ) diff --git a/pysnmp/hlapi/v1arch/asyncio/ntforg.py b/pysnmp/hlapi/v1arch/asyncio/ntforg.py index e59602af..0d97c66c 100644 --- a/pysnmp/hlapi/v1arch/asyncio/ntforg.py +++ b/pysnmp/hlapi/v1arch/asyncio/ntforg.py @@ -115,7 +115,7 @@ class instances (if `lookupMib` is `True`) representing MIB variables ... errorIndication, errorStatus, errorIndex, varBinds = await sendNotification( ... SnmpDispatcher(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 162)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 162)), ... 'trap', ... NotificationType(ObjectIdentity('IF-MIB', 'linkDown'))) ... print(errorIndication, errorStatus, errorIndex, varBinds) diff --git a/pysnmp/hlapi/v1arch/asyncio/transport.py b/pysnmp/hlapi/v1arch/asyncio/transport.py index 9a016ec5..85be65ec 100644 --- a/pysnmp/hlapi/v1arch/asyncio/transport.py +++ b/pysnmp/hlapi/v1arch/asyncio/transport.py @@ -4,11 +4,11 @@ # Copyright (c) 2005-2020, Ilya Etingof # License: https://www.pysnmp.com/pysnmp/license.html # +import asyncio import socket -import sys +from typing import Tuple -from pysnmp.carrier.asyncio.dgram import udp -from pysnmp.carrier.asyncio.dgram import udp6 +from pysnmp.carrier.asyncio.dgram import udp, udp6 from pysnmp.error import PySnmpError from pysnmp.hlapi.transport import AbstractTransportTarget @@ -47,22 +47,25 @@ class instance. Examples -------- >>> from pysnmp.hlapi.v1arch.asyncore import UdpTransportTarget - >>> UdpTransportTarget(('demo.pysnmp.com', 161)) + >>> await UdpTransportTarget.create(('demo.pysnmp.com', 161)) UdpTransportTarget(('195.218.195.228', 161), timeout=1, retries=5) >>> """ - TRANSPORT_DOMAIN = udp.domainName + TRANSPORT_DOMAIN: Tuple[int, ...] = udp.DOMAIN_NAME PROTO_TRANSPORT = udp.UdpAsyncioTransport - def _resolveAddr(self, transportAddr): + async def _resolveAddr(self, transportAddr: Tuple) -> Tuple[str, int]: try: - return socket.getaddrinfo( - transportAddr[0], - transportAddr[1], - socket.AF_INET, - socket.SOCK_DGRAM, - socket.IPPROTO_UDP, + loop = asyncio.get_event_loop() + return ( + await loop.getaddrinfo( + transportAddr[0], + transportAddr[1], + family=socket.AF_INET, + type=socket.SOCK_DGRAM, + proto=socket.IPPROTO_UDP, + ) )[0][4][:2] except socket.gaierror as exc: raise PySnmpError( @@ -105,30 +108,33 @@ class instance. Examples -------- >>> from pysnmp.hlapi.asyncio import Udp6TransportTarget - >>> Udp6TransportTarget(('google.com', 161)) + >>> await Udp6TransportTarget.create(('google.com', 161)) Udp6TransportTarget(('2a00:1450:4014:80a::100e', 161), timeout=1, retries=5, tagList='') - >>> Udp6TransportTarget(('FEDC:BA98:7654:3210:FEDC:BA98:7654:3210', 161)) + >>> await Udp6TransportTarget.create(('FEDC:BA98:7654:3210:FEDC:BA98:7654:3210', 161)) Udp6TransportTarget(('fedc:ba98:7654:3210:fedc:ba98:7654:3210', 161), timeout=1, retries=5, tagList='') - >>> Udp6TransportTarget(('1080:0:0:0:8:800:200C:417A', 161)) + >>> await Udp6TransportTarget.create(('1080:0:0:0:8:800:200C:417A', 161)) Udp6TransportTarget(('1080::8:800:200c:417a', 161), timeout=1, retries=5, tagList='') - >>> Udp6TransportTarget(('::0', 161)) + >>> await Udp6TransportTarget.create(('::0', 161)) Udp6TransportTarget(('::', 161), timeout=1, retries=5, tagList='') - >>> Udp6TransportTarget(('::', 161)) + >>> await Udp6TransportTarget.create(('::', 161)) Udp6TransportTarget(('::', 161), timeout=1, retries=5, tagList='') >>> """ - TRANSPORT_DOMAIN = udp6.domainName + TRANSPORT_DOMAIN: Tuple[int, ...] = udp6.DOMAIN_NAME PROTO_TRANSPORT = udp6.Udp6AsyncioTransport - def _resolveAddr(self, transportAddr): + async def _resolveAddr(self, transportAddr: Tuple) -> Tuple[str, int]: try: - return socket.getaddrinfo( - transportAddr[0], - transportAddr[1], - socket.AF_INET6, - socket.SOCK_DGRAM, - socket.IPPROTO_UDP, + loop = asyncio.get_event_loop() + return ( + await loop.getaddrinfo( + transportAddr[0], + transportAddr[1], + family=socket.AF_INET6, + type=socket.SOCK_DGRAM, + proto=socket.IPPROTO_UDP, + ) )[0][4][:2] except socket.gaierror as exc: raise PySnmpError( diff --git a/pysnmp/hlapi/v3arch/asyncio/cmdgen.py b/pysnmp/hlapi/v3arch/asyncio/cmdgen.py index a56daf8a..8069038a 100644 --- a/pysnmp/hlapi/v3arch/asyncio/cmdgen.py +++ b/pysnmp/hlapi/v3arch/asyncio/cmdgen.py @@ -143,7 +143,7 @@ async def getCmd( ... errorIndication, errorStatus, errorIndex, varBinds = await getCmd( ... SnmpEngine(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 161)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ... ContextData(), ... ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0)) ... ) @@ -264,7 +264,7 @@ async def setCmd( ... errorIndication, errorStatus, errorIndex, varBinds = await setCmd( ... SnmpEngine(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 161)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ... ContextData(), ... ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr', 0), 'Linux i386') ... ) @@ -393,7 +393,7 @@ async def nextCmd( ... errorIndication, errorStatus, errorIndex, varBinds = await nextCmd( ... SnmpEngine(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 161)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ... ContextData(), ... ObjectType(ObjectIdentity('SNMPv2-MIB', 'system')) ... ) @@ -561,7 +561,7 @@ async def bulkCmd( ... errorIndication, errorStatus, errorIndex, varBinds = await bulkCmd( ... SnmpEngine(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 161)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ... ContextData(), ... 0, 2, ... ObjectType(ObjectIdentity('SNMPv2-MIB', 'system')) @@ -721,7 +721,7 @@ async def walkCmd( >>> from pysnmp.hlapi.v3arch.asyncio import * >>> g = await walkCmd(SnmpEngine(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 161)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ... ContextData(), ... ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr'))) >>> next(g) @@ -918,7 +918,7 @@ async def bulkWalkCmd( >>> from pysnmp.hlapi.v3arch.asyncio import * >>> g = await bulkWalkCmd(SnmpEngine(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 161)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 161)), ... ContextData(), ... 0, 25, ... ObjectType(ObjectIdentity('SNMPv2-MIB', 'sysDescr'))) diff --git a/pysnmp/hlapi/v3arch/asyncio/ntforg.py b/pysnmp/hlapi/v3arch/asyncio/ntforg.py index 02921127..a78e02e8 100644 --- a/pysnmp/hlapi/v3arch/asyncio/ntforg.py +++ b/pysnmp/hlapi/v3arch/asyncio/ntforg.py @@ -116,7 +116,7 @@ async def sendNotification( ... errorIndication, errorStatus, errorIndex, varBinds = await sendNotification( ... SnmpEngine(), ... CommunityData('public'), - ... UdpTransportTarget(('demo.pysnmp.com', 162)), + ... await UdpTransportTarget.create(('demo.pysnmp.com', 162)), ... ContextData(), ... 'trap', ... NotificationType(ObjectIdentity('IF-MIB', 'linkDown'))) diff --git a/pysnmp/hlapi/v3arch/asyncio/slim.py b/pysnmp/hlapi/v3arch/asyncio/slim.py index 9df1c18e..9b55c0c5 100644 --- a/pysnmp/hlapi/v3arch/asyncio/slim.py +++ b/pysnmp/hlapi/v3arch/asyncio/slim.py @@ -142,9 +142,9 @@ async def get( return await getCmd( self.snmpEngine, CommunityData(communityName, mpModel=self.version - 1), - Udp6TransportTarget((address, port), timeout, retries) + await Udp6TransportTarget.create((address, port), timeout, retries) if ":" in address - else UdpTransportTarget((address, port), timeout, retries), + else await UdpTransportTarget.create((address, port), timeout, retries), ContextData(), *varBinds, ) @@ -233,9 +233,9 @@ async def next( return await nextCmd( self.snmpEngine, CommunityData(communityName, mpModel=self.version - 1), - Udp6TransportTarget((address, port), timeout, retries) + await Udp6TransportTarget.create((address, port), timeout, retries) if ":" in address - else UdpTransportTarget((address, port), timeout, retries), + else await UdpTransportTarget.create((address, port), timeout, retries), ContextData(), *varBinds, ) @@ -356,9 +356,9 @@ async def bulk( return await bulkCmd( self.snmpEngine, CommunityData(communityName, mpModel=version), - Udp6TransportTarget((address, port), timeout, retries) + await Udp6TransportTarget.create((address, port), timeout, retries) if ":" in address - else UdpTransportTarget((address, port), timeout, retries), + else await UdpTransportTarget.create((address, port), timeout, retries), ContextData(), nonRepeaters, maxRepetitions, @@ -442,9 +442,9 @@ async def set( return await setCmd( self.snmpEngine, CommunityData(communityName, mpModel=self.version - 1), - Udp6TransportTarget((address, port), timeout, retries) + await Udp6TransportTarget.create((address, port), timeout, retries) if ":" in address - else UdpTransportTarget((address, port), timeout, retries), + else await UdpTransportTarget.create((address, port), timeout, retries), ContextData(), *varBinds, ) diff --git a/pysnmp/hlapi/v3arch/asyncio/transport.py b/pysnmp/hlapi/v3arch/asyncio/transport.py index 9777d438..594001eb 100644 --- a/pysnmp/hlapi/v3arch/asyncio/transport.py +++ b/pysnmp/hlapi/v3arch/asyncio/transport.py @@ -4,8 +4,8 @@ # Copyright (c) 2005-2020, Ilya Etingof # License: https://www.pysnmp.com/pysnmp/license.html # +import asyncio import socket -import sys from typing import Tuple from pysnmp.carrier.asyncio.dgram import udp, udp6 @@ -44,7 +44,7 @@ class instance. Examples -------- >>> from pysnmp.hlapi.v3arch.asyncio import UdpTransportTarget - >>> UdpTransportTarget(('demo.pysnmp.com', 161)) + >>> await UdpTransportTarget.create(('demo.pysnmp.com', 161)) UdpTransportTarget(('195.218.195.228', 161), timeout=1, retries=5, tagList='') >>> """ @@ -52,19 +52,22 @@ class instance. TRANSPORT_DOMAIN: Tuple[int, ...] = udp.DOMAIN_NAME PROTO_TRANSPORT = udp.UdpAsyncioTransport - def _resolveAddr(self, transportAddr: Tuple) -> Tuple[str, int]: + async def _resolveAddr(self, transportAddr: Tuple) -> Tuple[str, int]: try: - return socket.getaddrinfo( - transportAddr[0], - transportAddr[1], - socket.AF_INET, - socket.SOCK_DGRAM, - socket.IPPROTO_UDP, + loop = asyncio.get_event_loop() + return ( + await loop.getaddrinfo( + transportAddr[0], + transportAddr[1], + family=socket.AF_INET, + type=socket.SOCK_DGRAM, + proto=socket.IPPROTO_UDP, + ) )[0][4][:2] - except socket.gaierror: + except socket.gaierror as exc: raise PySnmpError( "Bad IPv4/UDP transport address {}: {}".format( - "@".join([str(x) for x in transportAddr]), sys.exc_info()[1] + "@".join([str(x) for x in transportAddr]), exc ) ) @@ -102,15 +105,15 @@ class instance. Examples -------- >>> from pysnmp.hlapi.v3arch.asyncio import Udp6TransportTarget - >>> Udp6TransportTarget(('google.com', 161)) + >>> await Udp6TransportTarget.create(('google.com', 161)) Udp6TransportTarget(('2a00:1450:4014:80a::100e', 161), timeout=1, retries=5, tagList='') - >>> Udp6TransportTarget(('FEDC:BA98:7654:3210:FEDC:BA98:7654:3210', 161)) + >>> await Udp6TransportTarget.create(('FEDC:BA98:7654:3210:FEDC:BA98:7654:3210', 161)) Udp6TransportTarget(('fedc:ba98:7654:3210:fedc:ba98:7654:3210', 161), timeout=1, retries=5, tagList='') - >>> Udp6TransportTarget(('1080:0:0:0:8:800:200C:417A', 161)) + >>> await Udp6TransportTarget.create(('1080:0:0:0:8:800:200C:417A', 161)) Udp6TransportTarget(('1080::8:800:200c:417a', 161), timeout=1, retries=5, tagList='') - >>> Udp6TransportTarget(('::0', 161)) + >>> await Udp6TransportTarget.create(('::0', 161)) Udp6TransportTarget(('::', 161), timeout=1, retries=5, tagList='') - >>> Udp6TransportTarget(('::', 161)) + >>> await Udp6TransportTarget.create(('::', 161)) Udp6TransportTarget(('::', 161), timeout=1, retries=5, tagList='') >>> """ @@ -118,18 +121,21 @@ class instance. TRANSPORT_DOMAIN: Tuple[int, ...] = udp6.DOMAIN_NAME PROTO_TRANSPORT = udp6.Udp6AsyncioTransport - def _resolveAddr(self, transportAddr: tuple): + async def _resolveAddr(self, transportAddr: Tuple) -> Tuple[str, int]: try: - return socket.getaddrinfo( - transportAddr[0], - transportAddr[1], - socket.AF_INET6, - socket.SOCK_DGRAM, - socket.IPPROTO_UDP, + loop = asyncio.get_event_loop() + return ( + await loop.getaddrinfo( + transportAddr[0], + transportAddr[1], + family=socket.AF_INET6, + type=socket.SOCK_DGRAM, + proto=socket.IPPROTO_UDP, + ) )[0][4][:2] - except socket.gaierror: + except socket.gaierror as exc: raise PySnmpError( "Bad IPv6/UDP transport address {}: {}".format( - "@".join([str(x) for x in transportAddr]), sys.exc_info()[1] + "@".join([str(x) for x in transportAddr]), exc ) ) diff --git a/tests/hlapi/asyncio/agent/ntforg/test_default-v1-trap.py b/tests/hlapi/asyncio/agent/ntforg/test_default-v1-trap.py index a6d36123..4eeb0507 100644 --- a/tests/hlapi/asyncio/agent/ntforg/test_default-v1-trap.py +++ b/tests/hlapi/asyncio/agent/ntforg/test_default-v1-trap.py @@ -11,8 +11,8 @@ async def test_send_trap_enterprise_specific(): errorIndication, errorStatus, errorIndex, varBinds = await sendNotification( snmpEngine, CommunityData("public", mpModel=0), - # UdpTransportTarget(("localhost", MANAGER_PORT)), # TODO: Fix this - UdpTransportTarget(("demo.pysnmp.com", 162)), + # await UdpTransportTarget.create(("localhost", MANAGER_PORT)), # TODO: Fix this + await UdpTransportTarget.create(("demo.pysnmp.com", 162)), ContextData(), "trap", NotificationType( @@ -41,8 +41,8 @@ async def test_send_trap_generic(): errorIndication, errorStatus, errorIndex, varBinds = await sendNotification( snmpEngine, CommunityData("public", mpModel=0), - # UdpTransportTarget(("localhost", MANAGER_PORT)), # TODO: Fix this - UdpTransportTarget(("demo.pysnmp.com", 162)), + # await UdpTransportTarget.create(("localhost", MANAGER_PORT)), # TODO: Fix this + await UdpTransportTarget.create(("demo.pysnmp.com", 162)), ContextData(), "trap", NotificationType(ObjectIdentity("1.3.6.1.6.3.1.1.5.2")) diff --git a/tests/hlapi/asyncio/agent/ntforg/test_v3-inform.py b/tests/hlapi/asyncio/agent/ntforg/test_v3-inform.py index 5f91ed99..004e70d2 100644 --- a/tests/hlapi/asyncio/agent/ntforg/test_v3-inform.py +++ b/tests/hlapi/asyncio/agent/ntforg/test_v3-inform.py @@ -11,7 +11,7 @@ async def test_send_v3_inform(): errorIndication, errorStatus, errorIndex, varBinds = await sendNotification( snmpEngine, UsmUserData("usr-md5-des", "authkey1", "privkey1"), - UdpTransportTarget(("localhost", MANAGER_PORT)), + await UdpTransportTarget.create(("localhost", MANAGER_PORT)), ContextData(), "inform", NotificationType(ObjectIdentity("1.3.6.1.6.3.1.1.5.2")) diff --git a/tests/hlapi/asyncio/agent/ntforg/test_v3-trap.py b/tests/hlapi/asyncio/agent/ntforg/test_v3-trap.py index f18aa8eb..cfde81d8 100644 --- a/tests/hlapi/asyncio/agent/ntforg/test_v3-trap.py +++ b/tests/hlapi/asyncio/agent/ntforg/test_v3-trap.py @@ -10,7 +10,7 @@ async def test_send_v3_trap_notification(): errorIndication, errorStatus, errorIndex, varBinds = await sendNotification( snmpEngine, UsmUserData("usr-md5-des", "authkey1", "privkey1"), - UdpTransportTarget(("localhost", MANAGER_PORT)), + await UdpTransportTarget.create(("localhost", MANAGER_PORT)), ContextData(), "trap", NotificationType(ObjectIdentity("IF-MIB", "linkDown")), diff --git a/tests/hlapi/asyncio/manager/cmdgen/test_custom_asn1_mib_search_path.py b/tests/hlapi/asyncio/manager/cmdgen/test_custom_asn1_mib_search_path.py index f18f3536..4cffd8cc 100644 --- a/tests/hlapi/asyncio/manager/cmdgen/test_custom_asn1_mib_search_path.py +++ b/tests/hlapi/asyncio/manager/cmdgen/test_custom_asn1_mib_search_path.py @@ -10,7 +10,7 @@ async def test_custom_asn1_mib_search_path(): errorIndication, errorStatus, errorIndex, varBinds = await getCmd( snmpEngine, CommunityData("public"), - UdpTransportTarget(("localhost", AGENT_PORT)), + await UdpTransportTarget.create(("localhost", AGENT_PORT)), ContextData(), ObjectType( ObjectIdentity("IF-MIB", "ifInOctets", 1).addAsn1MibSource( diff --git a/tests/hlapi/asyncio/manager/cmdgen/test_lcd_configurator.py b/tests/hlapi/asyncio/manager/cmdgen/test_lcd_configurator.py index 1f189e60..159946d3 100644 --- a/tests/hlapi/asyncio/manager/cmdgen/test_lcd_configurator.py +++ b/tests/hlapi/asyncio/manager/cmdgen/test_lcd_configurator.py @@ -1,17 +1,20 @@ from unittest import mock +import pytest + from pysnmp.hlapi.v3arch.asyncio import * from pysnmp.hlapi.v3arch.asyncio.lcd import CommandGeneratorLcdConfigurator @mock.patch("pysnmp.entity.config.addV3User") @mock.patch("pysnmp.entity.config.delV3User") -def test_usm_auth_cache_cleared(delV3User, addV3User): +@pytest.mark.asyncio +async def test_usm_auth_cache_cleared(delV3User, addV3User): """ Ensure auth cache is cleared when auth data is changed. """ snmpEngine = SnmpEngine() - transportTarget = UdpTransportTarget(("198.51.100.1", 161)) + transportTarget = await UdpTransportTarget.create(("198.51.100.1", 161)) authDataValues = { "userName": "username", diff --git a/tests/hlapi/asyncio/manager/cmdgen/test_send_trap.py b/tests/hlapi/asyncio/manager/cmdgen/test_send_trap.py index 29564be6..318a5083 100644 --- a/tests/hlapi/asyncio/manager/cmdgen/test_send_trap.py +++ b/tests/hlapi/asyncio/manager/cmdgen/test_send_trap.py @@ -12,7 +12,7 @@ async def test_send_trap(): errorIndication, errorStatus, errorIndex, varBinds = await sendNotification( snmpEngine, CommunityData("public", mpModel=0), - UdpTransportTarget(("demo.pysnmp.com", 162)), + await UdpTransportTarget.create(("demo.pysnmp.com", 162)), ContextData(), "trap", NotificationType( diff --git a/tests/hlapi/asyncio/manager/cmdgen/test_usm_none_none.py b/tests/hlapi/asyncio/manager/cmdgen/test_usm_none_none.py index 5537f6d4..9334d4ae 100644 --- a/tests/hlapi/asyncio/manager/cmdgen/test_usm_none_none.py +++ b/tests/hlapi/asyncio/manager/cmdgen/test_usm_none_none.py @@ -12,7 +12,7 @@ async def test_usm_no_auth_no_priv(): errorIndication, errorStatus, errorIndex, varBinds = await getCmd( snmpEngine, authData, - UdpTransportTarget(("localhost", AGENT_PORT), retries=0), + await UdpTransportTarget.create(("localhost", AGENT_PORT), retries=0), ContextData(), ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), ) @@ -33,7 +33,7 @@ async def test_usm_no_auth_no_priv_wrong_user(): errorIndication, errorStatus, errorIndex, varBinds = await getCmd( snmpEngine, authData, - UdpTransportTarget(("localhost", AGENT_PORT), retries=0), + await UdpTransportTarget.create(("localhost", AGENT_PORT), retries=0), ContextData(), ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), ) diff --git a/tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_aes128.py b/tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_aes128.py index 4af93e07..fda6399f 100644 --- a/tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_aes128.py +++ b/tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_aes128.py @@ -18,7 +18,7 @@ async def test_usm_sha_aes128(): errorIndication, errorStatus, errorIndex, varBinds = await getCmd( snmpEngine, authData, - UdpTransportTarget(("localhost", AGENT_PORT), retries=0), + await UdpTransportTarget.create(("localhost", AGENT_PORT), retries=0), ContextData(), ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), ) @@ -46,7 +46,7 @@ async def test_usm_sha_aes128_wrong_auth(): errorIndication, errorStatus, errorIndex, varBinds = await getCmd( snmpEngine, authData, - UdpTransportTarget(("localhost", AGENT_PORT), retries=0), + await UdpTransportTarget.create(("localhost", AGENT_PORT), retries=0), ContextData(), ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), ) @@ -71,7 +71,7 @@ async def test_usm_sha_aes128_wrong_priv(): errorIndication, errorStatus, errorIndex, varBinds = await getCmd( snmpEngine, authData, - UdpTransportTarget(("localhost", AGENT_PORT), retries=0), + await UdpTransportTarget.create(("localhost", AGENT_PORT), retries=0), ContextData(), ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), ) @@ -99,7 +99,7 @@ async def test_usm_sha_aes128_wrong_user(): errorIndication, errorStatus, errorIndex, varBinds = await getCmd( snmpEngine, authData, - UdpTransportTarget(("localhost", AGENT_PORT), retries=0), + await UdpTransportTarget.create(("localhost", AGENT_PORT), retries=0), ContextData(), ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), ) diff --git a/tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_none.py b/tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_none.py index f9811b90..ed822fc6 100644 --- a/tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_none.py +++ b/tests/hlapi/asyncio/manager/cmdgen/test_usm_sha_none.py @@ -16,7 +16,7 @@ async def test_usm_sha_none(): errorIndication, errorStatus, errorIndex, varBinds = await getCmd( snmpEngine, authData, - UdpTransportTarget(("localhost", AGENT_PORT), retries=0), + await UdpTransportTarget.create(("localhost", AGENT_PORT), retries=0), ContextData(), ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), ) @@ -42,7 +42,7 @@ async def test_usm_sha_none_wrong_auth(): errorIndication, errorStatus, errorIndex, varBinds = await getCmd( snmpEngine, authData, - UdpTransportTarget(("localhost", AGENT_PORT), retries=0), + await UdpTransportTarget.create(("localhost", AGENT_PORT), retries=0), ContextData(), ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), ) @@ -65,7 +65,7 @@ async def test_usm_sha_none_wrong_user(): errorIndication, errorStatus, errorIndex, varBinds = await getCmd( snmpEngine, authData, - UdpTransportTarget(("localhost", AGENT_PORT), retries=0), + await UdpTransportTarget.create(("localhost", AGENT_PORT), retries=0), ContextData(), ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), ) diff --git a/tests/hlapi/asyncio/manager/cmdgen/test_v1_get.py b/tests/hlapi/asyncio/manager/cmdgen/test_v1_get.py index 5a145a03..c99287bb 100644 --- a/tests/hlapi/asyncio/manager/cmdgen/test_v1_get.py +++ b/tests/hlapi/asyncio/manager/cmdgen/test_v1_get.py @@ -61,7 +61,7 @@ async def test_v1_get_raw(): errorIndication, errorStatus, errorIndex, varBinds = await getCmd( snmpEngine, CommunityData("public", mpModel=0), - UdpTransportTarget(("localhost", AGENT_PORT)), + await UdpTransportTarget.create(("localhost", AGENT_PORT)), ContextData(), ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), ) @@ -83,7 +83,7 @@ async def test_v1_get_ipv6(): errorIndication, errorStatus, errorIndex, varBinds = await getCmd( snmpEngine, CommunityData("public", mpModel=0), - Udp6TransportTarget(("localhost", AGENT_PORT)), + await Udp6TransportTarget.create(("localhost", AGENT_PORT)), ContextData(), ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), ) @@ -106,7 +106,7 @@ async def run_get(): errorIndication, errorStatus, errorIndex, varBinds = await getCmd( snmpEngine, CommunityData("community_string"), - UdpTransportTarget(("1.2.3.4", 161), timeout=1, retries=0), + await UdpTransportTarget.create(("1.2.3.4", 161), timeout=1, retries=0), ContextData(), ObjectType(ObjectIdentity("1.3.6.1.4.1.60069.9.1.0")), ) @@ -134,7 +134,9 @@ async def run_get(): errorIndication, errorStatus, errorIndex, varBinds = await getCmd( snmpEngine, CommunityData("public", mpModel=0), - UdpTransportTarget(("localhost", AGENT_PORT), timeout=1, retries=0), + await UdpTransportTarget.create( + ("localhost", AGENT_PORT), timeout=1, retries=0 + ), ContextData(), ObjectType(ObjectIdentity("1.3.6.1.4.1.60069.9.1.0")), ) @@ -160,7 +162,9 @@ async def test_v1_get_no_access_object(): errorIndication, errorStatus, errorIndex, varBinds = await getCmd( snmpEngine, CommunityData("public", mpModel=0), - UdpTransportTarget(("localhost", AGENT_PORT), timeout=1, retries=0), + await UdpTransportTarget.create( + ("localhost", AGENT_PORT), timeout=1, retries=0 + ), ContextData(), ObjectType(ObjectIdentity("1.3.6.1.4.1.60069.9.3")), ) diff --git a/tests/hlapi/asyncio/manager/cmdgen/test_v1_set.py b/tests/hlapi/asyncio/manager/cmdgen/test_v1_set.py index 53f42cd7..8cf7cb9f 100644 --- a/tests/hlapi/asyncio/manager/cmdgen/test_v1_set.py +++ b/tests/hlapi/asyncio/manager/cmdgen/test_v1_set.py @@ -39,7 +39,7 @@ async def test_v1_set_table_creation(): objects = walkCmd( snmpEngine, CommunityData("public", mpModel=0), - UdpTransportTarget(("localhost", AGENT_PORT)), + await UdpTransportTarget.create(("localhost", AGENT_PORT)), ContextData(), ObjectType(ObjectIdentity("1.3.6")), ) @@ -83,7 +83,7 @@ async def test_v1_set_table_creation(): objects = walkCmd( snmpEngine, CommunityData("public", mpModel=0), - UdpTransportTarget(("localhost", AGENT_PORT)), + await UdpTransportTarget.create(("localhost", AGENT_PORT)), ContextData(), ObjectType(ObjectIdentity("1.3.6")), ) diff --git a/tests/hlapi/asyncio/manager/cmdgen/test_v1_walk.py b/tests/hlapi/asyncio/manager/cmdgen/test_v1_walk.py index 74080b9f..7a34b299 100644 --- a/tests/hlapi/asyncio/manager/cmdgen/test_v1_walk.py +++ b/tests/hlapi/asyncio/manager/cmdgen/test_v1_walk.py @@ -10,7 +10,7 @@ async def test_v1_walk(): objects = walkCmd( snmpEngine, CommunityData("public", mpModel=0), - UdpTransportTarget(("localhost", AGENT_PORT)), + await UdpTransportTarget.create(("localhost", AGENT_PORT)), ContextData(), ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)), ) diff --git a/tests/hlapi/asyncio/manager/cmdgen/test_v2c_bulkwalk.py b/tests/hlapi/asyncio/manager/cmdgen/test_v2c_bulkwalk.py index 95ff6b54..2156e091 100644 --- a/tests/hlapi/asyncio/manager/cmdgen/test_v2c_bulkwalk.py +++ b/tests/hlapi/asyncio/manager/cmdgen/test_v2c_bulkwalk.py @@ -11,7 +11,7 @@ async def test_v2c_get_table_bulk(): objects = bulkWalkCmd( snmpEngine, CommunityData("public"), - UdpTransportTarget(("localhost", AGENT_PORT)), + await UdpTransportTarget.create(("localhost", AGENT_PORT)), ContextData(), 0, 4, @@ -47,7 +47,7 @@ async def test_v2c_get_table_bulk_0_4(): async for errorIndication, errorStatus, errorIndex, varBinds in bulkWalkCmd( snmpEngine, CommunityData("public"), - UdpTransportTarget(("localhost", AGENT_PORT)), + await UdpTransportTarget.create(("localhost", AGENT_PORT)), ContextData(), 0, 4, @@ -84,7 +84,7 @@ async def test_v2c_get_table_bulk_0_1(): async for errorIndication, errorStatus, errorIndex, varBinds in bulkWalkCmd( snmpEngine, CommunityData("public"), - UdpTransportTarget(("localhost", AGENT_PORT)), + await UdpTransportTarget.create(("localhost", AGENT_PORT)), ContextData(), 0, 1, diff --git a/tests/hlapi/asyncio/manager/cmdgen/test_v2c_get.py b/tests/hlapi/asyncio/manager/cmdgen/test_v2c_get.py index ce398b6e..b5ca6e7b 100644 --- a/tests/hlapi/asyncio/manager/cmdgen/test_v2c_get.py +++ b/tests/hlapi/asyncio/manager/cmdgen/test_v2c_get.py @@ -34,7 +34,9 @@ async def test_v2_get_no_access_object(): errorIndication, errorStatus, errorIndex, varBinds = await getCmd( snmpEngine, CommunityData("public"), - UdpTransportTarget(("localhost", AGENT_PORT), timeout=1, retries=0), + await UdpTransportTarget.create( + ("localhost", AGENT_PORT), timeout=1, retries=0 + ), ContextData(), ObjectType(ObjectIdentity("1.3.6.1.4.1.60069.9.3")), ) @@ -51,7 +53,9 @@ async def test_v2_get_legacy_object(): errorIndication, errorStatus, errorIndex, varBinds = await getCmd( snmpEngine, CommunityData("public"), - UdpTransportTarget(("localhost", AGENT_PORT), timeout=1, retries=0), + await UdpTransportTarget.create( + ("localhost", AGENT_PORT), timeout=1, retries=0 + ), ContextData(), ObjectType(ObjectIdentity("1.3.6.1.4.1.60069.9.4")), )