Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 2.8.0 #89

Merged
merged 34 commits into from
Nov 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b1032be
Change URLs in Usage to docs
miaow2 Nov 14, 2023
d70debc
Update project description
miaow2 Dec 12, 2023
04476cd
Add video presentation
miaow2 Dec 12, 2023
f83d730
Closes #50: Add template field to ConfigDiffScript (#51)
miaow2 Jan 27, 2024
63dd590
Closes #47: Move plugin to separete menu item in navbar (#52)
miaow2 Jan 28, 2024
5dd31cf
Closes #53: Add netbox-rq to installation process docs
miaow2 Jan 31, 2024
79c3ec3
Changelog for 2.2.0 version
miaow2 Feb 6, 2024
a757ac7
Handle junipers templates with set commands (#58)
miaow2 Apr 9, 2024
cd091be
Reverse columns in diff (#59)
miaow2 Apr 9, 2024
bbf8293
Add python 3.12 and Netbox 3.7.5 in CI
miaow2 Apr 10, 2024
afaafd5
Closes #56: Add python 3.12 and Netbox 3.7.5 in CI
miaow2 Apr 10, 2024
834e88e
Add warning about using set commands in Juniper
miaow2 Apr 11, 2024
1ca2303
Version 2.3.0
miaow2 Apr 11, 2024
21704dd
Merge branch 'main' into develop
miaow2 Apr 11, 2024
7d52fa3
Closes #63: Add patch commands for configuration
miaow2 May 12, 2024
63fc61b
Merge branch 'main' into develop
miaow2 May 12, 2024
487dbfa
Version 2.4.0
miaow2 May 12, 2024
d3672ec
Closes #67: Add option default_desired_privilege_level (#68)
cknost Jun 22, 2024
5dee473
Add docs for desired privilege level variables
miaow2 Jun 22, 2024
0980a05
Closes #69: Fix logger in SecretsMixin (#71)
miaow2 Jun 22, 2024
b52db25
Closes #70: Add escapejs filter to diff template (#72)
miaow2 Jun 30, 2024
d5a6d99
Version 2.5.0
miaow2 Jun 30, 2024
2234cc7
Merge branch 'main' into develop
miaow2 Jun 30, 2024
a0240d9
Closes #62: Add support for NetBox 4.0 (#74)
miaow2 Jul 14, 2024
5c3c92d
Update changelog
miaow2 Jul 14, 2024
3439c25
Merge branch 'main' into develop
miaow2 Jul 14, 2024
0829518
Closes #79: support for NetBox 4.1 (#80)
miaow2 Sep 29, 2024
167e5e6
Merge branch 'main' into develop
miaow2 Sep 29, 2024
9012a14
Fix ruff
miaow2 Sep 29, 2024
a57aead
Add diff statistics calculation and display in compliance view templa…
miaow2 Nov 9, 2024
6cdf1eb
Closes #84: Strip a lot of newlines in configs (#85)
miaow2 Nov 9, 2024
86c5d9a
Closes #81: Handle exceptions when calculating missing/extra commands…
miaow2 Nov 9, 2024
2c03cc2
Version 2.8.0
miaow2 Nov 10, 2024
edecabc
Merge branch 'main' into develop
miaow2 Nov 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Changelog


## 2.8.0 (2024-11-10)

* [#76](https://github.com/miaow2/netbox-config-diff/issues/76) Add in NetBox 4.0 and higher some statistics for diff
* [#81](https://github.com/miaow2/netbox-config-diff/issues/81) Fix error in rendering config with several substitutes
* [#84](https://github.com/miaow2/netbox-config-diff/issues/84) Strip multiple empty lines in configs

## 2.7.0 (2024-09-29)

* [#79](https://github.com/miaow2/netbox-config-diff/issues/79) Add support for NetBox 4.1

This release drops support for NetBox 3.6.

## 2.6.0 (2024-07-14)

* [#62](https://github.com/miaow2/netbox-config-diff/issues/62) Add support for NetBox 4.0
Expand Down
3 changes: 3 additions & 0 deletions docs/colliecting-diffs.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ If you have configs in NetBox DataSource, you can define it, the script instead
!!! note
Only synced DataSources are acceptable

!!! note
Diff replaces sequences of 3 or more empty lines with one empty line

If in your DataSource config names are different from the hostnames of the devices, you can specify config name with Jinja2 template in `Name template` field.
Reference device with `{{ object }}` variable.

Expand Down
2 changes: 1 addition & 1 deletion netbox_config_diff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

__author__ = "Artem Kotik"
__email__ = "[email protected]"
__version__ = "2.7.0"
__version__ = "2.8.0"


class ConfigDiffConfig(PluginConfig):
Expand Down
17 changes: 15 additions & 2 deletions netbox_config_diff/compliance/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def __init__(self, choices, *args, **kwargs):

def get_unified_diff(rendered_config: str, actual_config: str, device: str) -> str:
diff = unified_diff(
actual_config.splitlines(),
rendered_config.strip().splitlines(),
re.sub("\n{3,}", "\n", actual_config).splitlines(),
re.sub("\n{3,}", "\n", rendered_config).strip().splitlines(),
fromfiledate=device,
tofiledate=device,
lineterm="",
Expand All @@ -60,3 +60,16 @@ def get_remediation_commands(name: str, platform: str, actual_config: str, rende
host.load_running_config(config_text=actual_config)
host.load_generated_config(config_text=rendered_config)
return host.remediation_config_filtered_text(include_tags={}, exclude_tags={})


def get_diff_statistics(diff: str) -> tuple[int, int]:
lines_added = 0
lines_deleted = 0

for line in diff.splitlines():
if line.startswith("+") and not line.startswith("+++"):
lines_added += 1
elif line.startswith("-") and not line.startswith("---"):
lines_deleted += 1

return lines_added, lines_deleted
15 changes: 9 additions & 6 deletions netbox_config_diff/configurator/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,15 @@ async def _collect_one_diff(self, device: ConfiguratorDeviceDataClass) -> None:

device.diff = get_unified_diff(device.rendered_config, device.actual_config, device.name)
self.logger.add_diff(device.name, diff=device.diff)
device.missing = diff_network_config(
device.rendered_config, device.actual_config, PLATFORM_MAPPING[device.platform]
)
device.extra = diff_network_config(
device.actual_config, device.rendered_config, PLATFORM_MAPPING[device.platform]
)
try:
device.missing = diff_network_config(
device.rendered_config, device.actual_config, PLATFORM_MAPPING[device.platform]
)
device.extra = diff_network_config(
device.actual_config, device.rendered_config, PLATFORM_MAPPING[device.platform]
)
except Exception as e:
self.logger.log_warning(f"Unable to get missing/extra commands for {device.name}: {e}")
device.patch = get_remediation_commands(
device.name, device.platform, device.actual_config, device.rendered_config
)
Expand Down
6 changes: 3 additions & 3 deletions netbox_config_diff/configurator/platforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ def _render_substituted_config(

replace_sections = [(name, re.search(pattern=pattern, string=source_config)) for name, pattern in substitutes]

rendered_config = ""
rendered_config = config_template
for name, replace_section in replace_sections:
if not replace_section:
msg = f"substitution pattern {name} was unable to find a match in the target config" " source"
msg = f"substitution pattern {name} was unable to find a match in the target configsource"
self.logger.critical(msg)
raise TemplateError(msg)

replace_group = replace_section.group()
rendered_config = config_template.replace(f"{{{{ {name} }}}}", replace_group)
rendered_config = rendered_config.replace(f"{{{{ {name} }}}}", replace_group)

# remove any totally empty lines (from bad regex, or just device spitting out lines w/
# nothing on it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ <h5 class="card-header">Error</h5>
<div class="row mb-3">
<div class="col col-md-12">
<div class="card">
<h5 class="card-header">Diff</h5>
<h2 class="card-header">Diff
{% if version|first != "3" and statistics %}
<div class="card-actions">
<span style="color: #1a7f37;">{{ statistics.0 }}</span> line(s) missing,
<span style="color: #d1242f;">{{ statistics.1 }}</span> extra line(s)
</div>
{% endif %}
</h2>
<div class="card-body" id="diffElement"></div>
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions netbox_config_diff/views/compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from netbox.views import generic
from utilities.views import ViewTab, register_model_view

from netbox_config_diff.compliance.utils import get_diff_statistics
from netbox_config_diff.filtersets import ConfigComplianceFilterSet, PlatformSettingFilterSet
from netbox_config_diff.forms import (
ConfigComplianceFilterForm,
Expand All @@ -25,10 +26,14 @@ class ConfigComplianceView(generic.ObjectView):
template_name = "netbox_config_diff/configcompliance/data.html"

def get_extra_context(self, request, instance):
statistics = None
if instance.diff:
statistics = get_diff_statistics(instance.diff)
return {
"instance": instance,
"base_template": self.base_template,
"version": VERSION,
"statistics": statistics,
}


Expand Down
Loading