operations – Everything RPC

Base classes

class ncclient.operations.RPC(session[, async=False, timeout=None, raise_mode="none"])

Base class for all operations, directly corresponding to rpc requests. Handles making the request, and taking delivery of the reply.

DEPENDS
Subclasses can specify their dependencies on capabilities. List of URI’s or abbreviated names, e.g. ‘:writable-running’. These are verified at the time of instantiation. If the capability is not available, a MissingCapabilityError is raised.
REPLY_CLS
Subclasses can specify a different reply class, but it should be a subclass of RPCReply.
_assert(capability)
Subclasses can use this method to verify that a capability is available with the NETCONF server, before making a request that requires it. A MissingCapabilityError will be raised if the capability is not available.
_request(op)

Implementations of request() call this method to send the request and process the reply.

In synchronous mode, blocks until the reply is received and returns RPCReply. Depending on the raise_mode a rpc-error element in the reply may lead to an RPCError exception.

In asynchronous mode, returns immediately, returning self. The event attribute will be set when the reply has been received (see reply) or an error occured (see error).

Parameter:op – operation to be requested
Return type:RPCReply (sync) or RPC (async)
request(*args, **kwds)
Subclasses must implement this method. Typically only the request needs to be built as an Element and everything else can be handed off to _request().
event
Event that is set when reply has been received or when an error preventing delivery of the reply occurs.
error

Exception type if an error occured or None.

Note

This represents an error which prevented a reply from being received. An rpc-error does not fall in that category – see RPCReply for that.

reply
RPCReply element if reply has been received or None
raise_mode

Depending on this exception raising mode, an rpc-error in the reply may be raised as RPCError exceptions. Valid values:

  • "all" – any kind of rpc-error (error or warning)
  • "errors" – when the error-type element says it is an error
  • "none" – neither
is_async
Specifies whether this RPC will be / was requested asynchronously. By default RPC’s are synchronous.
timeout

Timeout in seconds for synchronous waiting defining how long the RPC request will block on a reply before raising TimeoutExpiredError. By default there is no timeout, represented by None.

Irrelevant for asynchronous usage.

class ncclient.operations.RPCReply(raw)

Represents an rpc-reply. Only concerns itself with whether the operation was successful.

Note

If the reply has not yet been parsed there is an implicit, one-time parsing overhead to accessing the attributes defined by this class and any subclasses.

xml
rpc-reply element as returned.
ok
Boolean value indicating if there were no errors.
error
Returns the first RPCError and None if there were no errors.
errors
list of RPCError objects. Will be empty if there were no rpc-error elements in reply.
exception ncclient.operations.RPCError(raw)

Bases: ncclient.operations.errors.OperationError

Represents an rpc-error. It is a type of OperationError and can be raised like any other exception.

type
string representing text of error-type element.
severity
string representing text of error-severity element.
tag
string representing text of error-tag element.
path
string or None; representing text of error-path element.
message
string or None; representing text of error-message element.
info
string (XML) or None; representing error-info element.

Operations

TODO

The operation classes are currently undocumented. See documentation of Manager for methods that utilize the operation classes. The parameters accepted by request() for these classes are the same.

Replies with data

class ncclient.operations.GetReply(raw)

Bases: ncclient.operations.rpc.RPCReply

Adds attributes for the data element to RPCReply. This pertains to the Get and GetConfig operations.

data
Same as data_ele
data_ele
data element as an Element
data_xml
data element as an XML string

Exceptions

exception ncclient.operations.OperationError
Bases: ncclient.NCClientError
exception ncclient.operations.MissingCapabilityError
Bases: ncclient.NCClientError
exception ncclient.operations.TimeoutExpiredError
Bases: ncclient.NCClientError

Table Of Contents

Previous topic

transport – Transport / Session layer

Next topic

Extending ncclient

This Page