Allow unracking devices by setting position = 0 #1103
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.