Skip to content
This repository has been archived by the owner on Jan 8, 2021. It is now read-only.

Sync Virtual Machine network names #100

Open
Haeki opened this issue Apr 29, 2020 · 6 comments
Open

Sync Virtual Machine network names #100

Haeki opened this issue Apr 29, 2020 · 6 comments

Comments

@Haeki
Copy link

Haeki commented Apr 29, 2020

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
Copy link
Author

Haeki commented Apr 29, 2020

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

@synackray
Copy link
Owner

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.

@Haeki
Copy link
Author

Haeki commented May 6, 2020

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

@synackray
Copy link
Owner

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!

@bb-Ricardo
Copy link

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
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants