diff --git a/generate-conf.py b/generate-conf.py index 9f3a596..4ac7c64 100644 --- a/generate-conf.py +++ b/generate-conf.py @@ -5,6 +5,7 @@ import logging from pprint import pprint import colorlog +import termcolor import yaml from jinja2 import Template @@ -21,7 +22,6 @@ def syntax_from_range(value, vlan_syntax=False): syntax = "" in_range = False for i in value: - print(i, type(i)) if prec is None or prec != i - 1: if syntax == "": syntax = str(i) @@ -105,7 +105,6 @@ def gen_interfaces(switch_config): if_profile = yaml.load(open("configs/profiles/{}.yml".format(if_config.get("profile"))), yaml.Loader) iface = range_from_syntax(iface) for iface_number in iface: - print("if_num", iface_number) if not if_profile.get("ignore_port", False): interface = { "number": iface_number, @@ -146,9 +145,6 @@ def gen_interfaces(switch_config): def gen_conf(master_config, switch_config, old_config): header = "\n".join(old_config.split("\n")[:2]) interfaces, vlans, mac_based_ports, ra_guard_ports, dhcp_snooping_vlans = gen_interfaces(switch_config) - print("mac", set(mac_based_ports)) - print("ra", set(ra_guard_ports)) - print("dhcp", set(dhcp_snooping_vlans)) config_dict = { "header": header, "hostname": switch_config.get("hostname"), @@ -211,7 +207,14 @@ if __name__ == "__main__": logging.info("Generating configuration for {}".format(args.switch_name)) configuration = gen_conf(master_config, switch_config, old_config) for line in difflib.unified_diff(old_config.split("\n"), configuration.split("\n"), fromfile='origin', tofile='new', lineterm=""): - print(line) + if line.startswith("-"): + termcolor.cprint(line, "red") + elif line.startswith("+"): + termcolor.cprint(line, "green") + elif line.startswith("@"): + termcolor.cprint(line, "yellow") + else: + print(line) if args.dry_run or input("Voulez-vous déployer la configuration sur le switch ? y/[n]").lower() not in ["o","y"]: logger.info("Aborting deployement") exit(0) diff --git a/requirements.txt b/requirements.txt index f4105ce..617e9d8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,7 @@ +colorlog==4.2.1 +Jinja2==2.11.2 +MarkupSafe==1.1.1 +pkg-resources==0.0.0 +PyYAML==5.3.1 ssh2-python==0.18.0.post1 +termcolor==1.1.0