Skip to content

Commit

Permalink
[ADD] Support added for flag use_for_ea_inheritance in ipv4addrs host…
Browse files Browse the repository at this point in the history
… record.
  • Loading branch information
JkhatriInfobox committed Sep 17, 2024
1 parent b288ce3 commit 464b17f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
27 changes: 25 additions & 2 deletions plugins/module_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,21 @@ 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)
self.update_object(ref, proposed_object)
res = self.update_object(ref, proposed_object)
result['changed'] = True

if ib_obj_type == NIOS_HOST_RECORD:
# WAPI always reset the use_for_ea_inheritance for each update operation
# Handle use_for_ea_inheritance flag changes for IPv4addr in a host record
# Fetch the updated reference of host to avoid drift.
host_ref = self.connector.get_object(res)

# Create a dictionary for quick lookups
ref_dict = {obj['ipv4addr']: obj['_ref'] for obj in host_ref['ipv4addrs']}
for proposed in proposed_object['ipv4addrs']:
ipv4addr = proposed['ipv4addr']
if ipv4addr in ref_dict:
self.update_object(ref_dict[ipv4addr], {'use_for_ea_inheritance': proposed['use_for_ea_inheritance']})
elif state == 'absent':
if ref is not None:
if 'ipv4addrs' in proposed_object:
Expand Down Expand Up @@ -607,6 +619,9 @@ def issubset(self, item, objects):
'''
for obj in objects:
if isinstance(item, dict):
# Normalize MAC address
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 @@ -786,7 +801,15 @@ 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.use_for_ea_inheritance', 'ipv4addrs.ipv4addr', 'ipv4addrs.mac', 'ipv4addrs.configure_for_dhcp', 'ipv4addrs.host']
ipv6addrs_return = ['ipv6addrs.use_for_ea_inheritance', 'ipv6addrs.ipv6addr', 'ipv6addrs.duid', 'ipv6addrs.configure_for_dhcp', 'ipv6addrs.host']
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
9 changes: 8 additions & 1 deletion plugins/modules/nios_host_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
required: true
aliases:
- address
use_for_ea_inheritance:
description:
- Set this to True when using this host address for EA inheritance.
The default value is False.
type: bool
required: false
configure_for_dhcp:
description:
- Configure the host_record over DHCP instead of DNS, if user
Expand Down Expand Up @@ -347,7 +353,8 @@ def main():
add=dict(type='bool', required=False),
use_nextserver=dict(type='bool', required=False, aliases=['use_pxe']),
nextserver=dict(required=False, aliases=['pxe']),
remove=dict(type='bool', required=False)
remove=dict(type='bool', required=False),
use_for_ea_inheritance=dict(type='bool', required=False)
)

ipv6addr_spec = dict(
Expand Down

0 comments on commit 464b17f

Please sign in to comment.