4. SwitchConfigGenerator API¶
-
SwitchConfigGenerator.
access_cleanup
(newconfig)¶ Remove trunk configuration for all ports set to access mode
Parameters: - oldconfig – CiscoConfParse object of existing configuration file
- newconfig – CiscoConfParse object, representing the “new” config file
-
SwitchConfigGenerator.
add_snooping
(newconfig, vlans)¶ Add DHCP snooping commands to new configuration file
Parameters: - newconfig – CiscoConfParse object, representing the “new” config file
- vlans – List of VLANs to add
-
SwitchConfigGenerator.
add_voice_vlan
(voicevlan, newconfig)¶ Add voice VLAN to access ports that do not have it
Todo
Remove print statements when interfaces_for_review is completed
Parameters: - voicevlan – a VLAN represented as a string or int
- newconfig – CiscoConfParse object representing the “new” configuration file
-
SwitchConfigGenerator.
condensify_ports
(ports)¶ Turn a collection of ports into a Cisco-formatted range
Todo
Altering format depending on “new” switch model
Parameters: ports – List of port names Returns: Ports in a Cisco-formatted range Return type: String
-
SwitchConfigGenerator.
extract_management
(oldconfig, newconfig)¶ Extract the management VLAN and add it to new config file
Assuming the target equipment is a layer 2 switch with only one management VLAN, the VLAN config is extracted and the option to retain IP information is provided. ip tacacs source-interface <VLAN> is added but only necessary for a 4506; this command will be ignored on all other models.
Parameters: - oldconfig – CiscoConfParse object of existing configuration file
- newconfig – CiscoConfParse object, representing the “new” config file
-
SwitchConfigGenerator.
file_export
(outputfile, newconfig)¶ Save current configuration to a file
Exports to the directory defined by internal/global var ‘output_dir’
Parameters: - outputfile – Desired file name
- newconfig – CiscoConfParse object, representing the “new” config file
-
SwitchConfigGenerator.
force_user_input
(display, expect='')¶ Enforce that the user input at least one character
Parameters: - display – String to display as the input prompt
- expect – Regex string representing the required format of the response before returning to caller. Defaults to an empty string (match any)
Returns: User’s input
Return type: String
-
SwitchConfigGenerator.
get_configs
()¶ Set the configuration file to pull data from Prompts user for file name
Returns: oldconfig – Existing/source configuration file newconfig – Container for the new device’s configuration Return type: CiscoConfParse, CiscoConfParse
-
SwitchConfigGenerator.
get_switch_model
()¶ Prompt user to select model from compatible list
Returns: The user’s input as the internal switch_models index Return type: Int
-
SwitchConfigGenerator.
get_vlan_list
(oldconfig, regex)¶ Retrieve all VLANs from the old configuration file and return a list.
(This is intended for future use in cross-platform conversions.)
Parameters: - oldconfig – CiscoConfParse object of existing configuration file
- regex – Regex string used to determine if port is a feed
Returns: All VLANs defined, sorted in ascending order
Return type: List
-
SwitchConfigGenerator.
interfaces_for_review
(newconfig, nojacks, newjacks)¶ Searches for interfaces on the “new” device with non-standard configs to be reviewed manually.
Searches for statically set PoE, duplex, operating speed, no defined switchport mode
Parameters: newconfig – CiscoConfParse object representing the “new” configuration file
-
SwitchConfigGenerator.
is_ip
(addr)¶
-
SwitchConfigGenerator.
migrate_ports
(oldconfig, newconfig, hostname, switch_type)¶ Map and transfer configuration settings of old ports
Searches for Excel workbooks in the ./cutsheer_dir/ directory. The “cutsheet” files are generated by TurboClerk which are pulled from Netdoc.
As of May 2016, Carlos Bassett has set a standard for worksheet layouts and file names, as follows:
- The spreadsheets must have each tab nammed from the source switch and the first column MUST be the port name.
- Any jack associated to this port must be in the row, otherwise configuration will not be transferred.
- The file with the current port-jack mappings must have the building code in the name, along with “as is”.
- The file with the future port-jack mappings must have the building code in the name, along with “to be”.
- The file with the future port-jack mappings MUST begin listing ports in the third row.
Note that this function has the potential to break if corresponding jacks are found from a different existing switch. A future workaround of loading the switch it is found from has been added as a TODO
Todo
Remove print statements when interfaces_for_review is completed
All returned variables are intended for printing out warnings/notices/debugging
Parameters: - oldconfig – CiscoConfParse object of existing configuration file
- newconfig – CiscoConfParse object, representing the “new” config file
- hostname – Name of the new switch
- switch_type – the index of switch_models that represents the “new” switch model
Returns: _blades_ – Detected blade numbers in the stack _nojacks_ – Port names on the new switch that do not have a jack associated with them _newjacks_ – Port names on the new switch that have jacks associated to them, however they do not exist in any As-Is spreadsheets
Return type: (Set, List, List)
-
SwitchConfigGenerator.
no_files_found
(directory)¶ Allows the user to move files to correct directory or exit early
Parameters: directory – The folder in which the files should be located
-
SwitchConfigGenerator.
remove_mdix_and_dot1q
(newconfig)¶ Remove MDIX and dot1q from all interfaces
Note
Should be run after trunk_cleanup()
Keyword arguments: newconfig – CiscoConfParse object, representing the “new” config file
-
SwitchConfigGenerator.
set_voice_vlan
(oldconfig)¶ Select and add a voice VLAN to add to access ports
Parameters: oldconfig – CiscoConfParse object of existing configuration file
-
SwitchConfigGenerator.
setup_feeds
(newconfig, switch_type, blades, vlans)¶ Configure feedports
Allows the user to define as many feedports as desired. Checks the validity of the port name as defined by a regex string.
Parameters: - newconfig – CiscoConfParse object, representing the “new” config file
- switch_type – The representation of the switch model in the form of the switch_models index
- blades – A Set of all blade numbers in the stack
- vlans – – A List of all VLANs transferred to the new configuration file
-
SwitchConfigGenerator.
trunk_cleanup
(newconfig)¶ Remove access mode configuration on trunk ports
Removes access/voice vlan configs, spanning-tree portfast, and no snmp trap link-status
Todo
Detect and remove VLANs from VLAN ranges
Parameters: newconfig – CiscoConfParse object representing the “new” configuration file
-
SwitchConfigGenerator.
vlan_extract
(oldconfig, newconfig, regex, genconfig=False)¶ Retrieve all VLANs from the old configuration file
Automatically detects if certain VLANs will not be used and will offer to prune them.
Note
For pruning to work, this _must_ be called before
setup_feeds()
Parameters: - oldconfig – CiscoConfParse object of existing configuration file
- newconfig – CiscoConfParse object, representing the “new” config file defaults to None
- regex – Regex string used to determine if port is a feed
- genconfig – A boolean representing if a full config will be generated: If True, all VLANs will be added to the new config file. Defaults to False
Returns: All VLANs defined, sorted in ascending order
Return type: List