ncclient_call
Ncclient is a popular library to interact with devices using NETCONF, this plugin is a wrapper around ncclient connection manager object.
NETCONF protocol has a specific set of RPC calls available for use, rather
than coding separate task for each of them, ncclient_call
made to execute
any arbitrary method supported by manager object plus a set of additional
helper methods to extend Ncclient library functionality.
ncclient_call sample usage
Sample code to run ncclient_call
task:
from nornir import InitNornir
from nornir_salt.plugins.tasks import ncclient_call
nr = InitNornir(config_file="config.yaml")
output = nr.run(
task=ncclient_call,
call="get_config",
source="running"
)
ncclient_call returns
Returns XML text string by default, but can return XML data transformed in JSON, YAML or Python format.
ncclient_call reference
- nornir_salt.plugins.tasks.ncclient_call.ncclient_call(task: nornir.core.task.Task, call: str, *args, **kwargs) nornir.core.task.Result
Task to handle a call of NCClient manager object methods
- Parameters
call – (str) ncclient manager object method to call
arg – (list) any
*args
to use with call methodkwargs – (dict) any
**kwargs
to use with call method
additional methods reference
ncclient_call - dir
- nornir_salt.plugins.tasks.ncclient_call._call_dir(manager, *args, **kwargs)
Function to return a list of available methods/operations
ncclient_call - help
- nornir_salt.plugins.tasks.ncclient_call._call_help(manager, method_name, *args, **kwargs)
Helper function to return docstring for requested method
- Parameters
method_name – (str) name of method or function to return docstring for
ncclient_call - server_capabilities
- nornir_salt.plugins.tasks.ncclient_call._call_server_capabilities(manager, capab_filter=None, *args, **kwargs)
Helper function to get server capabilities
- Parameters
capa_filter – (str) glob filter to filter capabilities
ncclient_call - connected
- nornir_salt.plugins.tasks.ncclient_call._call_connected(manager, *args, **kwargs)
Helper function to get connected status
ncclient_call - transaction
- nornir_salt.plugins.tasks.ncclient_call._call_transaction(manager, *args, **kwargs)
Function to edit device configuration in a reliable fashion using capabilities advertised by NETCONF server.
- Parameters
target – (str) name of datastore to edit configuration for, if no
target
argument provided and device supports candidate datastore usescandidate
datastore, usesrunning
datastore otherwiseconfig – (str) configuration to apply
confirmed – (bool) if True (default) uses commit confirmed
commit_final_delay – (int) time to wait before doing final commit after commit confirmed, default is 1 second
confirm_delay – (int) device commit confirmed rollback delay, default 60 seconds
validate – (bool) if True (default) validates candidate configuration before commit
edit_rpc – (str) name of edit configuration RPC, options are - “edit_config” (default), “load_configuration” (juniper devices only)
edit_arg – (dict) dictionary of arguments to use with configuration edit RPC
commit_arg – (dict) dictionary of commit RPC arguments used with first commit call
- Returns result
(list) list of steps performed with details
Function work flow:
Lock target configuration datastore
If server supports it - Discard previous changes if any
Perform configuration edit using RPC specified in
edit_rpc
argumentIf server supports it - validate configuration if
validate
argument is TrueDo commit operation:
If server supports it - do commit operation if
confirmed
argument is FalseIf server supports it - do commit confirmed if
confirmed
argument is True usingconfirm_delay
timer withcommit_arg
argumentIf confirmed commit requested, wait for
commit_final_delay
timer before sending final commit, final commit does not usecommit_arg
arguments
Unlock target configuration datastore
If server supports it - discard all changes if any of steps 3, 4, 5 or 7 fail
Return results list of dictionaries keyed by step name