|
LINK="#0000bb" VLINK="#551a8b" ALINK="#ff0000">
Asynchronous I/O engine
The pysnmp.asynrole module defines the manager
and agent classes, representing SNMP manager and agent roles
in a SNMP system. These classes implement network client (manager) and server
(agent) built on top of Sam Rushing's
asyncore framework.
The most important feature of an asynchronous I/O engine is that it can
exchange data over many BSD sockets (not necessarily SNMP parties) without
blocking on a temporarily suspended I/O operation.
The pysnmp.asynrole code is a pure network transport
facility -- it deals with abstract data items and has nothing to know about
SNMP context. In order to build a complete SNMP entity, a SNMP message
processing code should be used along. See SNMP protocol modules
(v2c, v1) for that.
The pysnmp.asynrole module defines the only class:
- class manager(cb_fun[, cb_ctx[, dst[, iface]]])
-
Returns a new instance of the manager class, representing
asynchronous I/O client (optionally connected to a network server running at
dst address) to be used to talk to one or more servers over its
own, single BSD socket.
The dst argument, whenever given, must follow the
socket module notation -- ('hostname',
port) where hostname a string and port is an integer.
The default for dst is None what means no default destination,
so user would unconditionally have to specify destination to each
manager.send() method (see below).
Once a default dst is specified, specific destination
may not be given to the manager.send() method.
The iface parameter, if given, specifies the interface and
port on local machine to bind() to. This argument must also
follow the socket module notation. All further requests would
then be originated from the given interface/port.
The default for iface is ('0.0.0.0', 0)) stands for binding
to a primary interface at the local machine.
The cb_fun argument must be a reference to a callback
function to be invoked by asyncore on data arrival. This
function will be passed the following parameters:
cb_fun(cb_ctx, (src,
rsp), (exc_type, exc_value,
exc_traceback))
where:
- cb_ctx is a reference to the same Python object as passed
by user on asynrole.manager class instaniation
- (src, rsp) is a request tuple holding
source address (in socket module notation) and response data
rsp (string) respectively
- (exc_type, exc_value,
exc_traceback) parameters represent exception details,
whenever happened, as provided by the sys module.
The cb_fun() function will always be invoked by asyncore
following each manager.send() call to either return
server reply on successful data exchange, or exception details on error.
- class agent(cb_fun[, cb_ctx[,
ifaces]])
-
Returns a new instance of the agent class, representing
asynchronous I/O server optionally bound to specific network interfaces/ports
ifaces at the local machine. One instance of the
agent class would talk to many clients over a single BSD socket.
The ifaces argument, whenever given, must be a list of
('ifacename', port) tuples
(socket module notation).
The default for the ifaces is to listen on the loopback
interface, port 161/UDP, so the default value is [('127.0.0.1', 161)].
The cb_fun argument must be a reference to a callback
function to be invoked by asyncore on data arrival. This
function will be passed the following parameters:
cb_fun(cb_ctx, (src,
req), (exc_type, exc_value,
exc_traceback))
where:
- cb_ctx is a reference to the same Python object as passed
by user on asynrole.agent class instaniation
- (src, req) is a request tuple holding
source address (in socket module notation) and request data
req (string) respectively
- (exc_type, exc_value,
exc_traceback) parameters represent exception details,
whenever happened, as provided by the sys module.
The cb_fun() function will be invoked by asyncore
on each data arrival as well as on error.
- exception Error
-
Exception raised on any error in the pysnmp.asynrole module,
as well as in its base (pysnmp.role) and derivative modules.
This exception class is a subclass of the pysnmp.role class.
See documentation on the error.General base class for
usage details.
The following exceptions are derived from this class:
- exception BadArgument
-
Bad parameters given.
Subsections
ilya@glas.net
|