Repository navigation
Conversation
…om field vCenter VM names and the hostname reported by VMware Tools from inside the guest OS can drift apart (renames, manual OS changes, bad clones). Setting vm_guest_hostname_custom_field lets a vCenter source sync guest.hostName into a configurable NetBox custom field, without touching the VM's name, so admins can compare both on one record.
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.
Summary
This PR adds optional support for syncing the hostname reported by VMware Tools (
guest.hostName) to a NetBox Virtual Machine custom field.The vCenter VM name and the hostname configured inside the guest operating system are not always the same. This can happen after VM renames, cloning operations, or manual hostname changes inside the guest OS.
Keeping both values in NetBox makes these differences easier to identify.
Configuration
A new optional VMware source setting is added:
When configured, netbox-sync reads the hostname reported by VMware Tools and writes it to the selected NetBox VM custom field.
The NetBox VM name continues to use the vCenter inventory name and is not changed by this feature.
Example:
or:
Custom field behavior
If the configured custom field does not already exist, netbox-sync creates it automatically as a Text custom field for Virtual Machine objects.
An existing custom field can also be used.
The hostname is stored as reported by VMware Tools without changing the case or removing the domain name.
VMware Tools unavailable
If VMware Tools is not installed, not running, or does not currently report a hostname, synchronization continues normally.
In this case, the custom field is not updated and the previous value in NetBox is preserved.
This avoids clearing a previously known hostname because of a temporary VMware Tools issue.
Performance
The hostname is read from the existing
vim.VirtualMachineobject usingguest.hostName.No additional per-VM vCenter API requests are required.
Backward compatibility
The feature is disabled by default.
Existing configurations are not affected unless
vm_guest_hostname_custom_fieldis explicitly configured.There are no mandatory configuration or NetBox schema changes.
Tested with
Successfully tested with:
The guest hostname was successfully retrieved from VMware Tools and synchronized to the configured NetBox VM custom field.
13 tests were also added for the new functionality and all are passing:
Documentation
The following were also updated:
settings-example.ini