Netbox: Reusable/packaged netbox constants

Created on 19 Jun 2018  路  5Comments  路  Source: netbox-community/netbox

Hello,

I was wondering if you would consider moving netbox' constants.py into a separate dependency required by both netbox and pynetbox or maybe making an API endpoint for them.

Handling them is not much of an hassle, but It might feel more comforting to have them right away when using pynetbox.

Most helpful comment

In pynetbox, I'd like to do the following without maintaining the constants by myself or using the hardcoded values :

nb.dcim.interfaces.create(device="somedevice", name="eth0", form_factor=IFACE_FF_1GE_FIXED)

I guess It would ease the use of pynetbox a bit and prevent some possible regressions in case of modifications on the constants part.

Adding special endpoints in the netbox API to expose the constants might be the way to go, since it would not be language dependent.

GET /api/dcim/constants/

{
    "dcim:constants": [
        {
            "IFACE_FF_100ME_FIXED": 800,
        },
        {
            "IFACE_FF_1GE_FIXED": 1000,
        },
        ...
    ]
}

That would require some work in the client libraries to cache this constants and make them reusable.

All 5 comments

Thank you for your interest in NetBox. It looks like your feature request is missing some information. Per the contributing guidelines, please ensure that you have provided all of the following:

  • A detailed description of the proposed functionality
  • A use case for the feature; who would use it and what value it would add to NetBox
  • A rough description of changes necessary to the database schema (if applicable)
  • Any third-party libraries or other resources which would be involved

Please update the issue so that it meets all of these requirements. If no response is received within a week, this issue will be closed. Thanks!

In pynetbox, I'd like to do the following without maintaining the constants by myself or using the hardcoded values :

nb.dcim.interfaces.create(device="somedevice", name="eth0", form_factor=IFACE_FF_1GE_FIXED)

I guess It would ease the use of pynetbox a bit and prevent some possible regressions in case of modifications on the constants part.

Adding special endpoints in the netbox API to expose the constants might be the way to go, since it would not be language dependent.

GET /api/dcim/constants/

{
    "dcim:constants": [
        {
            "IFACE_FF_100ME_FIXED": 800,
        },
        {
            "IFACE_FF_1GE_FIXED": 1000,
        },
        ...
    ]
}

That would require some work in the client libraries to cache this constants and make them reusable.

Adding special endpoints in the netbox API to expose the constants might be the way to go, since it would not be language dependent.

The interface form factors are available at /api/dcim/_choices/:

{
    "interface:form_factor": [
        {
            "value": 0,
            "label": "Virtual"
        },
        {
            "value": 200,
            "label": "Link Aggregation Group (LAG)"
        },
        {
            "value": 800,
            "label": "100BASE-TX (10/100ME)"
        },
        {
            "value": 1000,
            "label": "1000BASE-T (1GE)"
        },
        ...
}

Do you need the name of the constant itself exposed as well?

Wonder how I missed that. :)

Labels should be enough for now. In the long run constants might be cleaner though (If you ever wish to localize the app maybe, or to enable some readable filtering /api/dcim/_choices/interface:form_factor/?label=100BASE-TX%20%2810/100ME%29).

Do wish me open an issue on the pynetbox project to discuss the retrieval part in it ? Even if writing a custom function isn't hard, a reusable builtin method would be nicer.

@dsanader Feel free to open an FR against pynetbox for it. I haven't kept up much with pynetbox lately.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bellwood picture bellwood  路  4Comments

Ali-Yazdani picture Ali-Yazdani  路  3Comments

luto picture luto  路  3Comments

markve-sa picture markve-sa  路  4Comments

shugotek picture shugotek  路  3Comments