Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
Addition of strip to get rid of unwanted whitespaces, plus option to … (
Browse files Browse the repository at this point in the history
#801)

* Addition of strip to get rid of unwanted whitespaces, plus option to ignore certain lines when comparing configs

Signed-off-by: Piotr Bajorek <pibajore@cisco.com>

* Added arg description in docstrings

* Bump version

---------

Signed-off-by: Piotr Bajorek <pibajore@cisco.com>
  • Loading branch information
pibajore authored Aug 23, 2024
1 parent d195980 commit a2cbb67
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions catalystwan/api/templates/cli_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -126,6 +126,7 @@ def compare_template(
second: CiscoConfParse,
full: bool = False,
debug: bool = False,
ignored_lines: List[str] = [],
) -> str:
"""
Expand All @@ -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.
Expand Down Expand Up @@ -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 ["?", "-", "+"]]
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <kagorski@cisco.com>"]
readme = "README.md"
Expand Down

0 comments on commit a2cbb67

Please sign in to comment.