Skip to content

Commit

Permalink
[FIX] Updated default value of use_for_ea_inheritance to False and up…
Browse files Browse the repository at this point in the history
…dated validations.
  • Loading branch information
JkhatriInfobox committed Sep 26, 2024
1 parent 247e154 commit 98dec17
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions plugins/module_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,8 @@ def run(self, ib_obj_type, ib_spec):

check_remove = []
if (ib_obj_type == NIOS_HOST_RECORD):
if sum(addr.get('use_for_ea_inheritance', False) for addr in proposed_object['ipv4addrs']) > 1:
raise AnsibleError('Only one address allowed to be used for extensible attributes inheritance')
# this check is for idempotency, as if the same ip address shall be passed
# add param will be removed, and same exists true for remove case as well.
if 'ipv4addrs' in [current_object and proposed_object]:
Expand Down Expand Up @@ -510,7 +512,10 @@ def run(self, ib_obj_type, ib_spec):
result['changed'] = True
if not self.module.check_mode and res is None:
proposed_object = self.on_update(proposed_object, ib_spec)
res = self.update_object(ref, proposed_object)
# Remove 'use_for_ea_inheritance' from each dictionary in 'ipv4addrs'
update_proposed = {**proposed_object, 'ipv4addrs': [
{k: v for k, v in addr.items() if k != 'use_for_ea_inheritance'} for addr in proposed_object['ipv4addrs']]}
res = self.update_object(ref, update_proposed)
result['changed'] = True

if ib_obj_type == NIOS_HOST_RECORD and res:
Expand All @@ -521,7 +526,8 @@ def run(self, ib_obj_type, ib_spec):
if host_ref:
# Create a dictionary for quick lookups
ref_dict = {obj['ipv4addr']: obj['_ref'] for obj in host_ref['ipv4addrs']}
for proposed in proposed_object['ipv4addrs']:
sorted_ipv4addrs = sorted(proposed_object['ipv4addrs'], key=lambda x: x.get('use_for_ea_inheritance', False))
for proposed in sorted_ipv4addrs:
ipv4addr = proposed['ipv4addr']
if ipv4addr in ref_dict and 'use_for_ea_inheritance' in proposed:
self.update_object(ref_dict[ipv4addr], {'use_for_ea_inheritance': proposed['use_for_ea_inheritance']})
Expand Down
6 changes: 3 additions & 3 deletions plugins/modules/nios_host_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
use_for_ea_inheritance:
version_added: "1.7.0"
description:
- When use_for_ea_inheritance is True, the EA is inherited from Host address. The default value is True.
- When use_for_ea_inheritance is True, the EA is inherited from Host address. The default value is False.
type: bool
default: true
default: false
required: false
ipv4addr:
description:
Expand Down Expand Up @@ -378,7 +378,7 @@ def main():
add=dict(type='bool', required=False),
use_nextserver=dict(type='bool', required=False, aliases=['use_pxe']),
nextserver=dict(required=False, aliases=['pxe']),
use_for_ea_inheritance=dict(type='bool', required=False, default=True),
use_for_ea_inheritance=dict(type='bool', required=False, default=False),
remove=dict(type='bool', required=False)
)

Expand Down

0 comments on commit 98dec17

Please sign in to comment.