-
Notifications
You must be signed in to change notification settings - Fork 71
Dynamic Remediation Functions and Mapping to override default hier_config #770
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
Open
sdoiron0330
wants to merge
7
commits into
nautobot:develop
Choose a base branch
from
sdoiron0330:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d954e5b
dynamic remediation functions and mappings
sdoiron0330 3a0be06
Merge branch 'nautobot:develop' into develop
sdoiron0330 f869e8e
fix migration file
sdoiron0330 97b3b7b
Merge branch 'develop' of github.com:sdoiron0330/nautobot-app-golden-…
sdoiron0330 fa9b10e
remove model, add dynamic hierconfig as option for remediation settings
sdoiron0330 9b6b30c
remove newline
sdoiron0330 7ebd084
added docs about dynamic remediation
sdoiron0330 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,12 @@ | |
| from nautobot.tenancy.models import Tenant, TenantGroup | ||
|
|
||
| from nautobot_golden_config import models | ||
| from nautobot_golden_config.choices import ComplianceRuleConfigTypeChoice, ConfigPlanTypeChoice, RemediationTypeChoice | ||
| from nautobot_golden_config.choices import ( | ||
| ComplianceRuleConfigTypeChoice, | ||
| ConfigPlanTypeChoice, | ||
| RemediationTypeChoice, | ||
| DynamicRemediationExpressionChoice, | ||
| ) | ||
|
|
||
| # ConfigCompliance | ||
|
|
||
|
|
@@ -644,3 +649,54 @@ class Meta: | |
| "change_control_url", | ||
| "tags", | ||
| ] | ||
|
|
||
|
|
||
| class DynamicRemediationMappingForm(NautobotModelForm): | ||
| """Form for ConfigPlan instances.""" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fix the docstring. |
||
|
|
||
| remediation_function = forms.DynamicModelChoiceField( | ||
| queryset=models.DynamicRemediationFunction.objects.all(), | ||
| ) | ||
| platform = forms.DynamicModelChoiceField(queryset=Platform.objects.all()) | ||
|
|
||
| class Meta: | ||
| """Boilerplate form Meta data for ConfigPlan.""" | ||
|
|
||
| model = models.DynamicRemediationMapping | ||
| fields = ("expression_choice", "config_string", "remediation_function", "platform", "enabled") | ||
|
|
||
|
|
||
| class DynamicRemediationMappingBulkEditForm(NautobotBulkEditForm): | ||
| """BulkEdit form for DynamicRemediationMapping instances.""" | ||
|
|
||
| pk = django_forms.ModelMultipleChoiceField( | ||
| queryset=models.DynamicRemediationMapping.objects.all(), widget=django_forms.MultipleHiddenInput | ||
| ) | ||
|
|
||
| expression_choice = django_forms.ChoiceField( | ||
| choices=forms.add_blank_choice(DynamicRemediationExpressionChoice), | ||
| required=False, | ||
| widget=django_forms.Select(), | ||
| label="Plan Type", | ||
| ) | ||
|
|
||
| config_string = django_forms.CharField(required=False) | ||
|
|
||
| remediation_function = forms.DynamicModelChoiceField( | ||
| queryset=models.DynamicRemediationFunction.objects.all(), | ||
| required=False, | ||
| ) | ||
| platform = forms.DynamicModelChoiceField( | ||
| queryset=Platform.objects.all(), | ||
| required=False, | ||
| ) | ||
| enabled = django_forms.BooleanField(required=False) | ||
|
|
||
| field_order = ("expression_choice", "config_string", "remediation_function", "platform", "enabled", "note") | ||
|
|
||
| class Meta: | ||
| """Boilerplate form Meta data for DynamicRemediationMapping.""" | ||
|
|
||
| model = models.DynamicRemediationMapping | ||
|
|
||
| nullable_fields = [] | ||
120 changes: 120 additions & 0 deletions
120
nautobot_golden_config/migrations/0031_dynamicremediation.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| # Generated by Django 3.2.24 on 2024-06-10 14:23 | ||
|
|
||
| import django.core.serializers.json | ||
| from django.db import migrations, models | ||
| import django.db.models.deletion | ||
| import nautobot.core.models.fields | ||
| import nautobot.extras.models.mixins | ||
| import uuid | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("extras", "0099_remove_dangling_note_objects"), | ||
| ("nautobot_golden_config", "0030_alter_goldenconfig_device"), | ||
| ("dcim", "0052_fix_interface_redundancy_group_created"), | ||
| ("extras", "0103_add_db_indexes_to_object_change"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.CreateModel( | ||
| name="DynamicRemediationFunction", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.UUIDField( | ||
| default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True | ||
| ), | ||
| ), | ||
| ("created", models.DateTimeField(auto_now_add=True, null=True)), | ||
| ("last_updated", models.DateTimeField(auto_now=True, null=True)), | ||
| ( | ||
| "_custom_field_data", | ||
| models.JSONField(blank=True, default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder), | ||
| ), | ||
| ("file_name", models.CharField(max_length=200)), | ||
| ( | ||
| "dynamic_remediation_repository", | ||
| models.ForeignKey( | ||
| limit_choices_to={ | ||
| "provided_contents__contains": "nautobot_golden_config.hierconfigdynamicremedation" | ||
| }, | ||
| on_delete=django.db.models.deletion.PROTECT, | ||
| related_name="dynamic_remediation_repository", | ||
| to="extras.gitrepository", | ||
| ), | ||
| ), | ||
| ( | ||
| "tags", | ||
| nautobot.core.models.fields.TagsField( | ||
| help_text="A comma-separated list of tags.", | ||
| through="extras.TaggedItem", | ||
| to="extras.Tag", | ||
| verbose_name="Tags", | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "abstract": False, | ||
| "unique_together": {("file_name", "dynamic_remediation_repository")}, | ||
| }, | ||
| bases=( | ||
| models.Model, | ||
| nautobot.extras.models.mixins.DynamicGroupMixin, | ||
| nautobot.extras.models.mixins.NotesMixin, | ||
| ), | ||
| ), | ||
| migrations.CreateModel( | ||
| name="DynamicRemediationMapping", | ||
| fields=[ | ||
| ( | ||
| "id", | ||
| models.UUIDField( | ||
| default=uuid.uuid4, editable=False, primary_key=True, serialize=False, unique=True | ||
| ), | ||
| ), | ||
| ("created", models.DateTimeField(auto_now_add=True, null=True)), | ||
| ("last_updated", models.DateTimeField(auto_now=True, null=True)), | ||
| ( | ||
| "_custom_field_data", | ||
| models.JSONField(blank=True, default=dict, encoder=django.core.serializers.json.DjangoJSONEncoder), | ||
| ), | ||
| ("expression_choice", models.CharField(max_length=50)), | ||
| ("config_string", models.CharField(max_length=256)), | ||
| ("enabled", models.BooleanField(default=True)), | ||
| ( | ||
| "platform", | ||
| models.ForeignKey( | ||
| on_delete=django.db.models.deletion.CASCADE, | ||
| related_name="dynamic_remediation_mapping", | ||
| to="dcim.platform", | ||
| ), | ||
| ), | ||
| ( | ||
| "remediation_function", | ||
| models.ForeignKey( | ||
| on_delete=django.db.models.deletion.PROTECT, | ||
| to="nautobot_golden_config.dynamicremediationfunction", | ||
| ), | ||
| ), | ||
| ( | ||
| "tags", | ||
| nautobot.core.models.fields.TagsField( | ||
| help_text="A comma-separated list of tags.", | ||
| through="extras.TaggedItem", | ||
| to="extras.Tag", | ||
| verbose_name="Tags", | ||
| ), | ||
| ), | ||
| ], | ||
| options={ | ||
| "abstract": False, | ||
| "unique_together": {("expression_choice", "config_string", "remediation_function")}, | ||
| }, | ||
| bases=( | ||
| models.Model, | ||
| nautobot.extras.models.mixins.DynamicGroupMixin, | ||
| nautobot.extras.models.mixins.NotesMixin, | ||
| ), | ||
| ), | ||
| ] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked at the code, but this part makes sense, I think that this is mostly what needs to be updated, more specifically there shouldn't be a reason to create a new model here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be possible to have a similar solution :
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made some changes to remove the model and just load modules from the git repo when doing remediation; lmk what you think