Skip to content

vmware: create cables from ESXi CDP/LLDP neighbours, behind sync_host_cables - #565

Open
semx wants to merge 5 commits into
developmentfrom
feature/host-cdp-lldp-cables
Open

vmware: create cables from ESXi CDP/LLDP neighbours, behind sync_host_cables#565
semx wants to merge 5 commits into
developmentfrom
feature/host-cdp-lldp-cables

Conversation

@semx

@semx semx commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

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 an if: NBCable was in the class-level dependent_netbox_objects, so every run did a GET /api/dcim/cables whether or not you used the feature (now appended per instance); the branch replaced the single QueryNetworkHint("") 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() matched sw01.dc1 against a neighbour reporting sw01.dc2. And there were five log.info lines per pNIC per run.

I also dropped two things rather than keep guessing: the cable type, which was set to dac-active for 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. --purge removes 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.py is 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.

root and others added 5 commits August 22, 2026 15:00
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.
@semx
semx requested a review from bb-Ricardo as a code owner September 10, 2026 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant