diff --git a/catalystwan/api/templates/cli_template.py b/catalystwan/api/templates/cli_template.py index afaebb05..db0ff3f9 100644 --- a/catalystwan/api/templates/cli_template.py +++ b/catalystwan/api/templates/cli_template.py @@ -5,7 +5,7 @@ import json import logging from difflib import Differ -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, List from attr import define # type: ignore from ciscoconfparse import CiscoConfParse # type: ignore @@ -126,6 +126,7 @@ def compare_template( second: CiscoConfParse, full: bool = False, debug: bool = False, + ignored_lines: List[str] = [], ) -> str: """ @@ -134,6 +135,7 @@ def compare_template( second: Second template for comparison. full: Return a full comparison if True, otherwise only the lines that differ. debug: Adding debug to the logger. Defaults to False. + ignored_lines: List of configs statements to be excluded from comparison Returns: str: The compared templates. @@ -162,8 +164,11 @@ def compare_template( auth-port 151 exit """ - first_n = list(map(lambda x: x + "\n", first.ioscfg)) - second_n = list(map(lambda x: x + "\n", second.ioscfg)) + for line in ignored_lines: + first.delete_lines(line) + second.delete_lines(line) + first_n = list(map(lambda x: x.strip() + "\n", first.ioscfg)) + second_n = list(map(lambda x: x.strip() + "\n", second.ioscfg)) compare = list(Differ().compare(first_n, second_n)) if not full: compare = [x for x in compare if x[0] in ["?", "-", "+"]] @@ -177,6 +182,7 @@ def compare_with_running( template: CiscoConfParse, device: Device, debug: bool = False, + ignored_lines: List[str] = [], ) -> str: """The comparison of the config with the one running on the machine. @@ -185,6 +191,7 @@ def compare_with_running( device: The device on which to compare config. full: Return a full comparison if True, otherwise only the lines that differ. debug: Adding debug to the logger. Defaults to False. + ignored_lines: List of configs statements to be excluded from comparison Returns: str: The compared templates. @@ -216,4 +223,4 @@ def compare_with_running( . """ running_config = self.load_running(session, device) - return self.compare_template(running_config, template, debug) + return self.compare_template(running_config, template, debug=debug, ignored_lines=ignored_lines) diff --git a/pyproject.toml b/pyproject.toml index 1331076a..e103b264 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "catalystwan" -version = "0.34.1" +version = "0.34.2" description = "Cisco Catalyst WAN SDK for Python" authors = ["kagorski "] readme = "README.md"