From f72e1ee061b5dd712cd86460e0f65df580753b63 Mon Sep 17 00:00:00 2001 From: Stephen Kiely Date: Wed, 11 Dec 2024 14:54:30 -0600 Subject: [PATCH 1/7] Add template to mark fields as required/not required --- nautobot_device_onboarding/jobs.py | 4 +- .../ssot_sync_devices.html | 75 +++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 nautobot_device_onboarding/templates/nautobot_device_onboarding/ssot_sync_devices.html diff --git a/nautobot_device_onboarding/jobs.py b/nautobot_device_onboarding/jobs.py index 6ed3b70f..3ffe2541 100755 --- a/nautobot_device_onboarding/jobs.py +++ b/nautobot_device_onboarding/jobs.py @@ -275,7 +275,7 @@ class Meta: csv_file = FileVar( label="CSV File", required=False, - description="If a file is provided all the options below will be ignored.", + description="If a file is provided, all the options in the manual input tab will be disabled.", ) location = ObjectVar( model=Location, @@ -337,6 +337,8 @@ class Meta: description="Device platform. Define ONLY to override auto-recognition of platform.", ) + template_name = "nautobot_device_onboarding/ssot_sync_devices.html" + def load_source_adapter(self): """Load onboarding network adapter.""" self.source_adapter = SyncDevicesNetworkAdapter(job=self, sync=self.sync) diff --git a/nautobot_device_onboarding/templates/nautobot_device_onboarding/ssot_sync_devices.html b/nautobot_device_onboarding/templates/nautobot_device_onboarding/ssot_sync_devices.html new file mode 100644 index 00000000..9f702bc8 --- /dev/null +++ b/nautobot_device_onboarding/templates/nautobot_device_onboarding/ssot_sync_devices.html @@ -0,0 +1,75 @@ +{% extends 'extras/job.html' %} +{% load form_helpers %} + +{% block job_form %} + +{% render_form job_form excluded_fields="['location', 'namespace', 'ip_addresses', 'device_role', 'device_status', 'interface_status', 'ip_address_status', 'port', 'timeout', 'secrets_group', 'platform', 'set_mgmt_only', 'update_devices_without_primary_ip', 'csv_file']" %} + + {% with csv_tab_active=form.initial.csv_input%} + +
+
+ {% render_field job_form.location %} + {% render_field job_form.namespace %} + {% render_field job_form.ip_addresses %} + {% render_field job_form.port %} + {% render_field job_form.timeout %} + {% render_field job_form.set_mgmt_only %} + {% render_field job_form.update_devices_without_primary_ip %} + {% render_field job_form.device_role %} + {% render_field job_form.device_status %} + {% render_field job_form.interface_status %} + {% render_field job_form.ip_address_status %} + {% render_field job_form.secrets_group %} + {% render_field job_form.platform %} +
+
+ {% render_field job_form.csv_file %} +
+
+ {% endwith %} + +{% endblock job_form %} + +{% block javascript %} + {{ block.super }} + +{% endblock javascript %} From 6d7223de011cf4c4496d893678fc43d2ce575a29 Mon Sep 17 00:00:00 2001 From: Stephen Kiely Date: Thu, 12 Dec 2024 08:08:47 -0600 Subject: [PATCH 2/7] Refactor javascript --- nautobot_device_onboarding/jobs.py | 23 --------- .../ssot_sync_devices.html | 48 ++++++++++--------- 2 files changed, 25 insertions(+), 46 deletions(-) diff --git a/nautobot_device_onboarding/jobs.py b/nautobot_device_onboarding/jobs.py index 3ffe2541..a14733bf 100755 --- a/nautobot_device_onboarding/jobs.py +++ b/nautobot_device_onboarding/jobs.py @@ -504,29 +504,6 @@ def run( raise ValidationError(message="CSV check failed. No devices will be synced.") else: - # Verify that all requried form inputs have been provided - required_inputs = { - "location": location, - "namespace": namespace, - "ip_addresses": ip_addresses, - "device_role": device_role, - "device_status": device_status, - "interface_status": interface_status, - "ip_address_status": ip_address_status, - "port": port, - "timeout": timeout, - "secrets_group": secrets_group, - } - - missing_required_inputs = [ - form_field for form_field, input_value in required_inputs.items() if not input_value - ] - if not missing_required_inputs: - pass - else: - self.logger.error(f"Missing requried inputs from job form: {missing_required_inputs}") - raise ValidationError(message=f"Missing required inputs {missing_required_inputs}") - self.location = location self.namespace = namespace self.ip_addresses = ip_addresses.replace(" ", "").split(",") diff --git a/nautobot_device_onboarding/templates/nautobot_device_onboarding/ssot_sync_devices.html b/nautobot_device_onboarding/templates/nautobot_device_onboarding/ssot_sync_devices.html index 9f702bc8..e87b2f81 100644 --- a/nautobot_device_onboarding/templates/nautobot_device_onboarding/ssot_sync_devices.html +++ b/nautobot_device_onboarding/templates/nautobot_device_onboarding/ssot_sync_devices.html @@ -42,33 +42,35 @@ {{ block.super }} From 5142dc62f4b3f5a571709931c57235c6969451d5 Mon Sep 17 00:00:00 2001 From: Stephen Kiely Date: Thu, 12 Dec 2024 08:16:39 -0600 Subject: [PATCH 3/7] Add change fragment --- changes/243.changed | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/243.changed diff --git a/changes/243.changed b/changes/243.changed new file mode 100644 index 00000000..3b9ae3d8 --- /dev/null +++ b/changes/243.changed @@ -0,0 +1 @@ +Sync Devices From Network job form now highlights required fields. From 63f1822ffc05a5cb98697fba84940b2132cbdc9a Mon Sep 17 00:00:00 2001 From: Stephen Kiely Date: Thu, 12 Dec 2024 08:22:07 -0600 Subject: [PATCH 4/7] Add the script type. --- .../templates/nautobot_device_onboarding/ssot_sync_devices.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nautobot_device_onboarding/templates/nautobot_device_onboarding/ssot_sync_devices.html b/nautobot_device_onboarding/templates/nautobot_device_onboarding/ssot_sync_devices.html index e87b2f81..768ae6ce 100644 --- a/nautobot_device_onboarding/templates/nautobot_device_onboarding/ssot_sync_devices.html +++ b/nautobot_device_onboarding/templates/nautobot_device_onboarding/ssot_sync_devices.html @@ -40,7 +40,7 @@ {% block javascript %} {{ block.super }} -