[PR #15061] [MERGED] 14438 database representation of scripts #14511

Closed
opened 2025-12-29 23:24:54 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/15061
Author: @arthanson
Created: 2/6/2024
Status: Merged
Merged: 2/23/2024
Merged by: @jeremystretch

Base: featureHead: 14438-script-model


📝 Commits (10+)

📊 Changes

25 files changed (+568 additions, -335 deletions)

View changed files

📝 netbox/extras/api/serializers.py (+37 -65)
📝 netbox/extras/api/views.py (+13 -51)
📝 netbox/extras/events.py (+3 -5)
📝 netbox/extras/filtersets.py (+21 -0)
📝 netbox/extras/forms/bulk_import.py (+2 -5)
📝 netbox/extras/forms/model_forms.py (+12 -29)
netbox/extras/migrations/0109_script_model.py (+159 -0)
netbox/extras/migrations/0110_remove_eventrule_action_parameters.py (+15 -0)
📝 netbox/extras/models/models.py (+0 -4)
📝 netbox/extras/models/scripts.py (+93 -6)
📝 netbox/extras/reports.py (+1 -0)
📝 netbox/extras/scripts.py (+3 -4)
📝 netbox/extras/tests/test_api.py (+19 -10)
📝 netbox/extras/urls.py (+9 -4)
📝 netbox/extras/views.py (+61 -62)
📝 netbox/netbox/settings.py (+1 -0)
📝 netbox/templates/extras/eventrule.html (+0 -6)
📝 netbox/templates/extras/script.html (+12 -3)
📝 netbox/templates/extras/script/base.html (+4 -4)
📝 netbox/templates/extras/script/jobs.html (+13 -0)

...and 5 more files

📄 Description

Fixes: #14438

Adds database representation of scripts. There are several parts of this:

  • Adds the actual Script model
  • Update all jobs that point to the module.script to point to the new Script object and update associated code
  • Update all event rules that point to the module.script to point to the new Script object and update associated code

The action_parameter on EventRule is removed as it was only used to save the name of the script as the action_object pointed to the script module. It now points directly to the Script model. If the script named in the action_parameter no longer exists then a dummy Script object is created with is_valid=False.

API

The API was kept as compatible as possible, mostly adding in the new is_valid flag. As the old API was driven off of the module, it would only return scripts that were actually in the module. Now if a script is deleted in the code behind the covers we just mark the script as is_valid=False and it is up to the user to actually delete it, so now the API can return these 'ghost' objects.

The API also still allows referencing by the string 'module.script_name' for backwards compatibility, where the new one just uses id for the script object.

Also, as backwards compatibility was preferred - there are some updates that could be done to the API that would be more breaking changes to keep it more in-line with other APIs, but were not done. For example - the jobs could be returned on the Script object but wasn't as that would be breaking and it could introduce a lot of bloat to the returned data if there were a lot of previously run jobs for a script.

*Note: I had to make two migrations - if the remove event_rule.actions_parameters was done in the first migration it would error with "django.db.utils.OperationalError: cannot ALTER TABLE "extras_eventrule" because it has pending trigger events"


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/15061 **Author:** [@arthanson](https://github.com/arthanson) **Created:** 2/6/2024 **Status:** ✅ Merged **Merged:** 2/23/2024 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `feature` ← **Head:** `14438-script-model` --- ### 📝 Commits (10+) - [`1034ee7`](https://github.com/netbox-community/netbox/commit/1034ee7380647011304bfb53afbd9f27802f4a7e) 14438 script model - [`4cb3b63`](https://github.com/netbox-community/netbox/commit/4cb3b63f79ea9814bc4627bcad4f8be683591cca) 14438 script model - [`fc890e3`](https://github.com/netbox-community/netbox/commit/fc890e36afab0354b9918829bd323cfeddf8a0ce) 14438 script model - [`6930e44`](https://github.com/netbox-community/netbox/commit/6930e441ae7a0be01f1d7367e048c6393d461ebd) 14438 script job mapping - [`5981fc9`](https://github.com/netbox-community/netbox/commit/5981fc958dac30381c526240c6bdfb2320feb719) 14438 script job mapping - [`9543169`](https://github.com/netbox-community/netbox/commit/95431690253ee7cd98b0982aab3716c826c7ebb2) 14438 script job run - [`d162d44`](https://github.com/netbox-community/netbox/commit/d162d440b045b446545236ebd57de68ab0b6920b) 14438 fix migration - [`0bd15c3`](https://github.com/netbox-community/netbox/commit/0bd15c30ec23a103db52009ac10aa7f3da7572e8) 14438 merge feature - [`0c214d3`](https://github.com/netbox-community/netbox/commit/0c214d37b31118a042f96fe1671f26220f379efb) 14438 fix merge - [`41c792a`](https://github.com/netbox-community/netbox/commit/41c792a3e53bb172ad73d63ad14a7efc1a391657) 14438 fix merge ### 📊 Changes **25 files changed** (+568 additions, -335 deletions) <details> <summary>View changed files</summary> 📝 `netbox/extras/api/serializers.py` (+37 -65) 📝 `netbox/extras/api/views.py` (+13 -51) 📝 `netbox/extras/events.py` (+3 -5) 📝 `netbox/extras/filtersets.py` (+21 -0) 📝 `netbox/extras/forms/bulk_import.py` (+2 -5) 📝 `netbox/extras/forms/model_forms.py` (+12 -29) ➕ `netbox/extras/migrations/0109_script_model.py` (+159 -0) ➕ `netbox/extras/migrations/0110_remove_eventrule_action_parameters.py` (+15 -0) 📝 `netbox/extras/models/models.py` (+0 -4) 📝 `netbox/extras/models/scripts.py` (+93 -6) 📝 `netbox/extras/reports.py` (+1 -0) 📝 `netbox/extras/scripts.py` (+3 -4) 📝 `netbox/extras/tests/test_api.py` (+19 -10) 📝 `netbox/extras/urls.py` (+9 -4) 📝 `netbox/extras/views.py` (+61 -62) 📝 `netbox/netbox/settings.py` (+1 -0) 📝 `netbox/templates/extras/eventrule.html` (+0 -6) 📝 `netbox/templates/extras/script.html` (+12 -3) 📝 `netbox/templates/extras/script/base.html` (+4 -4) 📝 `netbox/templates/extras/script/jobs.html` (+13 -0) _...and 5 more files_ </details> ### 📄 Description ### Fixes: #14438 Adds database representation of scripts. There are several parts of this: * Adds the actual Script model * Update all jobs that point to the module.script to point to the new Script object and update associated code * Update all event rules that point to the module.script to point to the new Script object and update associated code The action_parameter on EventRule is removed as it was only used to save the name of the script as the action_object pointed to the script module. It now points directly to the Script model. If the script named in the action_parameter no longer exists then a dummy Script object is created with is_valid=False. ### API The API was kept as compatible as possible, mostly adding in the new is_valid flag. As the old API was driven off of the module, it would only return scripts that were actually in the module. Now if a script is deleted in the code behind the covers we just mark the script as is_valid=False and it is up to the user to actually delete it, so now the API can return these 'ghost' objects. The API also still allows referencing by the string 'module.script_name' for backwards compatibility, where the new one just uses id for the script object. Also, as backwards compatibility was preferred - there are some updates that could be done to the API that would be more breaking changes to keep it more in-line with other APIs, but were not done. For example - the jobs could be returned on the Script object but wasn't as that would be breaking and it could introduce a lot of bloat to the returned data if there were a lot of previously run jobs for a script. **Note:* I had to make two migrations - if the remove event_rule.actions_parameters was done in the first migration it would error with "django.db.utils.OperationalError: cannot ALTER TABLE "extras_eventrule" because it has pending trigger events" --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 23:24:54 +01:00
adam closed this issue 2025-12-29 23:24:54 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#14511