Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bugs on Host Record #262

Merged
merged 2 commits into from
Sep 18, 2024
Merged
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
29 changes: 27 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,16 @@ def compare_objects(self, current_object, proposed_object):
return False

for subitem in proposed_item:
if current_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 +721,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 +833,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
Loading