scrapli_netconf_call

Dependencies: Scrapli Netconf need to be installed

Scrapli Netconf is a library to interact with devices using NETCONF. scrapli_netconf_call task plugin is a wrapper around Scrapli Netconf connection object.

NETCONF protocol has a specific set of RPC calls available for use, rather than coding separate task for each of them, scrapli_netconf_call made to execute any arbitrary method supported by Scrapli Netconf connection object plus a set of additional helper methods for extended functionality.

Sample code to run scrapli_netconf_call task:

from nornir import InitNornir
from nornir_salt.plugins.tasks import scrapli_netconf_call

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

output = nr.run(
    task=scrapli_netconf_call,
    call="get_config",
    source="running"
)

API Reference

nornir_salt.plugins.tasks.scrapli_netconf_call.scrapli_netconf_call(task: nornir.core.task.Task, call: str, *args, **kwargs) nornir.core.task.Result

Dispatcher function to call one of the supported scrapli_netconf methods or one of helper functions.

Parameters
  • call – (str) Scrapli Netconf connection object method to call

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

  • kwargs – (dict) any **kwargs to use with call method

Returns

result of scrapli-netconf connection method call

Additional Call Methods Reference

dir

nornir_salt.plugins.tasks.scrapli_netconf_call._call_dir(conn, *args, **kwargs)

Helper function to return a list of supported tasks

help

nornir_salt.plugins.tasks.scrapli_netconf_call._call_help(conn, *args, **kwargs)

Helper function to return docstring for requested method

Parameters

method_name – (str) name of method or function to return docstring for

server_capabilities

nornir_salt.plugins.tasks.scrapli_netconf_call._call_server_capabilities(conn, capab_filter=None, *args, **kwargs)

Helper function to return NETCONF server capabilities

Parameters

capa_filter – (str) glob filter to filter capabilities

connected

nornir_salt.plugins.tasks.scrapli_netconf_call._call_connected(conn, *args, **kwargs)

Helper function to return connection status

transaction

nornir_salt.plugins.tasks.scrapli_netconf_call._call_transaction(conn, *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

  • 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. 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 operation

  6. Unlock target configuration datastore

  7. If steps 3, 4 or 5 fails, discard all changes

  8. Return results list of dictionaries keyed by step name

Scrapli-netconf implementation lacks of support for commit confirmed operation as of creating this module.