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

Add 'interface_connection.id' to output of '/api/dcim/interfaces/[id]/' #2034

Closed
bdlamprecht opened this issue Apr 17, 2018 · 1 comment
Closed
Labels
status: accepted This issue has been accepted for implementation
Milestone

Comments

@bdlamprecht
Copy link
Contributor

Issue type

[X] Feature request

Environment

  • Python version: 3.5.2
  • NetBox version: 2.3.2

Description

Currently, when you hit the API at /api/dcim/interfaces/[id]/ you get a lot of attributes such device, is_connected, description, and more importantly, interface_connection. All of this is very helpful, but what is missing that I'd like to have added is the id of the interface_connection (if applicable).

For example, the output you get from /api/dcim/interfaces/59/ is as follows (some fields have been removed for brevity):

{
    "id": 59,
    "device": {
        "id": 135,
        "url": "/api/dcim/devices/135/",
        "name": "foo-bar-b",
        "display_name": "foo-bar-b"
    },
    "enabled": true,
    "lag": null,
    "mtu": null,
    "mac_address": null,
    "mgmt_only": false,
    "description": "",
    "is_connected": true,
    "interface_connection": {
        "interface": {
            "id": 56,
            "url": "/api/dcim/interfaces/56/",
            "device": {
                "id": 134,
                "url": "/api/dcim/devices/134/",
                "name": "foo-bar-a",
                "display_name": "foo-bar-a"
            },
            "name": "xe-0/0/0",
            "enabled": true,
            "description": ""
        },
        "status": true
    }
}

I know I can get the information I'm looking for (i.e. the id for the interface_connection) by hitting the API at /api/dcim/interface_connections/?device=foo-bar-a and doing some basic logic to determine if the device in question is on the "a-side" or the "b-side" of the interface_connection.

For example, you get the following output (some fields have also been remove for brevity):

{
    "count": 4,
    "results": [
        {
            "id": 2,
            "interface_a": {
                "id": 59,
                "url": "/api/dcim/interfaces/59/",
                "device": {
                    "id": 135,
                    "url": "/api/dcim/devices/135/",
                    "name": "foo-bar-b",
                    "display_name": "foo-bar-b"
                },
                "name": "xe-0/0/0",
                "form_factor": {
                    "value": 1200,
                    "label": "SFP+ (10GE)"
                },
                "enabled": true,
                "lag": null,
                "mtu": null,
                "mac_address": null,
                "mgmt_only": false,
                "description": ""
            },
            "interface_b": {
                "id": 56,
                "url": "/api/dcim/interfaces/56/",
                "device": {
                    "id": 134,
                    "url": "/api/dcim/devices/134/",
                    "name": "foo-bar-a",
                    "display_name": "foo-bar-a"
                },
                "name": "xe-0/0/0",
                "form_factor": {
                    "value": 1200,
                    "label": "SFP+ (10GE)"
                },
                "enabled": true,
                "lag": null,
                "mtu": null,
                "mac_address": null,
                "mgmt_only": false,
                "description": ""
            },
            "connection_status": {
                "value": true,
                "label": "Connected"
            }
        }
    ]
}

In summary, the desired output I'd like to get of /api/dcim/interfaces/59/ is the following (note the added id of interface_connection):

{
    "id": 59,
    "device": {
        "id": 135,
        "url": "/api/dcim/devices/135/",
        "name": "foo-bar-b",
        "display_name": "foo-bar-b"
    },
    "enabled": true,
    "lag": null,
    "mtu": null,
    "mac_address": null,
    "mgmt_only": false,
    "description": "",
    "is_connected": true,
    "interface_connection": {
        "id": 2,
        "interface": {
            "id": 56,
            "url": "/api/dcim/interfaces/56/",
            "device": {
                "id": 134,
                "url": "/api/dcim/devices/134/",
                "name": "foo-bar-a",
                "display_name": "foo-bar-a"
            },
            "name": "xe-0/0/0",
            "enabled": true,
            "description": ""
        },
        "status": true
    }
}

I don't imagine that this would take too much effort to implement (perhaps one to two lines of code), but if that is not the base, please let me know and I'll go back the "hack" that I was using previously.

@bdlamprecht
Copy link
Contributor Author

One thing that I forgot to mention is why does /api/dcim/interfaces/ allow for the filters ?device=[NAME] AND ?device_id=[ID] but /api/dcim/interface-connections/ only allows for ?device=[NAME]?

Not a huge issue, but I'd imagine that consistency between the two would be fairly important.

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation API change labels Apr 19, 2018
@jeremystretch jeremystretch added this to the v2.4 milestone Apr 19, 2018
frankfarmer added a commit to Wikia/netbox that referenced this issue Apr 19, 2018
frankfarmer added a commit to Wikia/netbox that referenced this issue Apr 19, 2018
frankfarmer added a commit to Wikia/netbox that referenced this issue Apr 19, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jan 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants