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

16145 Use module.ScriptName to call Script API instead of PK #16170

Merged
merged 5 commits into from
May 22, 2024

Conversation

arthanson
Copy link
Collaborator

@arthanson arthanson commented May 16, 2024

Fixes: #16145

Changes the script api back to using the "module.ScriptName" instead of id (this is the way it was in NB3.x). The test was a bit of a mess to fix, the issue is the get_vars function in the Script class calls the python_class property which calls module_scripts on on the module - this tries to load the module which fails as the script doesn't actually exist on disk.

curl -X 'GET' \
  'http://localhost:8000/api/extras/scripts/testscript.NewBranchScript/' \
  -H 'accept: application/json; indent=4' \
  -H 'Content-Type: application/json' \
  -H "Authorization: Token 6f22af1129a164f92e4abdfa716cb54df9684f5e"

{
    "id": 3,
    "url": "http://localhost:8000/api/extras/scripts/3/",
    "module": 7,
    "name": "NewBranchScript",
    "description": "Provision a new branch site",
    "vars": {
        "site_name": "StringVar",
        "switch_count": "IntegerVar",
        "switch_model": "ObjectVar",
        "manufacturer": "ObjectVar"
    },
    "result": {
        "object_id": null,
        "name": "",
        "scheduled": null,
        "interval": null,
        "started": null,
        "completed": null,
        "data": null,
        "job_id": null
    },
    "display": "NewBranchScript (testscript)",
    "is_executable": true
}

@arthanson arthanson changed the title DRAFT: 16145 script 16145 Use module.ScriptName to call Script API instead of PK May 16, 2024
@arthanson arthanson marked this pull request as ready for review May 16, 2024 22:34
Copy link
Member

@jeremystretch jeremystretch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we retain the numeric PK form of the URL as well, as an alternative? That would be more consistent with the manner by which other objects in NetBox are referenced.

@jeremystretch
Copy link
Member

Thanks @arthanson!

@jeremystretch jeremystretch merged commit 8e44668 into develop May 22, 2024
6 checks passed
@jeremystretch jeremystretch deleted the 16145-script branch May 22, 2024 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4.0.2 scripts can only be launched by api with ID and no longer with a name.
2 participants