Merge branch 'develop' of github.com:8ctorres/netbox into develop

This commit is contained in:
8ctorres 2024-07-06 16:48:22 +02:00
commit fcef7c8eff

View File

@ -65,6 +65,18 @@ class AnotherCustomScript(Script):
script_order = (MyCustomScript, AnotherCustomScript) script_order = (MyCustomScript, AnotherCustomScript)
``` ```
The `run()` method is the entrypoint for the script, and it runs in the context of NetBox's own execution environment. This means from here, everything inside NetBox itself is accesible. The [NetBox Shell](../administration/netbox-shell.md) is a good resource to keep in hand, since it allows to see the objects in NetBox in the same way the script does.
The `run()` method can itself call other methods that are in the same module but outside the "MyCustomScript" class, and if there are several scripts in the same module (this is, in the same Python file), both scripts can reuse the same auxiliary methods, keeping the code cleaner. For this reason, it is encouraged to keep similar scripts in the same module. Script can return a string, which will be displayed in a text box in the web interface after the script finishes. This is useful, for instance, for returning a piece of configuration or information that you want the user to be able to easily copy and paste somewhere else.
## Module Attributes
### `name`
You can define `name` within a script module (the Python file which contains one or more scripts) to set the module name. If `name` is not defined, the module's file name will be used.
## Script Attributes ## Script Attributes
Script attributes are defined under a class named `Meta` within the script. These are optional, but encouraged. Script attributes are defined under a class named `Meta` within the script. These are optional, but encouraged.