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

Netbox REST API reports faulty virtual device context url #12975

Closed
pertoft opened this issue Jun 23, 2023 · 1 comment
Closed

Netbox REST API reports faulty virtual device context url #12975

pertoft opened this issue Jun 23, 2023 · 1 comment
Assignees
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@pertoft
Copy link

pertoft commented Jun 23, 2023

NetBox version

v3.4.7

Python version

3.11

Steps to Reproduce

  1. Perform a GET request to get a virtual device context:
    curl -X 'GET' \ 'https://netboxtest.netic.dk/api/dcim/virtual-device-contexts/?id=9
    Response:
{
  "count": 1,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": 9,
      "url": "https://netboxtest.netic.dk/api/dcim/devices/9/",
      "display": "k7404",
      "name": "k7404",
      "device": {
        "id": 1508,
        "url": "https://netboxtest.netic.dk/api/dcim/devices/1508/",
        "display": "dc4-1-a7-fg01.inf.example.dk",
        "name": "dc4-1-a7-fg01.inf.example.dk"
      },
      "identifier": null,
      "tenant": {
        "id": 404,
        "url": "https://netboxtest.netic.dk/api/tenancy/tenants/404/",
        "display": "EXAMPLE",
        "name": "EXAMPLE",
        "slug": "example"
      },
      "primary_ip": null,
      "primary_ip4": null,
      "primary_ip6": null,
      "status": "active",
      "description": "",
      "comments": "",
      "tags": [],
      "custom_fields": {},
      "created": "2023-06-23T08:10:45.356064Z",
      "last_updated": "2023-06-23T08:10:45.356085Z",
      "interface_count": 0
    }
  ]
}

It seems to me that the "url" is wrong: "url": "https://netboxtest.netic.dk/api/dcim/devices/9/" as it points at a device, and not the virtual device context endpoint.

This causes a problem when I try to delete the virtual device context, because it tries to lookup the device, and not the vdc:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/runpy.py", line 198, in _run_module_as_main
    return _run_code(code, main_globals, None,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/runpy.py", line 88, in _run_code
    exec(code, run_globals)
  File "/Users/pto/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 39, in <module>
    cli.main()
  File "/Users/pto/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main
    run()
  File "/Users/pto/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "/Users/pto/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/pto/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/Users/pto/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "/Users/pto/source/network/fortigate_hosted_vdom/NeticNetbox.py", line 114, in <module>
    n.virtual_device_context_remove(vdc,firewall)
  File "/Users/pto/source/network/fortigate_hosted_vdom/NeticNetbox.py", line 66, in virtual_device_context_remove
    vdc.delete()
  File "/opt/homebrew/lib/python3.11/site-packages/pynetbox/core/response.py", line 614, in delete
    return True if req.delete() else False
                   ^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pynetbox/core/query.py", line 372, in delete
    return self._make_call(verb="delete", data=data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/pynetbox/core/query.py", line 240, in _make_call
    raise RequestError(req)
pynetbox.core.query.RequestError: The requested url: https://netboxtest.netic.dk/api/dcim/devices/9/ could not be found.

Expected Behavior

url should point at the virtual device context, and not at the device

Observed Behavior

url points at a dcim device

@pertoft pertoft added the type: bug A confirmed report of unexpected behavior in the application label Jun 23, 2023
@kkthxbye-code kkthxbye-code added the status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation label Jun 23, 2023
@kkthxbye-code
Copy link
Contributor

Seems like a copy-paste error, the url field just needs to be corrected.

url = serializers.HyperlinkedIdentityField(view_name='dcim-api:device-detail')

@jeremystretch jeremystretch added the severity: medium Results in substantial degraded or broken functionality for specfic workflows label Jun 23, 2023
@jeremystretch jeremystretch self-assigned this Jun 23, 2023
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Jun 23, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
severity: medium Results in substantial degraded or broken functionality for specfic workflows status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

3 participants