Support both IPv4 and IPv6 "Primary IP" for devices
As the subject indicates, you cannot have both a v4 and v6 primary IP for a device.
Would be nice to have both =)
Currently we use a single primary_ip field on Device to indicate which IP should be used to reach it. As you point out, this can be either IPv4 or IPv6, but not both.
We could replace this with primary_ip4 and primary_ip6, but then we need some way to decide which address family should be used. For instance, when NetBox reaches out to a device to gather inventory data, should it try IPv4 or IPv6 first? Is this answer the same for all devices?
Seems like it would be reasonable to create a PRIMARY_AF configuration variable to indicate whether IPv4 or IPv6 should be preferred, but I'm open to suggestions.
I would suggest as the internet has done it for years.
if ipv6 exist use ipv6 first then followed by ipv4.
Just thinking out loud, I see this as entailing three distinct migrations:
- Add fields
primary_ip4andprimary_ip6to the Device model. - Copy the value of
primary_ipto one or the other, depending on the address family ofprimary_ip, for all Devices (this is a data migration as opposed to a schema migration). - Delete the
primary_ipfield from the Device model.
The primary_ip field would become a property on Device which returns primary_ip6 if set, or falls back to primary_ip4.
Your last comment is exactly how this should be.
You could do this by keeping the existing variable and setting it to IPv6 or you could do it by finding out if IPv6 is set to anything and then trying that first or reverting to IPv4, again if set, if IPv6 is not supported on that device.
@jeremystretch can you comment on what you mean about "For instance, when NetBox reaches out to a device to gather inventory data"? I didn't think netbox was built for that kind of thing.
@LBegnaud please see:
https://github.com/digitalocean/netbox/blob/develop/netbox/extras/management/commands/run_inventory.py
That runs inventory for devices via RPC
Yeah, it's still a beta-level undocumented feature. It was a rushed implementation that needs more love and care before it can be deemed part of NetBox proper.
Neat. Thanks for the info!