Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- Adds the ability to return ``primary_ip4_netmask`` for virtual machines in nb_inventory plugin.
13 changes: 13 additions & 0 deletions plugins/inventory/nb_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,13 @@ def extract_primary_ip4(self, host):
except Exception:
return

def extract_primary_ip4_netmask(self, host):
try:
address = host["primary_ip4"]["address"]
return str(ip_interface(address).netmask)
except Exception:
return

def extract_primary_ip6(self, host):
try:
address = host["primary_ip6"]["address"]
Expand Down Expand Up @@ -1938,6 +1945,12 @@ def _fill_host_variables(self, host, hostname):
if extracted_primary_ip4:
self._set_variable(hostname, "primary_ip4", extracted_primary_ip4)

extracted_primary_ip4_netmask = self.extract_primary_ip4_netmask(host=host)
if extracted_primary_ip4_netmask:
self._set_variable(
hostname, "primary_ip4_netmask", extracted_primary_ip4_netmask
)

extracted_primary_ip6 = self.extract_primary_ip6(host=host)
if extracted_primary_ip6:
self._set_variable(hostname, "primary_ip6", extracted_primary_ip6)
Expand Down