netbox icon indicating copy to clipboard operation
netbox copied to clipboard

Support both IPv4 and IPv6 "Primary IP" for devices

Open bellwood opened this issue 10 years ago • 8 comments

As the subject indicates, you cannot have both a v4 and v6 primary IP for a device.

Would be nice to have both =)

bellwood avatar Jun 29 '16 02:06 bellwood

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.

jeremystretch avatar Jun 29 '16 03:06 jeremystretch

I would suggest as the internet has done it for years.

if ipv6 exist use ipv6 first then followed by ipv4.

starlokii avatar Jun 29 '16 06:06 starlokii

Just thinking out loud, I see this as entailing three distinct migrations:

  1. Add fields primary_ip4 and primary_ip6 to the Device model.
  2. Copy the value of primary_ip to one or the other, depending on the address family of primary_ip, for all Devices (this is a data migration as opposed to a schema migration).
  3. Delete the primary_ip field 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.

jeremystretch avatar Jul 09 '16 15:07 jeremystretch

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.

MaXFalstein avatar Jul 11 '16 09:07 MaXFalstein

@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 avatar Aug 23 '16 21:08 LBegnaud

@LBegnaud please see:

https://github.com/digitalocean/netbox/blob/develop/netbox/extras/management/commands/run_inventory.py

That runs inventory for devices via RPC

bellwood avatar Aug 23 '16 22:08 bellwood

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.

jeremystretch avatar Aug 24 '16 01:08 jeremystretch

Neat. Thanks for the info!

LBegnaud avatar Aug 24 '16 13:08 LBegnaud