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 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 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 uses candidate datastore, uses running datastore otherwise

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

  1. Lock target configuration datastore

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

  3. Perform configuration edit using RPC specified in edit_rpc argument

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

  5. Do commit operation:

    1. If server supports it - do commit operation if confirmed argument is False

    2. If server supports it - do commit confirmed if confirmed argument is True using confirm_delay timer with commit_arg argument

    3. If confirmed commit requested, wait for commit_final_delay timer before sending final commit, final commit does not use commit_arg arguments

  6. Unlock target configuration datastore

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

  8. Return results list of dictionaries keyed by step name