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 import ncclient_call

nr = InitNornir(config_file="config.yaml")

output =

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

  • call – (str) ncclient manager object method to call

  • arg – (list) any *args to use with call method

  • kwargs – (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 alist 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


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, *args, **kwargs)

Helper function to get server 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.

  • target – (str) name of datastore to edit configuration for, if no target argument provided and device supports candidate datastore uses candidate datastore, uses running datastore otherwise

  • config – (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:

  1. Lock target configuration datastore

  2. If server supports it - Discard previous changes if any

  3. Edit configuration

  4. If server supports it - validate configuration if validate argument is True

  5. If server supports it - do commit confirmed if confirmed argument is True

  6. If server supports it - do commit operation

  7. Unlock target configuration datastore

  8. If server supports it - discard all changes if any of steps 3, 4, 5 or 6 fail

  9. Return results list of dictionaries keyed by step name