Skip to content

Commit

Permalink
[FIX] NPA-167: Fix re-run of Host Record with nextserver
Browse files Browse the repository at this point in the history
[FIX] NPA-173: Fix host record PXE server with alias naming
[FIX] NPA-174: FIX re-run of HOST Record with MAC
  • Loading branch information
JkhatriInfobox committed Sep 17, 2024
1 parent 844c264 commit bf646b8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
28 changes: 26 additions & 2 deletions plugins/module_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,9 @@ def issubset(self, item, objects):
'''
for obj in objects:
if isinstance(item, dict):
# Normalize MAC address for comparission
if 'mac' in item:
item['mac'] = item['mac'].replace('-', ':').lower()
if all(entry in obj.items() for entry in item.items()):
return True
else:
Expand Down Expand Up @@ -675,6 +678,15 @@ def compare_objects(self, current_object, proposed_object):
return False

for subitem in proposed_item:
# Host IPv4addrs wont contain use_nextserver and nextserver
# If DHCP is false.
dhcp_flag = current_item[0].get('configure_for_dhcp', False)
use_nextserver = subitem.get('use_nextserver', False)
if key == 'ipv4addrs' and not dhcp_flag:
subitem.pop('use_nextserver', None)
subitem.pop('nextserver', None)
elif key == 'ipv4addrs' and dhcp_flag and not use_nextserver:
subitem.pop('nextserver', None)
if not self.issubset(subitem, current_item):
return False

Expand Down Expand Up @@ -708,7 +720,6 @@ def compare_objects(self, current_object, proposed_object):

def get_object_ref(self, module, ib_obj_type, obj_filter, ib_spec):
''' this function gets the reference object of pre-existing nios objects '''

update = False
old_name = new_name = None
old_ipv4addr_exists = old_text_exists = False
Expand Down Expand Up @@ -821,7 +832,20 @@ def get_object_ref(self, module, ib_obj_type, obj_filter, ib_spec):
# check if test_obj_filter is empty copy passed obj_filter
else:
test_obj_filter = obj_filter
ib_obj = self.get_object(ib_obj_type, test_obj_filter.copy(), return_fields=list(ib_spec.keys()))
return_fields = list(ib_spec.keys())
if ib_obj_type == NIOS_HOST_RECORD:
ipv4addrs_return = [
'ipv4addrs.ipv4addr', 'ipv4addrs.mac', 'ipv4addrs.configure_for_dhcp', 'ipv4addrs.host',
'ipv4addrs.nextserver', 'ipv4addrs.use_nextserver'
]
ipv6addrs_return = [
'ipv6addrs.ipv6addr', 'ipv6addrs.duid', 'ipv6addrs.configure_for_dhcp', 'ipv6addrs.host',
'ipv6addrs.use_nextserver', 'ipv6addrs.nextserver'
]
return_fields.extend(ipv4addrs_return)
return_fields.extend(ipv6addrs_return)

ib_obj = self.get_object(ib_obj_type, test_obj_filter.copy(), return_fields=return_fields)

# prevents creation of a new A record with 'new_ipv4addr' when A record with a particular 'old_ipv4addr' is not found
if old_ipv4addr_exists and (ib_obj is None or len(ib_obj) == 0):
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/nios_host_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def ipaddr(module, key, filtered_keys=None):


def ipv4addrs(module):
return ipaddr(module, 'ipv4addrs', filtered_keys=['address', 'dhcp'])
return ipaddr(module, 'ipv4addrs', filtered_keys=['address', 'dhcp', 'pxe', 'use_pxe'])


def ipv6addrs(module):
Expand Down

0 comments on commit bf646b8

Please sign in to comment.