netbox-community / netbox

The premier source of truth powering network automation. Open source under Apache 2. Try NetBox Cloud free: https://netboxlabs.com/free-netbox-cloud/
http://netboxlabs.com/oss/netbox/
Apache License 2.0
15.83k stars 2.54k forks source link

Allow ordering by custom fields when using the REST API #15050

Open Yutsuten opened 7 months ago

Yutsuten commented 7 months ago

NetBox version

v3.7.1

Feature type

Change to existing functionality

Proposed functionality

This is a continuation of #14854

Currently the ordering parameter on API requests do not allow the usage of custom fields. It only allows predetermined fields (name, site, etc) to be used.

I propose that we could also use custom fields on ordering too. So when generating a GET request to /api/dcim/devices/?ordering=cf_cpu, for instance, the data would be sorted by the custom field cpu.

We can do that on the NetBox's web interface already, where the sort parameter is used instead. The expected output is the same, but using the API interface.

Use case

There are two reasons for my project to need this:

  1. Usage of NetBox as a component (it is part of a bigger project)
  2. The extensive usage of custom fields

Starting with 1. NetBox is an excellent tool to organize devices in a network. That's why we're using it. But we want to do more than just organize the data. We want to access it's data from another components. We want to extend it's functionality. So, for instance, we want to take actions on the devices that are registered on NetBox: Component "ABC" get NetBox data, run some commands over the network, and finally it may make some updates to NetBox. All of this "communication" between components happens using the REST API. We do stuff that is out of scope of NetBox itself. That's why the API exists after all, right?

Now with 2. In my use case, a device, for example, goes beyond what NetBox means it to be. It may mean an actual server, with CPU, memory, disk capacity, etc. And custom fields are used to store these data. (In fact there is much more than that. There are things that are so specific to my use case that it is out of scope for asking to add these to NetBox.).

The component used to store data (NetBox) and the component used to run actions (let's call it Component "ABC") are different. The Component "ABC" also have an user interface, and it may show data in a similar way NetBox does. That's why we want to allow custom field sorting using the API too.

Database changes

Not required.

External dependencies

Not required.

jeffgdotorg commented 7 months ago

Thank you for the additional detail in this issue versus its bug precursor.

At the moment we're in something of a freeze where custom field work is concerned, so I'm marking this issue as blocked by #14000. Once that work to re-architect the representation of custom fields is done, we can work on scheduling this feature work.

kidonson commented 3 months ago

I'm also interested in this feature, and I noticed #14000 has been closed. Is this no longer blocked?

michi-sab commented 2 months ago

Also interested in this feature. Is there any plan for implementing it?