vcenter-netbox-sync icon indicating copy to clipboard operation
vcenter-netbox-sync copied to clipboard

Sync Virtual Machine network names

Open Haeki opened this issue 5 years ago • 6 comments

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))

Haeki avatar Apr 29 '20 11:04 Haeki

I don't know what the Netbox api character limit ist but the name should probably also be truncated

Haeki avatar Apr 29 '20 13:04 Haeki

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.

synackray avatar May 01 '20 10:05 synackray

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]))

Haeki avatar May 06 '20 21:05 Haeki

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!

synackray avatar May 07 '20 16:05 synackray

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.

bb-Ricardo avatar Sep 25 '20 20:09 bb-Ricardo

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.

bb-Ricardo avatar Nov 06 '20 19:11 bb-Ricardo