netbox: add orphaned_device_status and orphaned_vm_status - #564
Merged
Merged
Conversation
Closes #458 Adds two new config options to automatically set the NetBox status of orphaned devices and VMs. When a device/VM is orphaned (source no longer reports it), the status is changed to the configured value (e.g. 'decommissioning'). When the object reappears in a source, the status is restored to 'active'. The status change is guarded by prune_enabled — if a source is unavailable (failed to initialize), pruning is disabled which prevents the status change. This protects against false decommissioning during transient source outages. Only affects NBDevice and NBVM — other prunable objects (interfaces, IPs, etc.) don't have a status field.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #514 by @berlikm and #458, his commit is in here unchanged.
The options do what #458 asked for: park a device or VM at a chosen status while it is orphaned. What needed fixing before it could land was the other half - his branch also restored a reappearing object to
active, and that ran for everyone, including people who never set either option. A VM someone had deliberately put onplannedwould have been flipped toactiveon the next run.It now only restores the status if the object still carries the exact status configured for orphans, so it only undoes what this program did itself. Anything a user or a source set is left alone. With neither option configured nothing touches a status at all.
Two things I checked while in there and left as they are: the orphan branch is gated on
prune_enabled, which is right since pruning is disabled whenever a source was unavailable and we would otherwise park healthy objects; and the configured value is validated against NetBox's status list at config time, so a typo fails the run instead of writing garbage. Reworded both option descriptions to say all of that.tests/test_orphaned_object_status.py: 3 of 13 fail without the fix - the two "option unset, status untouched" cases and the one where a user-set status must survive. Suite 137.