feat: track rack and position in Ironic extra fields - #2227
Draft
cardoe wants to merge 3 commits into
Draft
Conversation
The Ironic node `extra` dict carries UnderStack-specific metadata that the Nautobot device sync consumes, but it was previously undocumented. Document the `extra` field and the `external_cmdb_id` key as they exist today.
Resolve the OpenStack region this deployment manages to its Nautobot Location once, up front, and thread that Location object down to fetch_node_details so location-scoped Nautobot lookups can be scoped to it (e.g. resolving a rack). On the event path, handle_node_event now uses the OpenStack connection it already receives (conn.config.region_name) instead of discarding it. On the resync CLI path the region is derived from the same clouds.yaml/env the IronicClient uses. In both cases get_location_for_region looks up the Location and fails fast if the region does not resolve to exactly one Nautobot Location. No node-sync behavior change yet, but objects and lookups that should be location-scoped can and should use this.
The Nautobot device sync previously derived a node's rack and location only from the switches its ports are cabled to, and never set the rack-unit position. Allow an explicit placement via the node's Ironic extra field: rack (a Nautobot rack name) and position (the rack unit). When both are present and the rack name resolves to a single Nautobot rack, the sync uses them for rack, location, and position, overriding the switch-based lookup. The lookup is scoped to the region's Nautobot location (a rack name is only unique within a location), an ambiguous match falls back cleanly, and the position is validated before any state is mutated. If either field is missing or the rack can't be resolved, the sync falls back to the existing switch-based behavior. Also stop preserving the old device's position on re-enrollment when extra supplies one, so extra stays authoritative.
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.
Refactor the code path of syncing devices from Ironic into Nautobot to utilize the
extra.rackandextra.positiondata that would come from Ironic. To do this I first changed how we determine the Nautobot Location, which should always be equal to the OpenStack region and has not been respected before. So this updates the code to use the OpenStack region and perform a lookup of the Nautobot Location based on that value first and thread that through. There are more objects and item in Nautobot that we've treated globally unique but should be scoped to this Location but I've left that to a future update. Lastly (or first commit really) document theextravalues that are used by scripts and code on an Ironic node.