ansible_modules icon indicating copy to clipboard operation
ansible_modules copied to clipboard

[Feature]: primary_ip4 field returned by nb_inventory plugin should include netmask length

Open mkurjanski opened this issue 2 years ago • 4 comments

NetBox version

v3.4.2

Feature type

Change to existing Plugin

Proposed functionality

Currently nb_inventory returns primary_ip4 field after truncating the prefix length information. In my opinion more detailed information is better and the prefix length should be preserved.

Use case

Currently if I want to look up the primary ipv4 IP information from the host I have to run separate lookup calls to find the netmask information for that IP. If nb_inventory plugin returned this information by default that would remove the need for additional API calls.

External dependencies

No response

mkurjanski avatar Jan 26 '23 13:01 mkurjanski

I'm 👎 on this since it's really the prefix that the IP is associated with, where that information resides. Also changing this to add the prefix length to IP addresses would break any code that currently relies on there not being a prefix length included in the field.

sc68cal avatar Jan 29 '23 17:01 sc68cal

Could it return the mask length in a separate attribute?

noziwatele avatar Feb 09 '23 09:02 noziwatele

I don't agree with the comment the netmask length is only an attribute of a prefix and not the IP address. Netbox keeps the netmask info inside of the IPAddress model for a good reason. When you configure an IP on a device you always have to define the netmask with it.

In my view the nb_inventory plugin already returns the host IP without the subnet via the ansible_host var, which probably most of people use in their scripts. The primary_ip4 seems redundant to ansible_host var in this case. And the primary_ip4 returned from nb_inventory is inconsistent compared with what Netbox holds (IP with netmask).

mkurjanski avatar Feb 09 '23 12:02 mkurjanski

Stripping off the netmask from the IP is super easy. Re-adding it through additional netbox call per each IP is quite a lot of overhead.

mkurjanski avatar Feb 09 '23 12:02 mkurjanski