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:

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 object

  • tabulate – (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 applied

  • reverse – (bool) reverses sort order if True, default is False

Supported values for tabulate attribute:

  • brief - tablefmt is grid, showindex is True, headers are host, name, result, exception

  • terse - tablefmt is simple, showindex is True, headers are host, name, result, exception

  • True - uses headers, no other formatting

  • False - does nothing, returns original results

  • extend - if result is a list, extends it to form final table, appends it as is otherwise

  • dictionary - dictionary content passed as **kwargs to tabulate.tabulate method