vmware: create cables from ESXi CDP/LLDP neighbours, behind sync_host_cables - #565
Open
semx wants to merge 5 commits into
Open
vmware: create cables from ESXi CDP/LLDP neighbours, behind sync_host_cables#565semx wants to merge 5 commits into
semx wants to merge 5 commits into
Conversation
During host sync, read physical NIC neighbor hints (CDP connectedSwitchPort / LLDP lldpInfo), match switch device and port in NetBox inventory, and create dcim.cable objects (server pNIC ↔ switch port) when both ends resolve.
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.
This is #535 by @killaexist, and I want your eyes on it rather than merging it myself - it grew well past the gate I asked him for.
The gate is done and measured.
sync_host_cables, bool, off by default, and with it off a vcsim sync produces the same inventory as current development: same 30 interfaces with the same descriptions, no cable objects, none of the cable code entered. Three things were needed for that beyond anif:NBCablewas in the class-leveldependent_netbox_objects, so every run did aGET /api/dcim/cableswhether or not you used the feature (now appended per instance); the branch replaced the singleQueryNetworkHint("")per host with one call per pNIC, which is 12 extra vCenter round trips on the vc001 capture (restored); and the LLDP text was appended to every pNIC description, which would have rewritten descriptions in NetBox for everyone.While in there I fixed things that would have bitten whoever turned it on. An interface already cabled to anything else made NetBox reject the POST with "already has a cable attached" on every run forever, since the existing-cable check only matched a cable between exactly those two interfaces. An existing cable was skipped without claiming it, so it was tagged orphaned, pruned, and recreated on the next run. Interface lookup fell back to comparing device names, and this tool explicitly supports same-named devices in different sites, so it could cable the wrong box.
_find_device_by_name()matchedsw01.dc1against a neighbour reportingsw01.dc2. And there were fivelog.infolines per pNIC per run.I also dropped two things rather than keep guessing: the cable
type, which was set todac-activefor anything that is not FastEthernet even though CDP/LLDP say nothing about the medium, and the label, which was a pair of raw NetBox interface IDs in a user-visible field -get_display_name()resolves the terminations instead.The part I am least comfortable with is that
add_device_vm_to_inventory()now returns the device and the interfaces it created instead of nothing, so the cable step does not have to rescan the inventory. Both callers are in this file, but it is a signature change in shared code and it is your call whether that is worth it.Cables are cleaned up the same way as everything else: no longer reported means the source tag goes, orphaned tag comes, and
prune_data()deletes after the delay.--purgeremoves them too, which is new for anyone who ran the earlier version. First run after discovering a host cannot cable it, both ends need real NetBox IDs, so it happens on the second run - the docs say so.tests/test_vmware_host_cables.pyis 54 tests: the name-variant and CDP/LLDP parsing helpers, and the whole decision table for a neighbour that is missing, ambiguous, in another domain, already cabled, or cabling back. Suite 191.