-
Notifications
You must be signed in to change notification settings - Fork 29
Add primary_ip by default #46
Comments
Hi, @jaimehrubiks! This is a very fair ask. However, it is a bit of a challenge to accomplish. I remember looking at this originally and finding that vCenter does not designate a primary IP. Rather, it returns a list of all available. I want to be certain of that, so let me go back and check the data models for the VMware SDK. I'll let you know what I find. THanks! |
I understand. I do think that vCenter will never provide a "primary ip" because there is no such thing in the real world. What is a primary ip anyway? The one use to route traffic to the default internet (0.0.0.0)? The one used for management purposes? I think it is a matter of users' preferences. The problem here is to have a value directly mapped to the vm entry that can be used to easily get the server's IP address. That is why I was suggesting to use ANY of the ips in the list for such purpose (as normally, either there is only one, or any of those would work to do ssh). It could be optional, and configured through settings. Alternatively, a custom field or something else could be use to assign ips to VMs so that we can easily identify how to connect to a server. But the way it is now is less accessible, as a GET request to a VM using netbox' API will not give any IP information unless we set it on the "primary ip" |
I can most definitely offer an option to set one of the IPs as the primary. If I remember well vCenter always sets the first IP address in the list as the primary. Let me verify and try to create parity between the two. This logic will also need to make sure it accounts for the IPv4/6 allowed networks so an ignored IP is not accidentally qualified. That will require some more complex logic. Thanks for a fun challenge! |
Thank you. Let me know if you want testing! |
@jaimehrubiks I drafted up a method of setting the primary IP this weekend. Would you mind pulling the latest commit in |
Great news! will give it a try tomorrow (in around 12 hours) |
@synackray it worked once, when using a netbox instance which did already have devices and ip addresses. But this branch seems to fail in a fresh install, because it does not properly create virtual interfaces nor ip addresses at all. Let me get more details UPDATE: It worked this time. I need to do more testing, maybe it was a fail in my end. |
Very interesting. Thank you so much for your testing. I will also run this through a few cycles of fresh and mixed environment builds before promoting to |
I've been a little busy this week, that is why I couldn't test it as much as I wanted. I'll let you know when I run more tests. |
No worries. It's gone well on my side so far. I will likely promote to |
Merged into |
I tested it again. I works great. I have another issue that I'll put separately. |
@abhilashchinthalapudi also suggested it here but a new issue is a better place
I find that it would be very useful to have a primary IP for each VM set. I have tried to analyze the Netbox API but I could not find useful information. This feature is important because other tools that use Netbox as the single source of truth (like ansible dynamic inventory plugin) will be able to use this field to actually get the IP addresses.
I did not find a "is_primary" setting in the API, although some people talk about it here:
netbox-community/netbox#718
Ideally, any IP available within any interface in a VM could be set to be the primary_ip. Normally, only one IP (ipv4) is available in the majority of the cases, so in the scenario where two are available, we could set any of them.
Of course, this is a proposal, I don't know if owner likes this idea. If it looks good I'm willing to help or test.
The text was updated successfully, but these errors were encountered: