Allow unracking devices by setting position = 0#1103
Allow unracking devices by setting position = 0#1103eliezerlp wants to merge 1 commit intonetbox-community:develfrom
Conversation
sc68cal
left a comment
There was a problem hiding this comment.
This needs a unit test, but also frankly I'm not crazy about 0 having a special significance that is specific to this module.
I know there's an issue around somewhere in the tracker discussing how to handle unsetting fields, I'll have to find it
|
Thanks for the link to #330; I hadn't come across it. If we'd consider merging this approach specific to netbox_device |
|
Regarding this:
I understand the hesitation regarding @sc68cal, please let me know if this would be considered for merging. If so I'll proceed with adding tests. Thanks! |
|
I'm happy to merge this and see how users react to having an unracking option. But we need to document this properly. So @eliezerlp , could you add an example to the docs, and point it out in the option documentation. |
Related Issue
No related issue.
New Behavior
Allow setting a device as not racked by setting
position: 0in thedatastructure.Contrast to Current Behavior
Currently it is not possible to set a device as Not racked via the netbox.netbox.netbox_device module.
Netbox ordinarily rejects an API call with position=0 since this is outside of the allowable range of values.
The way to ordinarily set a device as unracked is to send
nullfor the particular field.Since the module strips default fields that have null values (even if explicitly included in the
data) it seems otherwise impossible to unrack a device.Allowing a value that is otherwise rejected by the API seems to be a natural fit.
Discussion: Benefits and Drawbacks
Why do you think this project and the community will benefit from your
proposed change?
Allows using module in a wider array of use cases.
My issue was that a device was moved to a particular rack, but the exact RU was not known. When updating the device with the new rack, I couldn't leave the device with the position populated as (1) it was incorrect and (2) it was already populated with another device.
What are the drawbacks of this change?
Not directly mirroring the API, but since
nullis problematic it seems OK.Is it backwards-compatible?
It seems backwards compatible since the value
0is otherwise rejected by the Netbox API since position must be >=1.0.Anything else that you think is relevant to the discussion of this PR.
My attempts to get the module to pass
nullwere originally foiled by the_remove_arg_spec_default()function. Originally having added a special case to that function, I decided that simply passing a non-null value (which ultimately results innullbeing sent) was best.It is worth noting that the
positionfield is one of many default fields that a user might need to set to null. It might we worth considering a more generic approach (perhaps in the future) that addresses any field. For example, one might want to disassociate a device from particularrack. In order to do this, similarly, sending outnullis required, but ordinarily stripped even if explicitly included in the data with no value set.Here is how a device without an assigned

positionlooks:Here is what a changelog entry looks like that actually unracks a device:

Changes to the Documentation
Not sure how to appropriately document this. I didn't find a spot where it would naturally fit but I do think that documentation is very important since the special meaning of
position: 0is not otherwise known. Here is an example blurb:Setting Devices as "Not Racked"
A device can be designated as "Not Racked" using the
positionfield in thenetbox_devicemodule. To do this, set thepositionvalue to0.For example:
Proposed Release Note Entry
Double Check
develbranch.