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

[IMP] optimise the code and validation checks. #283

Merged
merged 1 commit into from
Jan 20, 2025
Merged
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
33 changes: 22 additions & 11 deletions plugins/module_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,18 +710,29 @@ def compare_objects(self, current_object, proposed_object):
if key in ('external_servers', 'list_values') and not self.verify_list_order(proposed_item, current_item):
return False

if key == 'ipv4addrs':
if key == 'ipv4addrs' and current_item and isinstance(current_item[0], dict) and proposed_item:
current_config = current_item[0]
dhcp_flag = current_config.get('configure_for_dhcp', 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 isinstance(subitem, dict):
continue # Skip non-dict items
# Host IPv4addrs wont contain use_nextserver and nextserver
# If DHCP is false.
use_nextserver = subitem.get('use_nextserver', False)

if not dhcp_flag:
try:
subitem.pop('use_nextserver')
subitem.pop('nextserver')
except KeyError:
pass
elif dhcp_flag and not use_nextserver:
try:
subitem.pop('nextserver')
except KeyError:
pass

if not self.issubset(subitem, current_item):
return False

Expand Down
Loading