[PR #9574] [MERGED] Closes #9396: Query modules by module bay & display installed_modules for module_bay REST API endpoint #13488

Closed
opened 2025-12-29 23:19:09 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/9574
Author: @huntabyte
Created: 6/21/2022
Status: Merged
Merged: 6/23/2022
Merged by: @jeremystretch

Base: developHead: feature-9396


📝 Commits (3)

  • 79b3bc6 Closes #9396 - Added ability to query modules by module bay & installed_modules for module bay REST API endpoint
  • 9d848a4 Closes #9396 - Added ability to query modules by module bay & installed_modules for module bay REST API endpoint
  • f7dad0e Closes #9396 - Added ability to query modules by module bay & installed_modules for module bay REST API endpoint

📊 Changes

5 files changed (+23 additions, -3 deletions)

View changed files

📝 netbox/dcim/api/nested_serializers.py (+9 -0)
📝 netbox/dcim/api/serializers.py (+2 -2)
📝 netbox/dcim/api/views.py (+1 -1)
📝 netbox/dcim/filtersets.py (+6 -0)
📝 netbox/dcim/tests/test_filtersets.py (+5 -0)

📄 Description

Fixes: #9396, #9597

Users can now query modules based on a given module bay id.

GET /api/dcim/modules/?module_bay_id=2
Example Response  
{
    "count": 1,
    "next": null,
    "previous": null,
    "results": [
        {
            "id": 2,
            "url": "http://127.0.0.1:8000/api/dcim/modules/2/",
            "display": "Slot 1: EX9200-32XS (2)",
            "device": {
                "id": 96,
                "url": "http://127.0.0.1:8000/api/dcim/devices/96/",
                "display": "ncsu-coreswitch1",
                "name": "ncsu-coreswitch1"
            },
            "module_bay": {
                "id": 2,
                "url": "http://127.0.0.1:8000/api/dcim/module-bays/2/",
                "display": "Slot 1",
                "name": "Slot 1"
            },
            "module_type": {
                "id": 1,
                "url": "http://127.0.0.1:8000/api/dcim/module-types/1/",
                "display": "EX9200-32XS",
                "manufacturer": {
                    "id": 7,
                    "url": "http://127.0.0.1:8000/api/dcim/manufacturers/7/",
                    "display": "Juniper",
                    "name": "Juniper",
                    "slug": "juniper"
                },
                "model": "EX9200-32XS"
            },
            "serial": "",
            "asset_tag": null,
            "comments": "",
            "tags": [],
            "custom_fields": {},
            "created": "2022-04-08T00:59:29.103000Z",
            "last_updated": "2022-04-08T00:59:29.103000Z"
        }
    ]
}

The installed module is now returned when calling the module bay REST API endpoint.

GET /api/dcim/module_bays/1/
Example Response  
{
    "id": 1,
    "url": "http://127.0.0.1:8000/api/dcim/module-bays/1/",
    "display": "Slot 0",
    "device": {
        "id": 96,
        "url": "http://127.0.0.1:8000/api/dcim/devices/96/",
        "display": "ncsu-coreswitch1",
        "name": "ncsu-coreswitch1"
    },
    "name": "Slot 0",
    "installed_module": {
        "id": 1,
        "url": "http://127.0.0.1:8000/api/dcim/modules/1/",
        "display": "Slot 0: EX9200-32XS (1)",
        "serial": ""
    },
    "label": "",
    "position": "0",
    "description": "",
    "tags": [],
    "custom_fields": {},
    "created": "2022-04-08T00:58:12.864000Z",
    "last_updated": "2022-04-08T00:58:12.864000Z"
}
 
GET /api/dcim/module_bays/
Example Response  
{
    "count": 49,
    "next": null,
    "previous": null,
    "results": [
        {
            "id": 29,
            "url": "http://127.0.0.1:8000/api/dcim/module-bays/29/",
            "display": "ge-0/0/0",
            "device": {
                "id": 1,
                "url": "http://127.0.0.1:8000/api/dcim/devices/1/",
                "display": "dmi01-akron-rtr01",
                "name": "dmi01-akron-rtr01"
            },
            "name": "ge-0/0/0",
            "installed_module": null,
            "label": "",
            "position": "",
            "description": "",
            "tags": [],
            "custom_fields": {},
            "created": "2022-06-19T23:51:17.460166Z",
            "last_updated": "2022-06-19T23:51:17.460180Z"
        },
        {
            "id": 1,
            "url": "http://127.0.0.1:8000/api/dcim/module-bays/1/",
            "display": "Slot 0",
            "device": {
                "id": 96,
                "url": "http://127.0.0.1:8000/api/dcim/devices/96/",
                "display": "ncsu-coreswitch1",
                "name": "ncsu-coreswitch1"
            },
            "name": "Slot 0",
            "installed_module": {
                "id": 1,
                "url": "http://127.0.0.1:8000/api/dcim/modules/1/",
                "display": "Slot 0: EX9200-32XS (1)",
                "serial": ""
            },
            "label": "",
            "position": "0",
            "description": "",
            "tags": [],
            "custom_fields": {},
            "created": "2022-04-08T00:58:12.864000Z",
            "last_updated": "2022-04-08T00:58:12.864000Z"
        },
        {
            "id": 2,
            "url": "http://127.0.0.1:8000/api/dcim/module-bays/2/",
            "display": "Slot 1",
            "device": {
                "id": 96,
                "url": "http://127.0.0.1:8000/api/dcim/devices/96/",
                "display": "ncsu-coreswitch1",
                "name": "ncsu-coreswitch1"
            },
            "name": "Slot 1",
            "installed_module": {
                "id": 2,
                "url": "http://127.0.0.1:8000/api/dcim/modules/2/",
                "display": "Slot 1: EX9200-32XS (2)",
                "serial": ""
            },
            "label": "",
            "position": "1",
            "description": "",
            "tags": [],
            "custom_fields": {},
            "created": "2022-04-08T00:58:12.988000Z",
            "last_updated": "2022-04-08T00:58:12.988000Z"
        },
...

🔄 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/9574 **Author:** [@huntabyte](https://github.com/huntabyte) **Created:** 6/21/2022 **Status:** ✅ Merged **Merged:** 6/23/2022 **Merged by:** [@jeremystretch](https://github.com/jeremystretch) **Base:** `develop` ← **Head:** `feature-9396` --- ### 📝 Commits (3) - [`79b3bc6`](https://github.com/netbox-community/netbox/commit/79b3bc6d12f3f5d8c4445a14a6805a14deeb7443) Closes #9396 - Added ability to query modules by module bay & installed_modules for module bay REST API endpoint - [`9d848a4`](https://github.com/netbox-community/netbox/commit/9d848a413c203128280e10d7d04974a810f29f5d) Closes #9396 - Added ability to query modules by module bay & installed_modules for module bay REST API endpoint - [`f7dad0e`](https://github.com/netbox-community/netbox/commit/f7dad0ee93b42ea66ded7af9760c3122e97daed6) Closes #9396 - Added ability to query modules by module bay & installed_modules for module bay REST API endpoint ### 📊 Changes **5 files changed** (+23 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `netbox/dcim/api/nested_serializers.py` (+9 -0) 📝 `netbox/dcim/api/serializers.py` (+2 -2) 📝 `netbox/dcim/api/views.py` (+1 -1) 📝 `netbox/dcim/filtersets.py` (+6 -0) 📝 `netbox/dcim/tests/test_filtersets.py` (+5 -0) </details> ### 📄 Description <!-- Thank you for your interest in contributing to NetBox! Please note that our contribution policy requires that a feature request or bug report be opened for approval prior to filing a pull request. This helps avoid wasting time and effort on something that we might not be able to accept. Please indicate the relevant feature request or bug report below. IF YOUR PULL REQUEST DOES NOT REFERENCE AN ACCEPTED BUG REPORT OR FEATURE REQUEST, IT WILL BE MARKED AS INVALID AND CLOSED. --> ### Fixes: #9396, #9597 <!-- Please include a summary of the proposed changes below. --> Users can now query modules based on a given module bay id. ``` GET /api/dcim/modules/?module_bay_id=2 ``` <details><summary>Example Response</summary> &nbsp;<br> ```json { "count": 1, "next": null, "previous": null, "results": [ { "id": 2, "url": "http://127.0.0.1:8000/api/dcim/modules/2/", "display": "Slot 1: EX9200-32XS (2)", "device": { "id": 96, "url": "http://127.0.0.1:8000/api/dcim/devices/96/", "display": "ncsu-coreswitch1", "name": "ncsu-coreswitch1" }, "module_bay": { "id": 2, "url": "http://127.0.0.1:8000/api/dcim/module-bays/2/", "display": "Slot 1", "name": "Slot 1" }, "module_type": { "id": 1, "url": "http://127.0.0.1:8000/api/dcim/module-types/1/", "display": "EX9200-32XS", "manufacturer": { "id": 7, "url": "http://127.0.0.1:8000/api/dcim/manufacturers/7/", "display": "Juniper", "name": "Juniper", "slug": "juniper" }, "model": "EX9200-32XS" }, "serial": "", "asset_tag": null, "comments": "", "tags": [], "custom_fields": {}, "created": "2022-04-08T00:59:29.103000Z", "last_updated": "2022-04-08T00:59:29.103000Z" } ] } ``` </details> ---- The installed module is now returned when calling the module bay REST API endpoint. ``` GET /api/dcim/module_bays/1/ ``` <details><summary>Example Response</summary> &nbsp;<br> ```json { "id": 1, "url": "http://127.0.0.1:8000/api/dcim/module-bays/1/", "display": "Slot 0", "device": { "id": 96, "url": "http://127.0.0.1:8000/api/dcim/devices/96/", "display": "ncsu-coreswitch1", "name": "ncsu-coreswitch1" }, "name": "Slot 0", "installed_module": { "id": 1, "url": "http://127.0.0.1:8000/api/dcim/modules/1/", "display": "Slot 0: EX9200-32XS (1)", "serial": "" }, "label": "", "position": "0", "description": "", "tags": [], "custom_fields": {}, "created": "2022-04-08T00:58:12.864000Z", "last_updated": "2022-04-08T00:58:12.864000Z" } ``` </details> &nbsp;<br> ``` GET /api/dcim/module_bays/ ``` <details><summary>Example Response</summary> &nbsp;<br> ```json { "count": 49, "next": null, "previous": null, "results": [ { "id": 29, "url": "http://127.0.0.1:8000/api/dcim/module-bays/29/", "display": "ge-0/0/0", "device": { "id": 1, "url": "http://127.0.0.1:8000/api/dcim/devices/1/", "display": "dmi01-akron-rtr01", "name": "dmi01-akron-rtr01" }, "name": "ge-0/0/0", "installed_module": null, "label": "", "position": "", "description": "", "tags": [], "custom_fields": {}, "created": "2022-06-19T23:51:17.460166Z", "last_updated": "2022-06-19T23:51:17.460180Z" }, { "id": 1, "url": "http://127.0.0.1:8000/api/dcim/module-bays/1/", "display": "Slot 0", "device": { "id": 96, "url": "http://127.0.0.1:8000/api/dcim/devices/96/", "display": "ncsu-coreswitch1", "name": "ncsu-coreswitch1" }, "name": "Slot 0", "installed_module": { "id": 1, "url": "http://127.0.0.1:8000/api/dcim/modules/1/", "display": "Slot 0: EX9200-32XS (1)", "serial": "" }, "label": "", "position": "0", "description": "", "tags": [], "custom_fields": {}, "created": "2022-04-08T00:58:12.864000Z", "last_updated": "2022-04-08T00:58:12.864000Z" }, { "id": 2, "url": "http://127.0.0.1:8000/api/dcim/module-bays/2/", "display": "Slot 1", "device": { "id": 96, "url": "http://127.0.0.1:8000/api/dcim/devices/96/", "display": "ncsu-coreswitch1", "name": "ncsu-coreswitch1" }, "name": "Slot 1", "installed_module": { "id": 2, "url": "http://127.0.0.1:8000/api/dcim/modules/2/", "display": "Slot 1: EX9200-32XS (2)", "serial": "" }, "label": "", "position": "1", "description": "", "tags": [], "custom_fields": {}, "created": "2022-04-08T00:58:12.988000Z", "last_updated": "2022-04-08T00:58:12.988000Z" }, ... ``` </details> --- <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-29 23:19:09 +01:00
adam closed this issue 2025-12-29 23:19:09 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#13488