Networking

nornir.plugins.tasks.networking.napalm_cli(task: nornir.core.task.Task, commands: List[str]) → nornir.core.task.Result

Run commands on remote devices using napalm

Parameters:commands – commands to execute
Returns:
  • result (dict): result of the commands execution
Return type:Result object with the following attributes set
nornir.plugins.tasks.networking.napalm_configure(task: nornir.core.task.Task, dry_run: Optional[bool] = None, filename: Optional[str] = None, configuration: Optional[str] = None, replace: bool = False) → nornir.core.task.Result

Loads configuration into a network devices using napalm

Parameters:
  • dry_run – Whether to apply changes or not
  • filename – filename containing the configuration to load into the device
  • configuration – configuration to load into the device
  • replace – whether to replace or merge the configuration
Returns:

  • changed (bool): whether the task is changing the system or not
  • diff (string): change in the system

Return type:

Result object with the following attributes set

nornir.plugins.tasks.networking.napalm_get(task: nornir.core.task.Task, getters: List[str], getters_options: Optional[Dict[str, Dict[str, Any]]] = None, **kwargs) → nornir.core.task.Result

Gather information from network devices using napalm

Parameters:
  • getters – getters to use
  • getters_options (dict of dicts) – When passing multiple getters you pass a dictionary where the outer key is the getter name and the included dictionary represents the options to pass to the getter
  • **kwargs – will be passed as they are to the getters

Examples

Simple example:

> nr.run(task=napalm_get,
>        getters=["interfaces", "facts"])

Passing options using **kwargs:

> nr.run(task=napalm_get,
>        getters=["config"],
>        retrieve="all")

Passing options using getters_options:

> nr.run(task=napalm_get,
>        getters=["config", "interfaces"],
>        getters_options={"config": {"retrieve": "all"}})
Returns:
  • result (dict): dictionary with the result of the getter
Return type:Result object with the following attributes set
nornir.plugins.tasks.networking.napalm_validate(task: nornir.core.task.Task, src: Optional[str] = None, validation_source: Optional[Dict[str, Dict[str, Any]]] = None) → nornir.core.task.Result

Gather information with napalm and validate it:

Parameters:
  • src – file to use as validation source
  • validation_source (list) – data to validate device’s state
Returns:

  • result (dict): dictionary with the result of the validation
  • complies (bool): Whether the device complies or not

Return type:

Result object with the following attributes set

nornir.plugins.tasks.networking.netmiko_file_transfer(task: nornir.core.task.Task, source_file: str, dest_file: str, **kwargs) → nornir.core.task.Result

Execute Netmiko file_transfer method

Parameters:
  • source_file – Source file.
  • dest_file – Destination file.
  • kwargs – Additional arguments to pass to file_transfer
Returns:

  • result (bool): file exists and MD5 is valid
  • changed (bool): the destination file was changed

Return type:

Result object with the following attributes set

nornir.plugins.tasks.networking.netmiko_send_command(task: nornir.core.task.Task, command_string: str, use_timing: bool = False, enable: bool = False, **kwargs) → nornir.core.task.Result

Execute Netmiko send_command method (or send_command_timing)

Parameters:
  • command_string – Command to execute on the remote network device.
  • use_timing – Set to True to switch to send_command_timing method.
  • enable – Set to True to force Netmiko .enable() call.
  • kwargs – Additional arguments to pass to send_command method.
Returns:

  • result: Result of the show command (generally a string, but depends on use of TextFSM).

Return type:

Result object with the following attributes set

nornir.plugins.tasks.networking.netmiko_send_config(task: nornir.core.task.Task, config_commands: Optional[List[str]] = None, config_file: Optional[str] = None, **kwargs) → nornir.core.task.Result

Execute Netmiko send_config_set method (or send_config_from_file)

Parameters:
  • config_commands – Commands to configure on the remote network device.
  • config_file – File to read configuration commands from.
  • kwargs – Additional arguments to pass to method.
Returns:

  • result (str): string showing the CLI from the configuration changes.

Return type:

Result object with the following attributes set

nornir.plugins.tasks.networking.netmiko_save_config(task: nornir.core.task.Task, cmd: str = '', confirm: bool = False, confirm_response: str = '') → nornir.core.task.Result

Execute Netmiko save_config method :param cmd: Command used to save the configuration. :type cmd: str, optional :param confirm: Does device prompt for confirmation before executing save operation :type confirm: bool, optional :param confirm_response: Response send to device when it prompts for confirmation :type confirm_response: str, optional

Returns:
obj: nornir.core.task.Result:
  • result (str): String showing the CLI output from the save operation
nornir.plugins.tasks.networking.tcp_ping(task: nornir.core.task.Task, ports: List[int], timeout: int = 2, host: Optional[str] = None) → nornir.core.task.Result

Tests connection to a tcp port and tries to establish a three way handshake. To be used for network discovery or testing.

Parameters:
  • ports (list of int) – tcp ports to ping
  • timeout (int, optional) – defaults to 2
  • host (string, optional) – defaults to hostname
Returns:

  • result (dict): Contains port numbers as keys with True/False as values

Return type:

Result object with the following attributes set