Skip to content

feat(VMware): add option overwrite_host_interface_type - #595

Open
tfoks wants to merge 2 commits into
bb-Ricardo:developmentfrom
tfoks:fix/vmware-keep-physical-nic-type
Open

tfoks wants to merge 2 commits into
bb-Ricardo:developmentfrom
tfoks:fix/vmware-keep-physical-nic-type

Conversation

@tfoks

@tfoks tfoks commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

The VMware source derives a host pNIC's type from its current link speed. If the NIC has no link, it uses the first valid link speed, or other. The check_redfish source sets the type from the NIC hardware. With both sources on the same ESXi hosts, they disagree on every run:

INFO: Interface 'vmnic1 (de-mucesx54)' attribute 'type' changed from '10gbase-x-sfpp' to '1000base-t'
INFO: Interface 'vmnic4 (de-mucesx54)' attribute 'type' changed from '10gbase-x-sfpp' to '100base-tx'

The first case is an SFP+ port running at 1G; the second is an SFP+ port without link. Within one run, the revert logic cancels the PATCH again. What repeats is the log line, and the final type depends on the order of the sources.

This adds an option to the VMware source, as suggested in the review:

; define if the type of a host interface derived from its link speed overwrites a physical
; interface type in NetBox. Set to False if a source which knows the hardware (i.e.
; check_redfish) sets the type of the host interfaces
;overwrite_host_interface_type = True

The default True keeps the current behaviour, so vCenter-only setups still get a wrong type corrected. With False, the type of an existing host interface is kept if it's a physical type. virtual, bridge, lag, other or no type are still set by vCenter. New interfaces get the type vCenter derives.

Changes:

  • module/sources/vmware/config.py, settings-example.ini: new option overwrite_host_interface_type, default True.
  • module/sources/vmware/connection.py: with the option False, don't send a type for an existing host interface that has a physical type. NetBox returns the type as {"value": ..., "label": ...}, so the value is read from that dict.
  • tests/test_vmware_host_nic_type.py: second-run tests. With False, a physical type is kept and other is still updated. With the default, a wrong type is still set from the link speed. The first test fails on development.

Tested with the vcsim captures; see the tests above. Against NetBox 4.7.2 with a vCenter source and the check_redfish inventory files of HPE and Lenovo hosts, the first version of this PR stopped the type changes in the dry-run. Confirmed with overwrite_host_interface_type: False on our test and prod instances: the dry-run logs no type changes for host interfaces and no errors. pytest: 374 passed, 8 skipped (vcsim installed).

🤖 Generated with Claude Code

The VMware source derives the type of a host pNIC from its current link speed
(or the first valid link speed without link). With a check_redfish source on
the same hosts, which sets the type from the NIC hardware, both sources
overwrote each other on every run, i.e. 10gbase-x-sfpp <> 1000base-t for an
SFP+ port running at 1G.

Keep the current type of an existing host interface if it is a physical type
which supports the speed vCenter reports. A slower type is still updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tfoks
tfoks requested review from bb-Ricardo and semx as code owners October 12, 2026 07:50

@semx semx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conflict between the two sources is real, but the speed heuristic changes behaviour for everyone:

  • vCenter-only setups no longer get a too fast type corrected. Checked on 4.7.2 with vcsim: development sets vmnic0 back from 400gbase-x-qsfpdd to 1000base-t, this branch keeps 400G.
  • A port without link: vCenter derives other, its valid_types value is a string, so the guard is skipped and the SFP+ type is still overwritten, the second case from the description.
  • The FC types are in Gbit (1..128) and the Ethernet ones in Mbit, so with sync_host_fc_adapters they're compared across families.

I'd make this explicit instead: an overwrite_host_interface_type option like overwrite_device_interface_name, default True (current behaviour), and with False an existing physical type is kept. That covers redfish plus vCenter without guessing from speeds.

On the description: within one run the PATCH is cancelled again by the revert logic, what repeats is the log line, and the final type depends on the order of the sources.

Replace the link speed heuristic of the previous commit with an explicit option,
as suggested in the review. The heuristic changed the behaviour for vCenter-only
setups (a too fast type was no longer corrected), still overwrote the type of a
port without link (derived as 'other') and compared FC types in Gbit with
Ethernet types in Mbit.

overwrite_host_interface_type defaults to True, the current behaviour. With
False the type of an existing host interface is kept if it is a physical type,
so a check_redfish source can own the type of the host interfaces.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tfoks tfoks changed the title fix(VMware): keep a faster physical host NIC type already in NetBox feat(VMware): add option overwrite_host_interface_type Oct 12, 2026
@tfoks

tfoks commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Agreed. The speed comparison was guessing, and your three cases show it. I replaced it with overwrite_host_interface_type, modelled on overwrite_device_interface_name:

  • Default True: unchanged behaviour. A test checks that a too-fast type is still corrected from the link speed.
  • False: an existing physical type is kept. virtual, bridge, lag, other or no type are still set by vCenter. A port without link no longer matters, and nothing compares FC and Ethernet speeds.
  • Updated the description: within one run the PATCH is cancelled again, what repeats is the log line, and the final type depends on the source order.

The title is now feat(VMware): add option overwrite_host_interface_type.

@semx semx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much simpler this way, thanks. I tried it on the vcsim setup: set two vmnics to SFP+ and one to other through the API. With the option off the SFP+ types stayed, other got the link speed type, and the next run didn't touch anything. With the default, vCenter put 1000base-t back like before.

@tfoks

tfoks commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

Confirmed with overwrite_host_interface_type: False against NetBox 4.7.2 with a vCenter source plus the check_redfish inventory files of HPE and Lenovo hosts, on both our test and prod instances: the dry-run logs no type changes for host interfaces and no errors. I updated the description to match.

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.

2 participants