Skip to content

Commit

Permalink
Merge pull request #133 from nautobot/develop
Browse files Browse the repository at this point in the history
Merge 0.9.7 into main
  • Loading branch information
itdependsnetworks authored Sep 24, 2021
2 parents 23ca89c + d0d9586 commit 5c5f051
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 54 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## v0.9.7 - 2021-09

### Fixed

- #130 SSH Sessions does not die with celery workers, by adding context manager #128
- #125 Update search filterset

### Added

- #126 Add more robust checking for platform
- #115 Update docs to be more clear on how to use config context
## v0.9.6 - 2021-09

### Fixed
Expand All @@ -17,6 +28,7 @@
- #105 Added structure data config compliance
- #119 Migrate to Github Actions
- #121 Moved to Celery for development environment
- Added Mysql to development environment

## v0.9.5 - 2021-07

Expand Down
8 changes: 6 additions & 2 deletions docs/navigating-sot-agg.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ PLUGINS_CONFIG["nautobot_golden_config"]["sot_agg_transposer"] = "nautobot_golde
```
The path described must be within the Python path of your worker. It is up to the operator to ensure that happens.

## Config Context
## Config Contexts

Outside of the scope of this document, but it is worth mentioning the power that configuration context's with integration to Git can provide in this
solution.
solution. This is important since config contexts can be used for arbitrary JSON serializable data structures. That is helpful to model configuration
that is not within Nautobot Core or within a Nautobot Plugin. A common use case is to model "global configuration" like data, such as NTP, DNS, SNMP, etc.
For more information, please refer to the Nautobot Core documentation on
[Config Contexts](https://nautobot.readthedocs.io/en/latest/additional-features/config-contexts/#configuration-contexts) and leveraging
[Git Data Sources](https://nautobot.readthedocs.io/en/stable/user-guides/git-data-source/#using-git-data-sources).

## Performance

Expand Down
2 changes: 1 addition & 1 deletion nautobot_golden_config/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Plugin declaration for nautobot_golden_config."""

__version__ = "0.9.6"
__version__ = "0.9.7"

from nautobot.extras.plugins import PluginConfig

Expand Down
21 changes: 20 additions & 1 deletion nautobot_golden_config/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,13 @@ class ComplianceFeatureFilter(CustomFieldModelFilterSet):
label="Search",
)

def search(self, queryset, name, value): # pylint: disable=unused-argument,no-self-use
"""Perform the filtered search."""
if not value.strip():
return queryset
qs_filter = Q(name__icontains=value)
return queryset.filter(qs_filter)

class Meta:
"""Boilerplate filter Meta data for compliance feature."""

Expand All @@ -342,11 +349,23 @@ class Meta:
class ComplianceRuleFilter(CustomFieldModelFilterSet):
"""Inherits Base Class CustomFieldModelFilterSet."""

q = django_filters.CharFilter(
method="search",
label="Search",
)

def search(self, queryset, name, value): # pylint: disable=unused-argument,no-self-use
"""Perform the filtered search."""
if not value.strip():
return queryset
qs_filter = Q(feature__name__icontains=value)
return queryset.filter(qs_filter)

class Meta:
"""Boilerplate filter Meta data for compliance rule."""

model = models.ComplianceRule
fields = ["platform", "feature"]
fields = ["q", "platform", "feature"]


class ConfigRemoveFilter(CustomFieldModelFilterSet):
Expand Down
4 changes: 3 additions & 1 deletion nautobot_golden_config/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ class ComplianceRuleFilterForm(utilities_forms.BootstrapMixin, extras_forms.Cust
"""Form for ComplianceRule instances."""

model = models.ComplianceRule

q = forms.CharField(required=False, label="Search")
platform = utilities_forms.DynamicModelMultipleChoiceField(queryset=Platform.objects.all(), required=False)
feature = utilities_forms.DynamicModelMultipleChoiceField(
queryset=models.ComplianceFeature.objects.all(), required=False
Expand Down Expand Up @@ -183,7 +185,7 @@ class ComplianceFeatureFilterForm(utilities_forms.BootstrapMixin, extras_forms.C
"""Form for ComplianceFeature instances."""

model = models.ComplianceFeature

q = forms.CharField(required=False, label="Search")
name = utilities_forms.DynamicModelChoiceField(queryset=models.ComplianceFeature.objects.all(), required=False)


Expand Down
34 changes: 18 additions & 16 deletions nautobot_golden_config/nornir_plays/config_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def config_backup(job_result, data, backup_root_folder):
replace_regex_dict[regex.platform.slug] = []
replace_regex_dict[regex.platform.slug].append({"replace": regex.replace, "regex": regex.regex})
try:
nornir_obj = InitNornir(
with InitNornir(
runner=NORNIR_SETTINGS.get("runner"),
logging={"enabled": False},
inventory={
Expand All @@ -120,21 +120,23 @@ def config_backup(job_result, data, backup_root_folder):
"defaults": {"now": now},
},
},
)
except NornirNautobotException as err:
) as nornir_obj:

nr_with_processors = nornir_obj.with_processors([ProcessGoldenConfig(logger)])

nr_with_processors.run(
task=run_backup,
name="BACKUP CONFIG",
logger=logger,
global_settings=global_settings,
remove_regex_dict=remove_regex_dict,
replace_regex_dict=replace_regex_dict,
backup_root_folder=backup_root_folder,
)
logger.log_debug("Completed configuration from devices.")

except Exception as err:
logger.log_failure(None, err)
raise NornirNautobotException()

nr_with_processors = nornir_obj.with_processors([ProcessGoldenConfig(logger)])

nr_with_processors.run(
task=run_backup,
name="BACKUP CONFIG",
logger=logger,
global_settings=global_settings,
remove_regex_dict=remove_regex_dict,
replace_regex_dict=replace_regex_dict,
backup_root_folder=backup_root_folder,
)
raise

logger.log_debug("Completed configuration from devices.")
32 changes: 17 additions & 15 deletions nautobot_golden_config/nornir_plays/config_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def config_compliance(job_result, data, backup_root_path, intended_root_folder):
global_settings = GoldenConfigSetting.objects.first()
verify_global_settings(logger, global_settings, ["backup_path_template", "intended_path_template"])
try:
nornir_obj = InitNornir(
with InitNornir(
runner=NORNIR_SETTINGS.get("runner"),
logging={"enabled": False},
inventory={
Expand All @@ -145,20 +145,22 @@ def config_compliance(job_result, data, backup_root_path, intended_root_folder):
"defaults": {"now": now},
},
},
)
except NornirNautobotException as err:
logger.log_failure(None, err)
raise NornirNautobotException()
) as nornir_obj:

nr_with_processors = nornir_obj.with_processors([ProcessGoldenConfig(logger)])
nr_with_processors.run(
task=run_compliance,
name="RENDER COMPLIANCE TASK GROUP",
logger=logger,
global_settings=global_settings,
backup_root_path=backup_root_path,
intended_root_folder=intended_root_folder,
rules=rules,
)
nr_with_processors = nornir_obj.with_processors([ProcessGoldenConfig(logger)])

nr_with_processors.run(
task=run_compliance,
name="RENDER COMPLIANCE TASK GROUP",
logger=logger,
global_settings=global_settings,
backup_root_path=backup_root_path,
intended_root_folder=intended_root_folder,
rules=rules,
)

except Exception as err:
logger.log_failure(None, err)
raise

logger.log_debug("Completed Compliance for devices.")
35 changes: 18 additions & 17 deletions nautobot_golden_config/nornir_plays/config_intended.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def config_intended(job_result, data, jinja_root_path, intended_root_folder):
global_settings = GoldenConfigSetting.objects.first()
verify_global_settings(logger, global_settings, ["jinja_path_template", "intended_path_template", "sot_agg_query"])
try:
nornir_obj = InitNornir(
with InitNornir(
runner=NORNIR_SETTINGS.get("runner"),
logging={"enabled": False},
inventory={
Expand All @@ -101,20 +101,21 @@ def config_intended(job_result, data, jinja_root_path, intended_root_folder):
"defaults": {"now": now},
},
},
)
except NornirNautobotException as err:
) as nornir_obj:

nr_with_processors = nornir_obj.with_processors([ProcessGoldenConfig(logger)])

# Run the Nornir Tasks
nr_with_processors.run(
task=run_template,
name="RENDER CONFIG",
logger=logger,
global_settings=global_settings,
job_result=job_result,
jinja_root_path=jinja_root_path,
intended_root_folder=intended_root_folder,
)

except Exception as err:
logger.log_failure(None, err)
raise NornirNautobotException()

nr_with_processors = nornir_obj.with_processors([ProcessGoldenConfig(logger)])

# Run the Nornir Tasks
nr_with_processors.run(
task=run_template,
name="RENDER CONFIG",
logger=logger,
global_settings=global_settings,
job_result=job_result,
jinja_root_path=jinja_root_path,
intended_root_folder=intended_root_folder,
)
raise
5 changes: 5 additions & 0 deletions nautobot_golden_config/utilities/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def get_job_filter(data=None):
query.update({"id": data["device"].values_list("pk", flat=True)})

base_qs = models.GoldenConfigSetting.objects.first().get_queryset()
if DeviceFilterSet(data=query, queryset=base_qs).qs.filter(platform__isnull=True).count() > 0:
raise NornirNautobotException(
f"The following device(s) {', '.join([device.name for device in DeviceFilterSet(data=query, queryset=base_qs).qs.filter(platform__isnull=True)])} have no platform defined. Platform is required."
)

return DeviceFilterSet(data=query, queryset=base_qs).qs


Expand Down
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 = "nautobot-golden-config"
version = "0.9.6"
version = "0.9.7"
description = "A plugin for configuration on nautobot"
authors = ["Network to Code, LLC", "<[email protected]>"]

Expand Down

0 comments on commit 5c5f051

Please sign in to comment.