Replace numeric constants with slug values
See original GitHub issueProposed Changes
Replace the numeric values used for many fields with human-friendly slug values. For example:
RACK_STATUS_RESERVED = 0
RACK_STATUS_AVAILABLE = 1
RACK_STATUS_PLANNED = 2
RACK_STATUS_ACTIVE = 3
RACK_STATUS_DEPRECATED = 4
RACK_STATUS_CHOICES = [
[RACK_STATUS_ACTIVE, 'Active'],
[RACK_STATUS_PLANNED, 'Planned'],
[RACK_STATUS_RESERVED, 'Reserved'],
[RACK_STATUS_AVAILABLE, 'Available'],
[RACK_STATUS_DEPRECATED, 'Deprecated'],
]
would become
RACK_STATUS_RESERVED = 'active'
RACK_STATUS_AVAILABLE = 'planned'
RACK_STATUS_PLANNED = 'reserved'
RACK_STATUS_ACTIVE = 'available'
RACK_STATUS_DEPRECATED = 'deprecated'
RACK_STATUS_CHOICES = [
[RACK_STATUS_ACTIVE, 'Active'],
[RACK_STATUS_PLANNED, 'Planned'],
[RACK_STATUS_RESERVED, 'Reserved'],
[RACK_STATUS_AVAILABLE, 'Available'],
[RACK_STATUS_DEPRECATED, 'Deprecated'],
]
Justification
Employing human-friendly slug values make consuming the REST API more convenient. It also allows more human-friendly representations of the pertinent field values in other formats, such as YAML (see #451).
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:36 (33 by maintainers)
Top Results From Across the Web
How to convert a Title to a URL slug in jQuery? - Stack Overflow
I have no idea where the 'slug' term came from, but here we go: function convertToSlug(Text) { return Text.toLowerCase() .replace(/ /g ...
Read more >BigBinary Books - Optimizing slug generation process
One solution here is to use the LIKE operator from SQLite to query all tasks with a matching slug. Once we have a...
Read more >Store Variables with the TI-84 Plus Calculator - Dummies.com
Learn how to store variables in a TI-84 Plus calculator by using the STO key. Here's a step-by-step guide, with screen images.
Read more >replace - Functions - Configuration Language | Terraform
The replace function searches a given string for another given substring, and replaces all occurrences with a given replacement string.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
After giving this some more thought, I’m going to proceed with option 3 as it seems like the best compromise between developer and user maintainability. The
value
field will convey the new slug value, and we’ll add anid
field to continue conveying the numeric value (to be deprecated for v2.8).Importantly, these fields will accept both the numeric and slug values on write for the entire v2.7 release, to maintain backward compatibility for the near future.
The problem still lies in the transition of dependent-services. If the solution is to “wait until everything supports the new scheme” then that means the release of N-number of new versions external scripts/apps/services at the exact same time as the Netbox upgrade. That’s untenable for most environments.
to @lampwins point, if there was some sort of API versioning in place, for example v2.7.0 provided these two endpoints:
That would allow each individual external app/service/script to migrate in its own time, on separate release windows from the Netbox upgrade. This is a far better experience all around and makes the upgrade process much easier to go through.
From a maintainer perspective, really it’s just a separate API module at that point, the code for the two shall remain separate - and you only move new code to the
api_v2.py
module when there’s actually av2
- keeping it clear where things are.