operations
– Everything RPC¶
-
class
ncclient.operations.
RaiseMode
¶ Define how errors indicated by RPC should be handled.
Note that any error_filters defined in the device handler will still be applied, even if ERRORS or ALL is defined: If the filter matches, an exception will NOT be raised.
-
ALL
= 2¶ Don’t look at the error-type, always raise.
-
ERRORS
= 1¶ Raise only when the error-type indicates it is an honest-to-god error.
-
Base classes¶
-
class
ncclient.operations.
RPC
(session, device_handler, 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
instancedevice_handler” is the :class:`~ncclient.devices..*DeviceHandler` 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.
-
_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 theraise_mode
a rpc-error element in the reply may lead to anRPCError
exception.In asynchronous mode, returns immediately, returning self. The
event
attribute will be set when the reply has been received (seereply
) or an error occured (seeerror
).op is the operation to be requested as an
Element
-
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.
-
event
¶ Event
that is set when reply has been received or when an error preventing delivery of the reply occurs.
-
is_async
¶ Specifies whether this RPC will be / was requested asynchronously. By default RPC’s are synchronous.
-
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 inRaiseMode
.
-
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()
.
-
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.
-
_parsing_hook
(root)¶ No-op by default. Gets passed the root element for the reply.
-
errors
¶ List of RPCError objects. Will be empty if there were no rpc-error elements in reply.
-
ok
¶ Boolean value indicating if there were no errors.
-
xml
¶ rpc-reply element as returned.
-
-
exception
ncclient.operations.
RPCError
(raw, errs=None)¶ Bases:
ncclient.operations.errors.OperationError
Represents an rpc-error. It is a type of
OperationError
and can be raised as such.-
info
¶ XML string or None; representing the error-info element.
-
message
¶ The contents of the error-message element if present or None.
-
path
¶ The contents of the error-path element if present or None.
-
severity
¶ The contents of the error-severity element.
-
tag
¶ The contents of the error-tag element.
-
type
¶ The contents of the error-type element.
-
Operations¶
Retrieval¶
-
class
ncclient.operations.
Get
(session, device_handler, async=False, timeout=30, raise_mode=0)¶ Bases:
ncclient.operations.rpc.RPC
The get RPC.
session is the
Session
instancedevice_handler” is the :class:`~ncclient.devices..*DeviceHandler` 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
(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, device_handler, async=False, timeout=30, raise_mode=0)¶ Bases:
ncclient.operations.rpc.RPC
The get-config RPC.
session is the
Session
instancedevice_handler” is the :class:`~ncclient.devices..*DeviceHandler` 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, 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_xml
¶ data element as an XML string
-
-
class
ncclient.operations.
Dispatch
(session, device_handler, async=False, timeout=30, raise_mode=0)¶ Bases:
ncclient.operations.rpc.RPC
Generic retrieving wrapper
session is the
Session
instancedevice_handler” is the :class:`~ncclient.devices..*DeviceHandler` 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
(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, device_handler, async=False, timeout=30, raise_mode=0)¶ Bases:
ncclient.operations.rpc.RPC
edit-config RPC
session is the
Session
instancedevice_handler” is the :class:`~ncclient.devices..*DeviceHandler` 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
(config, format='xml', target='candidate', 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, device_handler, async=False, timeout=30, raise_mode=0)¶ Bases:
ncclient.operations.rpc.RPC
delete-config RPC
session is the
Session
instancedevice_handler” is the :class:`~ncclient.devices..*DeviceHandler` 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, device_handler, async=False, timeout=30, raise_mode=0)¶ Bases:
ncclient.operations.rpc.RPC
copy-config RPC
session is the
Session
instancedevice_handler” is the :class:`~ncclient.devices..*DeviceHandler` 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, device_handler, async=False, timeout=30, raise_mode=0)¶ Bases:
ncclient.operations.rpc.RPC
validate RPC. Depends on the :validate capability.
session is the
Session
instancedevice_handler” is the :class:`~ncclient.devices..*DeviceHandler` 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='candidate')¶ 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
** modified to only accept valid string as source argument. Elements no longer accepted - earies - 04/22/2013
Seealso: Source and target parameters
-
-
class
ncclient.operations.
Commit
(session, device_handler, 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
instancedevice_handler” is the :class:`~ncclient.devices..*DeviceHandler` 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, persist=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
persist make the confirmed commit survive a session termination, and set a token on the ongoing confirmed commit
-
-
class
ncclient.operations.
DiscardChanges
(session, device_handler, async=False, timeout=30, raise_mode=0)¶ Bases:
ncclient.operations.rpc.RPC
discard-changes RPC. Depends on the :candidate capability.
session is the
Session
instancedevice_handler” is the :class:`~ncclient.devices..*DeviceHandler` 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, device_handler, async=False, timeout=30, raise_mode=0)¶ Bases:
ncclient.operations.rpc.RPC
lock RPC
session is the
Session
instancedevice_handler” is the :class:`~ncclient.devices..*DeviceHandler` 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='candidate')¶ 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, device_handler, async=False, timeout=30, raise_mode=0)¶ Bases:
ncclient.operations.rpc.RPC
unlock RPC
session is the
Session
instancedevice_handler” is the :class:`~ncclient.devices..*DeviceHandler` 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='candidate')¶ 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, device_handler, 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
instancedevice_handler” is the :class:`~ncclient.devices..*DeviceHandler` 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, device_handler, async=False, timeout=30, raise_mode=0)¶ Bases:
ncclient.operations.rpc.RPC
kill-session RPC.
session is the
Session
instancedevice_handler” is the :class:`~ncclient.devices..*DeviceHandler` 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
-