[PR #18680] [MERGED] 18896 Replace STORAGE_BACKEND with STORAGES and support Script running from S3 #15410

Closed
opened 2025-12-30 00:21:46 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/18680
Author: @arthanson
Created: 2/19/2025
Status: Merged
Merged: 3/17/2025
Merged by: @arthanson

Base: featureHead: 18423-django-storages


📝 Commits (10+)

  • 289dcff 18423 scripts upload to django-storages
  • 78ae2fd Merge branch 'feature' into 18423-django-storages
  • d832314 18423 scripts upload to django-storages
  • 3f63e03 18423 source view
  • dad7637 18423 source view
  • 69fcdd2 18423 source view
  • 3ade819 18423 scripts root update
  • 099242e 18423 fix load_yaml / load_json
  • 45e2a93 18423 update docs
  • 65e6e3c Merge branch 'feature' into 18423-django-storages

📊 Changes

14 files changed (+247 additions, -78 deletions)

View changed files

📝 base_requirements.txt (+4 -0)
📝 docs/administration/replicating-netbox.md (+1 -1)
📝 docs/configuration/system.md (+32 -9)
📝 docs/customization/custom-scripts.md (+2 -0)
📝 docs/installation/3-netbox.md (+1 -1)
📝 netbox/core/models/data.py (+0 -11)
📝 netbox/core/models/files.py (+30 -6)
📝 netbox/extras/forms/scripts.py (+30 -0)
📝 netbox/extras/models/mixins.py (+33 -3)
📝 netbox/extras/scripts.py (+50 -2)
netbox/extras/storage.py (+14 -0)
📝 netbox/extras/views.py (+1 -2)
📝 netbox/netbox/settings.py (+48 -43)
📝 requirements.txt (+1 -0)

📄 Description

Fixes: #18896 (and #18423)

This Allows scripts to be run from S3 as well as config changes to allow for setting it. The changes are in two basic parts - the Script Form is changed to upload files using Django-storages (either FileSystem or S3) and the Script module loader is changed to pull from Django-storages.

  • Django-storages is now a requirement
  • STORAGE_BACKEND is now deprecated
  • STORAGES is now set directly as a config option
  • write_to_disk was moved from DataFile to ManagedFile as it is only ever used there or in classes derived from it.
  • The changes in BaseScript find_source is a replacement for the inspect module to actually find and load the modules.
  • extras.storage.ScriptFileSystemStorage is required for backwards compatibility with SCRIPTS_ROOT setting as otherwise with normal FileSystemStorage it will cause a path permission error going outside media root.

Note: the Script convenience methods load_yaml and load_json are not compatible when using S3 as they go direct to the local file system and are based on the path of the Script so wouldn't be backwards compatible. They are convenience functions so the script author could write them directly.

RELEASE_NOTES should probably have a section about replacing STORAGE_BACKEND and STORAGE_CONFIG with STORAGES for those updating from a previous version.


🔄 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/18680 **Author:** [@arthanson](https://github.com/arthanson) **Created:** 2/19/2025 **Status:** ✅ Merged **Merged:** 3/17/2025 **Merged by:** [@arthanson](https://github.com/arthanson) **Base:** `feature` ← **Head:** `18423-django-storages` --- ### 📝 Commits (10+) - [`289dcff`](https://github.com/netbox-community/netbox/commit/289dcffb95e9eee815664b85e86edbf5062e1d17) 18423 scripts upload to django-storages - [`78ae2fd`](https://github.com/netbox-community/netbox/commit/78ae2fdc2aaeea19df3a40640ccbc643acb3d398) Merge branch 'feature' into 18423-django-storages - [`d832314`](https://github.com/netbox-community/netbox/commit/d832314c295dd721a6780aeec15083382a3940c8) 18423 scripts upload to django-storages - [`3f63e03`](https://github.com/netbox-community/netbox/commit/3f63e0331c5122fe499c6f1f32e1d8fe0d5cf177) 18423 source view - [`dad7637`](https://github.com/netbox-community/netbox/commit/dad7637c8f696bae09ae72ee4aeeec9e02fcdb7e) 18423 source view - [`69fcdd2`](https://github.com/netbox-community/netbox/commit/69fcdd23b3492f694cbd5b389f350b204a05452a) 18423 source view - [`3ade819`](https://github.com/netbox-community/netbox/commit/3ade819706fdc24c3da73b0eeec72fa5cf217f83) 18423 scripts root update - [`099242e`](https://github.com/netbox-community/netbox/commit/099242e8218e527250d8b47bf74301f17ad17439) 18423 fix load_yaml / load_json - [`45e2a93`](https://github.com/netbox-community/netbox/commit/45e2a93e7386fc55288e4f9627f3c017863daed1) 18423 update docs - [`65e6e3c`](https://github.com/netbox-community/netbox/commit/65e6e3c87ae222599904adf3779f63c0593dc213) Merge branch 'feature' into 18423-django-storages ### 📊 Changes **14 files changed** (+247 additions, -78 deletions) <details> <summary>View changed files</summary> 📝 `base_requirements.txt` (+4 -0) 📝 `docs/administration/replicating-netbox.md` (+1 -1) 📝 `docs/configuration/system.md` (+32 -9) 📝 `docs/customization/custom-scripts.md` (+2 -0) 📝 `docs/installation/3-netbox.md` (+1 -1) 📝 `netbox/core/models/data.py` (+0 -11) 📝 `netbox/core/models/files.py` (+30 -6) 📝 `netbox/extras/forms/scripts.py` (+30 -0) 📝 `netbox/extras/models/mixins.py` (+33 -3) 📝 `netbox/extras/scripts.py` (+50 -2) ➕ `netbox/extras/storage.py` (+14 -0) 📝 `netbox/extras/views.py` (+1 -2) 📝 `netbox/netbox/settings.py` (+48 -43) 📝 `requirements.txt` (+1 -0) </details> ### 📄 Description ### Fixes: #18896 (and #18423) This Allows scripts to be run from S3 as well as config changes to allow for setting it. The changes are in two basic parts - the Script Form is changed to upload files using Django-storages (either FileSystem or S3) and the Script module loader is changed to pull from Django-storages. * Django-storages is now a requirement * STORAGE_BACKEND is now deprecated * STORAGES is now set directly as a config option * write_to_disk was moved from DataFile to ManagedFile as it is only ever used there or in classes derived from it. * The changes in BaseScript find_source is a replacement for the inspect module to actually find and load the modules. * extras.storage.ScriptFileSystemStorage is required for backwards compatibility with SCRIPTS_ROOT setting as otherwise with normal FileSystemStorage it will cause a path permission error going outside media root. **Note:** the Script convenience methods `load_yaml` and `load_json` are not compatible when using S3 as they go direct to the local file system and are based on the path of the Script so wouldn't be backwards compatible. They are convenience functions so the script author could write them directly. RELEASE_NOTES should probably have a section about replacing STORAGE_BACKEND and STORAGE_CONFIG with STORAGES for those updating from a previous version. --- <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-30 00:21:46 +01:00
adam closed this issue 2025-12-30 00:21:46 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15410