HostsKeepalive

Function to iterate over Nornir hosts’ connections and check if connection still alive. If connection not responding, HostsKeepalive function deletes it.

In general case, running HostsKeepalive function will keep connection with host open, preventing it from timeout due to inactivity.

HostsKeepalive function supports these connection types:

  • netmiko - uses is_alive() method to check connection

  • paramiko channel - uses connection conn_obj.active attribute to check connection status

  • napalm - uses is_alive() method to check connection

  • scrapli - uses isalive() method to check connection

  • ncclient - uses connected attribute of connection manager to check connection status

  • http - HTTP connections non-persistent hence HostsKeepalive does nothing

  • pyats - uses is_connected method

For other connection types HostsKeepalive logs warning message about connection type being unknown and keeps connection intact.

Note

HostsKeepalive only checks previously established connections, it does not creates new connections to hosts or tries to reopen dead connections.

HostsKeepalive Sample Usage

Sample code to invoke HostsKeepalive function:

from nornir import InitNornir
from nornir_salt.plugins.functions import HostsKeepalive

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

stats = HostsKeepalive(nr)

HostsKeepalive reference

nornir_salt.plugins.functions.HostsKeepalive.HostsKeepalive(nr)
Parameters

nr – Nornir object

Returns

stats dictionary with statistics about HostsKeepalive execution

Return stats dictionary keys description:

  • dead_connections_cleaned - contains overall number of connections cleaned