-
Notifications
You must be signed in to change notification settings - Fork 60
Hier Config V3 Upgrade #902
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
base: develop
Are you sure you want to change the base?
Changes from all commits
4f09319
8dfd774
901c153
c696674
2225b39
394a2ea
7e5b904
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Upgraded from hier_config v2.2.2 to v3.2.2, which is a breaking change from the hier_config side. The hier_config implementation was updated to reflect hier_config v3. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,8 @@ | |
from django.db import models | ||
from django.db.models.manager import BaseManager | ||
from django.utils.module_loading import import_string | ||
from hier_config import Host as HierConfigHost | ||
from hier_config import WorkflowRemediation, get_hconfig | ||
from hier_config.utils import hconfig_v2_os_v3_platform_mapper, load_hconfig_v2_options | ||
from nautobot.apps.models import RestrictedQuerySet | ||
from nautobot.apps.utils import render_jinja2 | ||
from nautobot.core.models.generics import PrimaryModel | ||
|
@@ -177,32 +178,39 @@ def _verify_get_custom_compliance_data(compliance_details): | |
|
||
def _get_hierconfig_remediation(obj): | ||
"""Returns the remediating config.""" | ||
hierconfig_os = obj.device.platform.network_driver_mappings["hier_config"] | ||
hierconfig_os = obj.device.platform.network_driver_mappings.get("hier_config") | ||
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. While testing the hier config v3 update, I noticed that if the |
||
|
||
if not hierconfig_os: | ||
raise ValidationError(f"platform {obj.network_driver} is not supported by hierconfig.") | ||
raise ValidationError(f"platform {obj.device.platform.network_driver} is not supported by hierconfig.") | ||
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. While testing this function, I noticed that |
||
|
||
try: | ||
remediation_setting_obj = RemediationSetting.objects.get(platform=obj.rule.platform) | ||
except Exception as err: # pylint: disable=broad-except: | ||
raise ValidationError(f"Platform {obj.network_driver} has no Remediation Settings defined.") from err | ||
raise ValidationError( | ||
f"Platform {obj.device.platform.network_driver} has no Remediation Settings defined." | ||
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. While testing this function, I noticed that 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. RemediationSetting is set per Platform, so probably we don't need network_driver here 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. The network driver is specifically used to map to a hier config driver in netutils. |
||
) from err | ||
|
||
remediation_options = remediation_setting_obj.remediation_options | ||
|
||
try: | ||
hc_kwargs = {"hostname": obj.device.name, "os": hierconfig_os} | ||
hierconfig_os = hconfig_v2_os_v3_platform_mapper(hierconfig_os) | ||
|
||
if remediation_options: | ||
hc_kwargs.update(hconfig_options=remediation_options) | ||
host = HierConfigHost(**hc_kwargs) | ||
hierconfig_os = load_hconfig_v2_options(remediation_options, hierconfig_os) | ||
|
||
hierconfig_running_config = get_hconfig(hierconfig_os, obj.actual) | ||
hierconfig_intended_config = get_hconfig(hierconfig_os, obj.intended) | ||
hierconfig_wfr = WorkflowRemediation( | ||
hierconfig_running_config, | ||
hierconfig_intended_config, | ||
) | ||
|
||
except Exception as err: # pylint: disable=broad-except: | ||
raise Exception( # pylint: disable=broad-exception-raised | ||
f"Cannot instantiate HierConfig on {obj.device.name}, check Device, Platform and Hier Options." | ||
) from err | ||
|
||
host.load_generated_config(obj.intended) | ||
host.load_running_config(obj.actual) | ||
host.remediation_config() | ||
remediation_config = host.remediation_config_filtered_text(include_tags={}, exclude_tags={}) | ||
remediation_config = hierconfig_wfr.remediation_config_filtered_text(include_tags={}, exclude_tags={}) | ||
|
||
return remediation_config | ||
|
||
|
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.
Would be great to document and standardize and document inputs in this method