option to hide script classes from being visible #8634

Closed
opened 2025-12-29 20:39:08 +01:00 by adam · 7 comments
Owner

Originally created by @FliesLikeABrick on GitHub (Sep 18, 2023).

NetBox version

v3.6.1

Feature type

New functionality

Proposed functionality

We would like to add a way to hide certain script classes from the UI when they do not have user-facing functionality (no run method). There seem to be a few ways this could be implemented:

  • Hide scripts that do not contain a run() method. This check could potentially be added into is_script() so that scripts without a run() method are inherently hidden. That is, codify the fact that a script without a run() method is not actually a script.
  • Add an option to the script module similar to script_order that lists classes which should be suppressed (something like "script_hide=(MyScript)), then use that list in the creation of sxripts to exclude those scripts. Add a check like "if cls not in script_hide" to the logic that creates the list of scripts)
  • Add an option to the script module which says that "script_order" is an absolute/complete list, and those scripts not listed should not be visible. Right now, any script not listed in "script_order" is just appended to the end. Such an option perhaps would be a boolean script_display_unordered=True/False

Use case

We have a class hierarchy for our Netbox scripts, to abstract common functionality. We do not want our intermediate classes from the module(s) being visible in the UI, as those classes do not contain user functionality

Database changes

None

External dependencies

None

Originally created by @FliesLikeABrick on GitHub (Sep 18, 2023). ### NetBox version v3.6.1 ### Feature type New functionality ### Proposed functionality We would like to add a way to hide certain script classes from the UI when they do not have user-facing functionality (no run method). There seem to be a few ways this could be implemented: - Hide scripts that do not contain a run() method. This check could potentially be added into is_script() so that scripts without a run() method are inherently hidden. That is, codify the fact that a script without a run() method is not actually a script. - Add an option to the script module similar to script_order that lists classes which should be suppressed (something like "script_hide=(MyScript)), then use that list in the creation of sxripts to exclude those scripts. Add a check like "if cls not in script_hide" to the logic that creates the list of scripts) - Add an option to the script module which says that "script_order" is an absolute/complete list, and those scripts not listed should not be visible. Right now, any script not listed in "script_order" is just appended to the end. Such an option perhaps would be a boolean script_display_unordered=True/False ### Use case We have a class hierarchy for our Netbox scripts, to abstract common functionality. We do not want our intermediate classes from the module(s) being visible in the UI, as those classes do not contain user functionality ### Database changes None ### External dependencies None
adam added the type: feature label 2025-12-29 20:39:08 +01:00
adam closed this issue 2025-12-29 20:39:08 +01:00
Author
Owner

@FliesLikeABrick commented on GitHub (Sep 18, 2023):

I have a branch ready for a pull request, if this issue/request is accepted.

@FliesLikeABrick commented on GitHub (Sep 18, 2023): I have a branch ready for a pull request, if this issue/request is accepted.
Author
Owner

@FliesLikeABrick commented on GitHub (Jan 29, 2024):

Hello, it has been 5 months since this was reported and I have offered a code fix - is anyone available to triage this request or provide feedback on the solution offered? I am not sure why the last two comments were deleted.

@FliesLikeABrick commented on GitHub (Jan 29, 2024): Hello, it has been 5 months since this was reported and I have offered a code fix - is anyone available to triage this request or provide feedback on the solution offered? I am not sure why the last two comments were deleted.
Author
Owner

@jeremystretch commented on GitHub (Jan 29, 2024):

IIRC inheriting from BaseScript rather than Script prevents a class from being listed. @FliesLikeABrick have you tried that?

I'm going to mark this as blocked by #12510 for now as I want to avoid potential conflicts with work we're doing on the Script class for v4.0.

@jeremystretch commented on GitHub (Jan 29, 2024): IIRC inheriting from `BaseScript` rather than `Script` prevents a class from being listed. @FliesLikeABrick have you tried that? I'm going to mark this as blocked by #12510 for now as I want to avoid potential conflicts with work we're doing on the Script class for v4.0.
Author
Owner

@FliesLikeABrick commented on GitHub (Jan 29, 2024):

@jeremystretch thank you for the reply - we are inheriting from Script currently and our intermediate class is appearing in the UI alongside our two subclasses of it

class CNVRScript(Script):
image

@FliesLikeABrick commented on GitHub (Jan 29, 2024): @jeremystretch thank you for the reply - we are inheriting from `Script` currently and our intermediate class is appearing in the UI alongside our two subclasses of it `class CNVRScript(Script):` <img width="267" alt="image" src="https://github.com/netbox-community/netbox/assets/1180584/2cc6a9dd-566c-4e09-8497-645b055c8056">
Author
Owner

@arthanson commented on GitHub (Feb 28, 2024):

@FliesLikeABrick I've tested this, if your class inherits from BaseScript it won't show up:

class NewBranchScript(Script):
    ...

class NewBranchScript1(BaseScript):
    ...

In the case above NewBranchScript will show up but NewBranchScript1 will not.

@arthanson commented on GitHub (Feb 28, 2024): @FliesLikeABrick I've tested this, if your class inherits from BaseScript it won't show up: ``` class NewBranchScript(Script): ... class NewBranchScript1(BaseScript): ... ``` In the case above NewBranchScript will show up but NewBranchScript1 will not.
Author
Owner

@arthanson commented on GitHub (May 22, 2024):

Closing as can use BaseScript

@arthanson commented on GitHub (May 22, 2024): Closing as can use BaseScript
Author
Owner

@rizlas commented on GitHub (Jul 31, 2024):

Hi,
I have a case where an option to hide will be perfect. Inheriting from BaseScript is not possible because it would also make the script that inherits from the base class disappear.

I've opened a discussion with example here: https://github.com/netbox-community/netbox/discussions/17040

@rizlas commented on GitHub (Jul 31, 2024): Hi, I have a case where an option to hide will be perfect. Inheriting from BaseScript is not possible because it would also make the script that inherits from the base class disappear. I've opened a discussion with example here: https://github.com/netbox-community/netbox/discussions/17040
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8634