s_nexthop_summary

s_nexthop_summary.script_main(session, ask_vrf=True, vrf=None)
SINGLE device script
Author: Jamie Caesar

This script will grab the route table information from a Cisco IOS or NXOS device and export details about each next-hop address (how many routes and from which protocol) into a CSV file. It will also list all connected networks and give a detailed breakdown of every route that goes to each next-hop.

Parameters:
  • session (sessions.Session) – A subclass of the sessions.Session object that represents this particular script session (either SecureCRTSession or DirectSession)
  • ask_vrf (bool) – A boolean that specifies if we should prompt for which VRF. The default is true, but when this module is called from other scripts, we may want avoid prompting and supply the VRF with the “vrf” input.
  • vrf (str) – The VRF that we should get the route table from. This is used only when ask_vrf is False.
s_nexthop_summary.update_empty_interfaces(route_table)

Takes the routes table as a list of dictionaries (with dict key names used in parse_routes function) and does recursive lookups to find the outgoing interface for those entries in the route-table where the outgoing interface isn’t listed.

Parameters:route_table (list of dict) – Route table information as a list of dictionaries (output from TextFSM)
Returns:The updated route_table object with outbound interfaces filled in.
Return type:list of dict
s_nexthop_summary.parse_routes(fsm_routes)

This function will take the TextFSM parsed route-table from the textfsm_parse_to_dict function. Each dictionary in the TextFSM output represents a route entry. Each of these dictionaries will be updated to convert IP addresses into ip_address or ip_network objects (from the ipaddress.py module). Some key names will also be updated also.

Parameters:fsm_routes (list of dict) – TextFSM output from the textfsm_parse_to_dict function.
Returns:An updated list of dictionaries that replaces IP address strings with objects from the ipaddress.py module
Return type:list of dict
s_nexthop_summary.nexthop_summary(textfsm_dict)

A function that builds a CSV output (list of lists) that displays the summary information after analyzing the input route table.

Parameters:textfsm_dict (list of dict) – The route table information in list of dictionaries format.
Returns:The nexthop summary information in a format that can be easily written to a CSV file.
Return type:list of lists