diff --git a/CHANGELOG.md b/CHANGELOG.md index 5263383d..d465cc34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## v1.0.3 - 2022-06 + +### Fixed + +- #257 Resolved template_content displaying SoT AGG link on Device detail page if Device not in scope of GoldenConfigSetting +- Change to pull version from package instead of static variable + ## v1.0.2 - 2022-05 ### Fixed diff --git a/README.md b/README.md index 518fc1a3..8dcc6f91 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ Nautobot Golden Config has currently no intended scheduled release schedule, and When a new release of any kind (e.g. from develop to main, or a release of a `stable-.`) is created the following should happen. - A release PR is created with: - Update to the CHANGELOG.md file to reflect the changes. - - Change the version from `..-beta` to `..` in both pyproject.toml and `nautobot.__init__.__version__`. + - Change the version from `..-beta` to `..` in pyproject.toml. - Set the PR to the proper branch, e.g. either `main` or `stable-.`. - Ensure the tests for the PR pass. - Merge the PR. diff --git a/nautobot_golden_config/__init__.py b/nautobot_golden_config/__init__.py index 0e694f11..96b62f73 100644 --- a/nautobot_golden_config/__init__.py +++ b/nautobot_golden_config/__init__.py @@ -1,6 +1,12 @@ """Plugin declaration for nautobot_golden_config.""" +# Metadata is inherited from Nautobot. If not including Nautobot in the environment, this should be added +try: + from importlib import metadata +except ImportError: + # Python version < 3.8 + import importlib_metadata as metadata -__version__ = "1.0.2" +__version__ = metadata.version(__name__) from nautobot.extras.plugins import PluginConfig diff --git a/nautobot_golden_config/template_content.py b/nautobot_golden_config/template_content.py index 7095af98..2ff5bf08 100644 --- a/nautobot_golden_config/template_content.py +++ b/nautobot_golden_config/template_content.py @@ -1,9 +1,11 @@ """Added content to the device model view for config compliance.""" from django.db.models import Count, Q +from nautobot.dcim.models import Device from nautobot.extras.plugins import PluginTemplateExtension from nautobot_golden_config.models import ConfigCompliance, GoldenConfig from nautobot_golden_config.utilities.constant import ENABLE_COMPLIANCE, CONFIG_FEATURES +from nautobot_golden_config.utilities.helper import get_device_to_settings_map class ConfigComplianceDeviceCheck(PluginTemplateExtension): # pylint: disable=abstract-method @@ -69,12 +71,15 @@ def get_device(self): def right_page(self): """Content to add to the configuration compliance.""" - golden_config = GoldenConfig.objects.filter(device=self.get_device()).first() + device = self.get_device() + golden_config = GoldenConfig.objects.filter(device=device).first() + settings = get_device_to_settings_map(queryset=Device.objects.filter(id=device.id)) extra_context = { "device": self.get_device(), # device, "golden_config": golden_config, "template_type": "device-configs", "config_features": CONFIG_FEATURES, + "matched_config_setting": settings.get(device.id, False), } return self.render( "nautobot_golden_config/content_template.html", diff --git a/nautobot_golden_config/templates/nautobot_golden_config/content_template.html b/nautobot_golden_config/templates/nautobot_golden_config/content_template.html index bfc41a5d..65b5d685 100644 --- a/nautobot_golden_config/templates/nautobot_golden_config/content_template.html +++ b/nautobot_golden_config/templates/nautobot_golden_config/content_template.html @@ -64,40 +64,42 @@ Config - - {% if config_features.compliance and golden_config.compliance_config %} - - Compliance - - - - + {% if matched_config_setting %} + + {% if config_features.compliance and golden_config.compliance_config %} + + Compliance + + + + + {% endif %} + {% if config_features.intended and golden_config.intended_config %} + + Intended + + + + + {% endif %} + {% if config_features.backup and golden_config.backup_config %} + + Actual + + + + + {% endif %} + {% if config_features.sotagg %} + + SoT Aggregation Data + + + + + {% endif %} + {% endif %} - {% if config_features.intended and golden_config.intended_config %} - - Intended - - - - - {% endif %} - {% if config_features.backup and golden_config.backup_config %} - - Actual - - - - - {% endif %} - {% if config_features.sotagg %} - - SoT Aggregation Data - - - - - {% endif %} - {% endif %} diff --git a/nautobot_golden_config/views.py b/nautobot_golden_config/views.py index 6ad3ed8b..5a4c22ca 100644 --- a/nautobot_golden_config/views.py +++ b/nautobot_golden_config/views.py @@ -11,6 +11,7 @@ import numpy as np import yaml from django.contrib import messages +from django.core.exceptions import ObjectDoesNotExist from django.db.models import Count, ExpressionWrapper, F, FloatField, Max, ProtectedError, Q from django.forms import ModelMultipleChoiceField, MultipleHiddenInput from django.shortcuts import redirect, render @@ -393,8 +394,11 @@ def diff_structured_data(backup_data, intended_data): if request.GET.get("format") in ["json", "yaml"]: structure_format = request.GET.get("format") - settings = get_device_to_settings_map(queryset=Device.objects.filter(pk=device.pk))[device.id] - _, output = graph_ql_query(request, device, settings.sot_agg_query.query) + settings = get_device_to_settings_map(queryset=Device.objects.filter(pk=device.pk)) + if device.id in settings: + _, output = graph_ql_query(request, device, settings[device.id].sot_agg_query.query) + else: + raise ObjectDoesNotExist(f"{device.name} does not map to a Golden Config Setting.") if structure_format == "yaml": output = yaml.dump(json.loads(json.dumps(output)), default_flow_style=False) diff --git a/pyproject.toml b/pyproject.toml index 603184a1..4b0eae23 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "nautobot-golden-config" -version = "1.0.2" +version = "1.0.3" description = "A plugin for configuration on nautobot" authors = ["Network to Code, LLC", ""]