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

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, *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 - locked

nornir_salt.plugins.tasks.ncclient_call._call_locked(manager, *args, **kwargs)

Module: nornir_salt Task plugin: ncclient_call Plugin function: locked

Helper function to run this edit-config flow:

  1. Lock target configuration/datastore

  2. Discard previous changes if any

  3. Run edit config

  4. Validate new confiugration if server supports it

  5. Run commit confirmed if server supports it

  6. Run final commit

  7. Unlock target configuration/datastore

If any of steps 3, 4, 5, 6 fails, all changes discarded

Parameters
  • target – (str) name of datastore to edit configuration for

  • config – (str) configuration to apply

  • format – (str) configuration format, default is xml

Returns result

(list) list of steps performed with details

Returns failed

(bool) status indicator if change failed