Skip to content

Commit

Permalink
first round of fixes (#581)
Browse files Browse the repository at this point in the history
Co-authored-by: Ken Celenza <[email protected]>
  • Loading branch information
jeffkala and itdependsnetworks authored Sep 13, 2023
1 parent 71dc3e5 commit f64009d
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
5 changes: 3 additions & 2 deletions nautobot_golden_config/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from nautobot.extras.models import DynamicGroup, GitRepository, JobResult, Status, Tag
from nautobot.tenancy.models import Tenant, TenantGroup
from nautobot.utilities.forms import add_blank_choice, DatePicker, SlugField, TagFilterField

from nautobot_golden_config import models
from nautobot_golden_config.choices import ComplianceRuleConfigTypeChoice, ConfigPlanTypeChoice, RemediationTypeChoice

Expand Down Expand Up @@ -513,7 +514,7 @@ class ConfigPlanUpdateForm(NautobotModelForm):
queryset=Status.objects.all(),
query_params={"content_types": models.ConfigPlan._meta.label_lower},
)
tag = utilities_forms.DynamicModelMultipleChoiceField(
tags = utilities_forms.DynamicModelMultipleChoiceField(
queryset=Tag.objects.all(), query_params={"content_types": "dcim.device"}, required=False
)

Expand All @@ -525,7 +526,7 @@ class Meta:
"change_control_id",
"change_control_url",
"status",
"tag",
"tags",
)


Expand Down
21 changes: 13 additions & 8 deletions nautobot_golden_config/nornir_plays/config_deployment.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""Nornir job for deploying configurations."""
from datetime import datetime

from nautobot.dcim.models import Device
from nautobot.extras.models import Status
from nautobot_plugin_nornir.plugins.inventory.nautobot_orm import NautobotORMInventory
from nautobot_plugin_nornir.constants import NORNIR_SETTINGS
from nautobot_plugin_nornir.plugins.inventory.nautobot_orm import NautobotORMInventory
from nautobot_plugin_nornir.utils import get_dispatcher
from nornir import InitNornir
from nornir.core.task import Result, Task
from nornir.core.plugins.inventory import InventoryPluginRegister
from nornir.core.task import Result, Task
from nornir_nautobot.plugins.tasks.dispatcher import dispatcher
from nornir_nautobot.utils.logger import NornirLogger

Expand All @@ -26,7 +27,7 @@ def run_deployment(task: Task, logger: NornirLogger, commit: bool, config_plan_q
# after https://github.com/nautobot/nautobot-plugin-golden-config/issues/443

if commit:
obj.update(status=Status.objects.get(slug="in-progress"))
plans_to_deploy.update(status=Status.objects.get(slug="in-progress"))
result = task.run(
task=dispatcher,
name="DEPLOY CONFIG TO DEVICE",
Expand All @@ -36,12 +37,16 @@ def run_deployment(task: Task, logger: NornirLogger, commit: bool, config_plan_q
config=consolidated_config_set,
default_drivers_mapping=get_dispatcher(),
)[1].result["result"]
if not result.failed:
logger.log_success(obj=obj, message="Successfully deployed configuration to device.")
obj.update(status=Status.objects.get(slug="completed"))
if not result:
plans_to_deploy.update(status=Status.objects.get(slug="failed"))
logger.log_failure(obj=obj, message="No Nornir Result was Returned.")
else:
obj.update(status=Status.objects.get(slug="failed"))
logger.log_failure(obj=obj, message="Failed deployment to the device.")
if not result.failed:
logger.log_success(obj=obj, message="Successfully deployed configuration to device.")
plans_to_deploy.update(status=Status.objects.get(slug="completed"))
else:
plans_to_deploy.update(status=Status.objects.get(slug="failed"))
logger.log_failure(obj=obj, message="Failed deployment to the device.")
else:
result = None
logger.log_info(obj=obj, message="Commit not enabled. Configuration not deployed to device.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
{% endblock %}

{% block buttons %}
{% include "nautobot_golden_config/job_result_modal.html" %}
{% include "nautobot_golden_config/job_result_modal.html" with modal_title="Generate Config Plans" %}

<a href="#" class="openBtn" data-toggle="modal" data-target="#modalPopup" data-backdrop="static">
<button type="button" id="startJob" class="btn btn-primary">Generate</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@

<!-- Deploy Button -->
{% if perms.extras.run_job %}
{% include "nautobot_golden_config/job_result_modal.html" %}
{% include "nautobot_golden_config/job_result_modal.html" with modal_title="Deploy Config Plans" %}
<button id="startJob" type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#modalPopup">
<span class="mdi mdi-upload-multiple" aria-hidden="true"></span> Deploy Selected
<span class="mdi mdi-upload-multiple" aria-hidden="true"></span> Deploy Selected
</button>
{% endif %}

{% endblock %}

{% block javascript %}
{{ block.super }}
<script src="{% static 'toggle_fields.js' %}"></script>
<script src="{% static 'run_job.js' %}"></script>
<script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{% render_field form.change_control_id %}
{% render_field form.change_control_url %}
{% render_field form.status %}
{% render_field form.tag %}
{% render_field form.tags %}
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h3 class="modal-title">Generating Config Plans</h3>
<h3 class="modal-title">{{ modal_title }}</h3>
</div>

<!-- Modal body -->
Expand Down

0 comments on commit f64009d

Please sign in to comment.