1. Getting started with the awesome configuration generator¶
1.1. Installation and Preparation¶
Before you begin, a few packages are necessary to download and install. You can do this via pip
for easy installation. You can simply type pip install -r requirements.txt
(or pip install -r dev-requirements.txt
if you plan on contributing).
1.1.1. Dependencies¶
natsort==5.0.1
ciscoconfparse==1.2.40
colorama==0.3.7
ipaddr==2.1.11
dnspython==1.14.0
openpyxl==2.3.5
et-xmlfile==1.0.1
jdcal==1.2
1.1.2. Developer Dependencies¶
alabaster==0.7.8
Babel==2.3.4
ciscoconfparse==1.2.40
colorama==0.3.7
dnspython==1.14.0
docutils==0.12
et-xmlfile==1.0.1
imagesize==0.7.1
ipaddr==2.1.11
jdcal==1.2
Jinja2==2.8
MarkupSafe==0.23
natsort==5.0.1
openpyxl==2.3.5
Pygments==2.1.3
pytz==2016.4
six==1.10.0
snowballstemmer==1.2.1
Sphinx==1.4.4
sphinx-rtd-theme==0.1.9
1.2. Directory Structure¶
In order to run the script, several folders need to be created:
configconverter
|\_ configs
|\_ cutsheets
\\_ output
\_ templates
1.3. Invoking the module from CLI¶
The module includes an if __name__ == '__main__':
statement so it can be
called from the directory itself. You may copy it directly, but we’ve included
it here (with the import
) for convenience:
from configconverter import SwitchConfigGenerator
if __name__ == "__main__":
oldconfig, newconfig = get_configs()
switch_type = get_switch_model()
hostname = force_user_input("Enter hostname of new switch: ").upper()
outputfile = input(
"Enter output file name (default - " + hostname + ".txt): ")
outputfile = outputfile if outputfile else hostname + ".txt"
createconfig = ("n" not in input(
"Generate full config file?[Y|n]: ").lower())
blades, nojacks, newjacks = migrate_ports(
oldconfig, newconfig, hostname, switch_type)
# Add ip dhcp snooping later! Adding it immediately after interfaces
# causes a bug if trying to use file as startup-config
vlans = vlan_extract(oldconfig, newconfig, feed_ports_regex[
switch_models[switch_type]], createconfig)
setup_feeds(newconfig, switch_type, blades, vlans)
interfaces_for_review(newconfig, nojacks, newjacks)
set_voice_vlan(oldconfig)
access_cleanup(newconfig)
trunk_cleanup(newconfig)
# This must be run AFTER trunk_cleanup()
if not switch_models[switch_type] == "3560":
remove_mdix_and_dot1q(newconfig)
if createconfig:
baseconfig = ".txt"
if (switch_type == len(switch_models) - 1):
baseconfig = "baseconfig.txt"
else:
baseconfig = switch_models[switch_type] + "base.txt"
newconfig.prepend_line("!")
newconfig.prepend_line("hostname " + hostname)
newconfig.prepend_line("!")
newconfig.commit()
extract_management(oldconfig, newconfig)
add_snooping(newconfig, vlans)
newconfig.append_line("!")
with open(template_dir + baseconfig, "r") as b:
for line in b:
newconfig.append_line(line.rstrip())
newconfig.commit()
file_export(outputfile, newconfig)
Note
You are still responsible for including the module directory in the search path