operations – Everything RPC

class ncclient.operations.RaiseMode
NONE = 0

Don’t attempt to raise any type of rpc-error as RPCError.

ERRORS = 1

Raise only when the error-type indicates it is an honest-to-god error.

ALL = 2

Don’t look at the error-type, always raise.

Base classes

class ncclient.operations.RPC(session, async=False, timeout=30, raise_mode=0)

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

session is the Session instance

async specifies whether the request is to be made asynchronously, see is_async

timeout is the timeout for a synchronous request, see timeout

raise_mode specifies the exception raising mode, see raise_mode

DEPENDS = []

Subclasses can specify their dependencies on capabilities as a 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, MissingCapabilityError is raised.

REPLY_CLS

By default RPCReply. Subclasses can specify a RPCReply subclass.

alias 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).

op is the operation to be requested as an Element

request()

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 an RPCError exception. Valid values are the constants defined in RaiseMode.

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.

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 some of the attributes defined by this class.

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.

_parsing_hook(root)

No-op by default. Gets passed the root element for the 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 as such.

type

The contents of the error-type element.

severity

The contents of the error-severity element.

tag

The contents of the error-tag element.

path

The contents of the error-path element if present or None.

message

The contents of the error-message element if present or None.

info

XML string or None; representing the error-info element.

Operations

Retrieval

class ncclient.operations.Get(session, async=False, timeout=30, raise_mode=0)

Bases: ncclient.operations.rpc.RPC

The get RPC.

session is the Session instance

async specifies whether the request is to be made asynchronously, see is_async

timeout is the timeout for a synchronous request, see timeout

raise_mode specifies the exception raising mode, see raise_mode

REPLY_CLS = <class ncclient.operations.retrieve.GetReply at 0xad3f4dc>

See GetReply.

request(filter=None)

Retrieve running configuration and device state information.

filter specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)

Seealso :Filter parameters
class ncclient.operations.GetConfig(session, async=False, timeout=30, raise_mode=0)

Bases: ncclient.operations.rpc.RPC

The get-config RPC.

session is the Session instance

async specifies whether the request is to be made asynchronously, see is_async

timeout is the timeout for a synchronous request, see timeout

raise_mode specifies the exception raising mode, see raise_mode

REPLY_CLS = <class ncclient.operations.retrieve.GetReply at 0xad3f4dc>

See GetReply.

request(source, filter=None)

Retrieve all or part of a specified configuration.

source name of the configuration datastore being queried

filter specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)

Seealso :Filter parameters
class ncclient.operations.GetReply(raw)

Bases: ncclient.operations.rpc.RPCReply

Adds attributes for the data element to RPCReply.

data

Same as data_ele

data_ele

data element as an Element

data_xml

data element as an XML string

class ncclient.operations.Dispatch(session, async=False, timeout=30, raise_mode=0)

Bases: ncclient.operations.rpc.RPC

Generic retrieving wrapper

session is the Session instance

async specifies whether the request is to be made asynchronously, see is_async

timeout is the timeout for a synchronous request, see timeout

raise_mode specifies the exception raising mode, see raise_mode

REPLY_CLS = <class ncclient.operations.retrieve.GetReply at 0xad3f4dc>

See GetReply.

request(rpc_command, source=None, filter=None)

rpc_command specifies rpc command to be dispatched either in plain text or in xml element format (depending on command)

source name of the configuration datastore being queried

filter specifies the portion of the configuration to retrieve (by default entire configuration is retrieved)

Seealso :Filter parameters

Examples of usage:

dispatch('clear-arp-table')

or dispatch element like

xsd_fetch = new_ele('get-xnm-information')
sub_ele(xsd_fetch, 'type').text="xml-schema"
sub_ele(xsd_fetch, 'namespace').text="junos-configuration"
dispatch(xsd_fetch)

Editing

class ncclient.operations.EditConfig(session, async=False, timeout=30, raise_mode=0)

Bases: ncclient.operations.rpc.RPC

edit-config RPC

session is the Session instance

async specifies whether the request is to be made asynchronously, see is_async

timeout is the timeout for a synchronous request, see timeout

raise_mode specifies the exception raising mode, see raise_mode

request(target, config, default_operation=None, test_option=None, error_option=None)

Loads all or part of the specified config to the target configuration datastore.

target is the name of the configuration datastore being edited

config is the configuration, which must be rooted in the config element. It can be specified either as a string or an Element.

default_operation if specified must be one of { “merge”, “replace”, or “none” }

test_option if specified must be one of { “test_then_set”, “set” }

error_option if specified must be one of { “stop-on-error”, “continue-on-error”, “rollback-on-error” }

The “rollback-on-error” error_option depends on the :rollback-on-error capability.

class ncclient.operations.DeleteConfig(session, async=False, timeout=30, raise_mode=0)

Bases: ncclient.operations.rpc.RPC

delete-config RPC

session is the Session instance

async specifies whether the request is to be made asynchronously, see is_async

timeout is the timeout for a synchronous request, see timeout

raise_mode specifies the exception raising mode, see raise_mode

request(target)

Delete a configuration datastore.

target specifies the name or URL of configuration datastore to delete

Seealso :Source and target parameters
class ncclient.operations.CopyConfig(session, async=False, timeout=30, raise_mode=0)

Bases: ncclient.operations.rpc.RPC

copy-config RPC

session is the Session instance

async specifies whether the request is to be made asynchronously, see is_async

timeout is the timeout for a synchronous request, see timeout

raise_mode specifies the exception raising mode, see raise_mode

request(source, target)

Create or replace an entire configuration datastore with the contents of another complete configuration datastore.

source is the name of the configuration datastore to use as the source of the copy operation or config element containing the configuration subtree to copy

target is the name of the configuration datastore to use as the destination of the copy operation

Seealso :Source and target parameters
class ncclient.operations.Validate(session, async=False, timeout=30, raise_mode=0)

Bases: ncclient.operations.rpc.RPC

validate RPC. Depends on the :validate capability.

session is the Session instance

async specifies whether the request is to be made asynchronously, see is_async

timeout is the timeout for a synchronous request, see timeout

raise_mode specifies the exception raising mode, see raise_mode

request(source)

Validate the contents of the specified configuration.

source is the name of the configuration datastore being validated or config element containing the configuration subtree to be validated

Seealso :Source and target parameters
class ncclient.operations.Commit(session, async=False, timeout=30, raise_mode=0)

Bases: ncclient.operations.rpc.RPC

commit RPC. Depends on the :candidate capability, and the :confirmed-commit.

session is the Session instance

async specifies whether the request is to be made asynchronously, see is_async

timeout is the timeout for a synchronous request, see timeout

raise_mode specifies the exception raising mode, see raise_mode

request(confirmed=False, timeout=None)

Commit the candidate configuration as the device’s new current configuration. Depends on the :candidate capability.

A confirmed commit (i.e. if confirmed is True) is reverted if there is no followup commit within the timeout interval. If no timeout is specified the confirm timeout defaults to 600 seconds (10 minutes). A confirming commit may have the confirmed parameter but this is not required. Depends on the :confirmed-commit capability.

confirmed whether this is a confirmed commit

timeout specifies the confirm timeout in seconds

class ncclient.operations.DiscardChanges(session, async=False, timeout=30, raise_mode=0)

Bases: ncclient.operations.rpc.RPC

discard-changes RPC. Depends on the :candidate capability.

session is the Session instance

async specifies whether the request is to be made asynchronously, see is_async

timeout is the timeout for a synchronous request, see timeout

raise_mode specifies the exception raising mode, see raise_mode

request()

Revert the candidate configuration to the currently running configuration. Any uncommitted changes are discarded.

Locking

class ncclient.operations.Lock(session, async=False, timeout=30, raise_mode=0)

Bases: ncclient.operations.rpc.RPC

lock RPC

session is the Session instance

async specifies whether the request is to be made asynchronously, see is_async

timeout is the timeout for a synchronous request, see timeout

raise_mode specifies the exception raising mode, see raise_mode

request(target)

Allows the client to lock the configuration system of a device.

target is the name of the configuration datastore to lock

class ncclient.operations.Unlock(session, async=False, timeout=30, raise_mode=0)

Bases: ncclient.operations.rpc.RPC

unlock RPC

session is the Session instance

async specifies whether the request is to be made asynchronously, see is_async

timeout is the timeout for a synchronous request, see timeout

raise_mode specifies the exception raising mode, see raise_mode

request(target)

Release a configuration lock, previously obtained with the lock operation.

target is the name of the configuration datastore to unlock

Session

class ncclient.operations.CloseSession(session, async=False, timeout=30, raise_mode=0)

Bases: ncclient.operations.rpc.RPC

close-session RPC. The connection to NETCONF server is also closed.

session is the Session instance

async specifies whether the request is to be made asynchronously, see is_async

timeout is the timeout for a synchronous request, see timeout

raise_mode specifies the exception raising mode, see raise_mode

request()

Request graceful termination of the NETCONF session, and also close the transport.

class ncclient.operations.KillSession(session, async=False, timeout=30, raise_mode=0)

Bases: ncclient.operations.rpc.RPC

kill-session RPC.

session is the Session instance

async specifies whether the request is to be made asynchronously, see is_async

timeout is the timeout for a synchronous request, see timeout

raise_mode specifies the exception raising mode, see raise_mode

request(session_id)

Force the termination of a NETCONF session (not the current one!)

session_id is the session identifier of the NETCONF session to be terminated as a 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

This Page