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

Add primary_ip by default #46

Closed
jjhidalgar opened this issue Jan 31, 2020 · 12 comments
Closed

Add primary_ip by default #46

jjhidalgar opened this issue Jan 31, 2020 · 12 comments

Comments

@jjhidalgar
Copy link

@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.

@synackray
Copy link
Owner

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!

@jjhidalgar
Copy link
Author

jjhidalgar commented Jan 31, 2020

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"

@synackray
Copy link
Owner

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!

@jjhidalgar
Copy link
Author

Thank you. Let me know if you want testing!

@synackray
Copy link
Owner

@jaimehrubiks I drafted up a method of setting the primary IP this weekend. Would you mind pulling the latest commit in 46-add-primary-ip and providing your feedback when you have a chance? Thanks!

@jjhidalgar
Copy link
Author

Great news! will give it a try tomorrow (in around 12 hours)

@jjhidalgar
Copy link
Author

jjhidalgar commented Feb 3, 2020

@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.

@synackray
Copy link
Owner

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 develop then. I would like to be certain not to break anything.

@jjhidalgar
Copy link
Author

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.

@synackray
Copy link
Owner

No worries. It's gone well on my side so far. I will likely promote to develop by the end of the week and then pass it to full regression testing. Thanks for all your help!

synackray added a commit that referenced this issue Feb 4, 2020
* Created functions for setting primary IP on NetBox hosts and VMs for #46

* Added primary ip comparison information message
@synackray
Copy link
Owner

Merged into develop.

@jjhidalgar
Copy link
Author

I tested it again. I works great. I have another issue that I'll put separately.

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

2 participants