summaryrefslogtreecommitdiff
path: root/pysnmp/hlapi/v1arch/asyncio/transport.py
diff options
context:
space:
mode:
authorIlya Etingof <etingof@gmail.com>2019-02-22 06:43:56 +0100
committerGitHub <noreply@github.com>2019-02-22 06:43:56 +0100
commit74fcc27b038da72c6aa9e2c08b4dac63175b8b5f (patch)
tree0c16c866ba88bf594b2ddea1f54fffe010b66ea8 /pysnmp/hlapi/v1arch/asyncio/transport.py
parent0cf85fdffc601477afb4a9c5568653154fb4eb32 (diff)
downloadpysnmp-git-74fcc27b038da72c6aa9e2c08b4dac63175b8b5f.tar.gz
Introduce asyncio binding to hlapi.v1arch (#244)
The hlapi.v1arch asyncio API is intended to be very similar to hlapi.v3arch.asyncio from its signature viewpoint, however it should be faster at the expense of no SNMPv3 support.
Diffstat (limited to 'pysnmp/hlapi/v1arch/asyncio/transport.py')
-rw-r--r--pysnmp/hlapi/v1arch/asyncio/transport.py126
1 files changed, 126 insertions, 0 deletions
diff --git a/pysnmp/hlapi/v1arch/asyncio/transport.py b/pysnmp/hlapi/v1arch/asyncio/transport.py
new file mode 100644
index 00000000..5d4895e5
--- /dev/null
+++ b/pysnmp/hlapi/v1arch/asyncio/transport.py
@@ -0,0 +1,126 @@
+#
+# This file is part of pysnmp software.
+#
+# Copyright (c) 2005-2019, Ilya Etingof <etingof@gmail.com>
+# License: http://snmplabs.com/pysnmp/license.html
+#
+import socket
+import sys
+
+from pysnmp.carrier.asyncio.dgram import udp
+from pysnmp.carrier.asyncio.dgram import udp6
+from pysnmp.error import PySnmpError
+from pysnmp.hlapi.transport import AbstractTransportTarget
+
+__all__ = ['Udp6TransportTarget', 'UdpTransportTarget']
+
+
+class UdpTransportTarget(AbstractTransportTarget):
+ """Represent UDP/IPv4 transport endpoint.
+
+ This object can be used for passing UDP/IPv4 configuration
+ information to the
+ :py:class:`~pysnmp.hlapi.v1arch.asyncio.AsyncCommandGenerator` and
+ :py:class:`~pysnmp.hlapi.v1arch.asyncio.AsyncNotificationOriginator`
+ objects scheduled on I/O by :py:class:`~pysnmp.hlapi.SnmpDispatcher`
+ class instance.
+
+ See :RFC:`1906#section-3` for more information on the UDP transport mapping.
+
+ Parameters
+ ----------
+ transportAddr: tuple
+ Indicates remote address in Python :py:mod:`socket` module format
+ which is a tuple of FQDN, port where FQDN is a string representing
+ either hostname or IPv4 address in quad-dotted form, port is an
+ integer.
+ timeout: :py:class:`int`
+ Response timeout in seconds.
+ retries: :py:class:`int`
+ Maximum number of request retries, 0 retries means just a single
+ request.
+ tagList: str
+ Arbitrary string that contains a list of tag values which are used
+ to select target addresses for a particular operation
+ (:RFC:`3413#section-4.1.4`).
+
+ Examples
+ --------
+ >>> from pysnmp.hlapi.v1arch.asyncore import UdpTransportTarget
+ >>> UdpTransportTarget(('demo.snmplabs.com', 161))
+ UdpTransportTarget(('195.218.195.228', 161), timeout=1, retries=5)
+ >>>
+ """
+ TRANSPORT_DOMAIN = udp.domainName
+ PROTO_TRANSPORT = udp.UdpAsyncioTransport
+
+ def _resolveAddr(self, transportAddr):
+ try:
+ return socket.getaddrinfo(transportAddr[0],
+ transportAddr[1],
+ socket.AF_INET,
+ socket.SOCK_DGRAM,
+ socket.IPPROTO_UDP)[0][4][:2]
+ except socket.gaierror as exc:
+ raise PySnmpError('Bad IPv4/UDP transport address %s: %s' % (
+ '@'.join([str(x) for x in transportAddr]), exc))
+
+
+class Udp6TransportTarget(AbstractTransportTarget):
+ """Represent UDP/IPv6 transport endpoint.
+
+ This object can be used for passing UDP/IPv6 configuration
+ information to the
+ :py:class:`~pysnmp.hlapi.v1arch.asyncio.AsyncCommandGenerator` and
+ :py:class:`~pysnmp.hlapi.v1arch.asyncio.AsyncNotificationOriginator`
+ objects scheduled on I/O by :py:class:`~pysnmp.hlapi.SnmpDispatcher`
+ class instance.
+
+ See :RFC:`1906#section-3`, :RFC:`2851#section-4` for more information
+ on the UDP and IPv6 transport mapping.
+
+ Parameters
+ ----------
+ transportAddr: tuple
+ Indicates remote address in Python :py:mod:`socket` module format
+ which is a tuple of FQDN, port where FQDN is a string representing
+ either hostname or IPv6 address in one of three conventional forms
+ (:RFC:`1924#section-3`), port is an integer.
+ timeout: int
+ Response timeout in seconds.
+ retries: int
+ Maximum number of request retries, 0 retries means just a single
+ request.
+ tagList: str
+ Arbitrary string that contains a list of tag values which are used
+ to select target addresses for a particular operation
+ (:RFC:`3413#section-4.1.4`).
+
+ Examples
+ --------
+ >>> from pysnmp.hlapi.asyncio import Udp6TransportTarget
+ >>> Udp6TransportTarget(('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))
+ 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))
+ Udp6TransportTarget(('1080::8:800:200c:417a', 161), timeout=1, retries=5, tagList='')
+ >>> Udp6TransportTarget(('::0', 161))
+ Udp6TransportTarget(('::', 161), timeout=1, retries=5, tagList='')
+ >>> Udp6TransportTarget(('::', 161))
+ Udp6TransportTarget(('::', 161), timeout=1, retries=5, tagList='')
+ >>>
+ """
+ TRANSPORT_DOMAIN = udp6.domainName
+ PROTO_TRANSPORT = udp6.Udp6AsyncioTransport
+
+ def _resolveAddr(self, transportAddr):
+ try:
+ return socket.getaddrinfo(transportAddr[0],
+ transportAddr[1],
+ socket.AF_INET6,
+ socket.SOCK_DGRAM,
+ socket.IPPROTO_UDP)[0][4][:2]
+ except socket.gaierror as exc:
+ raise PySnmpError('Bad IPv6/UDP transport address %s: %s' % (
+ '@'.join([str(x) for x in transportAddr]), exc))