Skip to content
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

14438 database representation of scripts #15061

Merged
merged 56 commits into from
Feb 23, 2024
Merged

Conversation

arthanson
Copy link
Collaborator

@arthanson arthanson commented Feb 6, 2024

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"

@arthanson arthanson changed the base branch from develop to feature February 6, 2024 18:45
@jeremystretch jeremystretch added this to the v4.0 milestone Feb 7, 2024
@renatoalmeidaoliveira
Copy link
Contributor

Maybe adding TagsMixin, ChangeLoggingMixin and JournalingMixin may give user some flexibility and better experience in the usage of Scripts models,
The TagsMixin may allow users to create granular constrais to Scripts Models allowing/restricting user from run/edit some Script
The ChangeLoggingMixin might be usefull when running the datasource sync because it may create changelogs when the script changes in the data source giving the user a better understanding of what is running
The JournalingMixin may allow users to track development or comunnicate with each other within the Script Model

netbox/extras/api/serializers.py Outdated Show resolved Hide resolved
netbox/extras/api/serializers.py Outdated Show resolved Hide resolved
netbox/extras/api/serializers.py Show resolved Hide resolved
netbox/extras/api/serializers.py Outdated Show resolved Hide resolved
netbox/extras/api/serializers.py Show resolved Hide resolved
netbox/extras/models/scripts.py Outdated Show resolved Hide resolved
netbox/extras/models/scripts.py Outdated Show resolved Hide resolved
netbox/extras/views.py Outdated Show resolved Hide resolved
netbox/extras/views.py Outdated Show resolved Hide resolved
netbox/extras/views.py Outdated Show resolved Hide resolved
@jeremystretch jeremystretch merged commit ca2ee43 into feature Feb 23, 2024
6 checks passed
@jeremystretch jeremystretch deleted the 14438-script-model branch February 23, 2024 13:27
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Maintain database representations of reports & scripts
3 participants