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 connectionparamiko channel - uses connection
conn_obj.activeattribute to check connection statusnapalm - uses
is_alive()method to check connectionscrapli - uses
isalive()method to check connectionncclient - uses
connectedattribute of connection manager to check connection statushttp - HTTP connections non-persistent hence
HostsKeepalivedoes nothingpyats - uses
is_connectedmethod
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
HostsKeepaliveexecution
Return
statsdictionary keys description:dead_connections_cleaned- contains overall number of connections cleaned