jwegner89 / netbox-utilities

Archived, new home at https://gitlab.com/jwegner/netbox-utilities
GNU General Public License v3.0
66 stars 18 forks source link

Sync-vmware Issue with non-unique host names #4

Open mmahacek opened 6 years ago

mmahacek commented 6 years ago

We have some VMs that have an operating system hostname that is not unique, which was causing them to not be provisioned properly into Netbox. I made the following workaround to have all VMs named by their VM name and not the guest host name.

Line 192: Old: $Hostname = $Guest.Hostname.ToLower() New: $Hostname = $VM.Name.ToLower()

jwegner89 commented 6 years ago

Netbox forces unique names for all VM objects, and this script intentionally canonicalizes to the OS hostname when it can be determined (lines 196-204). I understand the issue you're encountering, but I'm kind of anticipating that most people will adapt this script to their own environments. In particular, this is not the version of the script that I use in our organization because I insert a lot of organization-specific logic into our version. So I'm inclined to say that the current logic is fine and your use case is specific to your environment. Does that make sense?

With that said, I could understand adding in some logic to handle getting around the uniqueness requirement, e.g. if you've cloned a machine or are recovering from a Veeam backup. Do you have a suggestion for how you want to handle the case of another machine with the same hostname? When does that arise? Is it better simply to mirror the VM inventory name? I personally like the network hostname from in-guest, but I could see the other way as well.