TabulateFormatter
Function to transform results in a text table format using Tabulate module.
TabulateFormatter works with a list of dictionaries to represent them as a table, if Nornir AggregatedResult object passed on to TabulateFormatter it uses ResultSerializer function to serialize results into a list of dictionaries.
Dependencies:
Nornir 3.x.x
Tabulate module for results table formatting
Sample code to use TabulateFormatter:
from nornir import InitNornir
from nornir_salt.plugins.functions import TabulateFormatter
from nornir_netmiko import netmiko_send_command
nr = InitNornir(config_file="config.yaml")
result = NornirObj.run(
task=netmiko_send_command,
command_string="show clock"
)
print(TabulateFormatter(result))
# prints:
# result changed diff failed name connection_retry task_retry exception host
# ------------------------ --------- ------ -------- ---------- ------------------ ------------ ----------- ------
# Sun Jul 11 08:41:06 2021 False False show clock 0 0 ceos1
# Timezone: UTC
# Clock source: local
# Sun Jul 11 08:41:06 2021 False False show clock 0 0 ceos2
# Timezone: UTC
# Clock source: local
Reference
- nornir_salt.plugins.functions.TabulateFormatter.TabulateFormatter(result, tabulate=True, headers='keys', headers_exclude=None, sortby=None, reverse=False)
Function to format results in a text table.
- Parameters
result – list of dictionaries or
nornir.core.task.AggregatedResult
objecttabulate – (dict or str or bool) controls tabulate behavior
headers – (list or str) list of table headers, comma-separated string of headers or one of tabulate supported values, e.g.
keys
headers_exclude – (list) list of table headers, comma-separated string of headers to exclude
sortby – (str) name of the key to sort table by, default is
None
- no sorting appliedreverse – (bool) reverses sort order if True, default is False
Supported values for
tabulate
attribute:brief
-tablefmt
isgrid
,showindex
isTrue
,headers
arehost, name, result, exception
terse
-tablefmt
issimple
,showindex
isTrue
,headers
arehost, name, result, exception
True
- usesheaders
, no other formattingFalse
- does nothing, returns original resultsextend
- if result is a list, extends it to form final table, appends it as is otherwisedictionary
- dictionary content passed as**kwargs
totabulate.tabulate
method