vcenter-netbox-sync
vcenter-netbox-sync copied to clipboard
Sync Virtual Machine network names
Our VMs are connected to Networks with a clear defined naming convention that lets us get a lot of Information about the Network just by the name. Sadly those Names are not synced to Netbox and the interfaces are just named generic vNIC0, vNIC1, ...
Describe the solution you'd like If the network name is available sync it to Netbox if not use the generic vNICx.
Describe alternatives you've considered Maybe some people don't want the network names to be synced, so an optional setting could be created for that.
Additional context
The change would be really simple, only one line in run.py would have to change from nic_name = "vNIC{}".format(index) to nic_name = getattr(nic, "network", "vNIC{}".format(index))
I don't know what the Netbox api character limit ist but the name should probably also be truncated
Hello, @Haeki.
Thanks for the suggestion. This seems like a reasonable ask. Let me do some further testing and I'll work on getting this patched in.
I found and fixed a little Problem with this myself. Our network names contain plus signs so when rerunning the sync they don't get found in Netbox and are created again,
Luckily this is a very easy fix. When creating the query for virtual_interfaces qute_plus() should be used on vc_data[query_key]:
query = "?virtual_machine={}&{}={}".format(quote_plus(vc_data["virtual_machine"]["name"]), query_key,quote_plus(vc_data[query_key]))
Hi @Haeki! If you'd like to submit a pull request I would be happy to credit you with the contribution. Otherwise I am happy to patch this in. Thanks!
Also looked into it. For some strange reason you only get the network name from the guest tools. but the API should report the network names even without Guest tools installed.
I went down a rabbit hole and finally can see the light at the end of the tunnel again. This took way longer then expected (as usual).
Here you go: https://github.com/bb-Ricardo/netbox-sync
please test as much as you can: Debug logs are very welcome.