[Feature]: primary_ip4 field returned by nb_inventory plugin should include netmask length
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
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.
Could it return the mask length in a separate attribute?
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).
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.