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
format – (str) configuration string format, default is xml
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
- 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
Edit configuration
If server supports it - validate configuration if
validate
argument is TrueIf server supports it - do commit confirmed if
confirmed
argument is TrueIf server supports it - do commit operation
Unlock target configuration datastore
If server supports it - discard all changes if any of steps 3, 4, 5 or 6 fail
Return results list of dictionaries keyed by step name