Utilities

CiscoAutomationFramework also provides some integrated utility functions for doing various things with data from switches such as abbreviating interfaces, checking if IP addresses are valid, and printing output in a nice format.

CiscoAutomationFramework.util.abbreviate_interface(interface_string, max_chars=2)

Takes an Interface name ex. GigabitEthernet1/0/4 and abbreviates it ex Gi1/0/4

Parameters:interface_string (str) – Interface String ex. GigabitEthernet1/0/4

:param :return: Abbreviated interface string :rtype: str

CiscoAutomationFramework.util.column_print(data, spaces_between_columns=2, separator_char=None)

Print in nice even columns where each column is only the width it needs to be, not the width of the widest column in the list. This will give output in a table format similar to much Windows/Linux CLI output. Based off of code from https://stackoverflow.com/questions/9989334/create-nice-column-output-in-python

Parameters:
  • data (list[Union[list, tuple]]) – List of List/Tuples of equal length, the first list being the header, all the rest being the data.
  • spaces_between_columns (int) – Number of spaces to be between each column (default 2)
  • separator_char (str) – Character to place in a row between the header and data, default to nothing
Returns:

Nothing. This function executes the print

CiscoAutomationFramework.util.is_ipv4(addr)

Checks if the IP address provided is an IPv4 Address.

Parameters:addr (str) – IP address to check
Returns:True/False
Return type:bool