From 67fdd6d7f17cf3711ee2bdb3c877b87fe3a91ec3 Mon Sep 17 00:00:00 2001 From: Jeenitkumar Khatri Date: Tue, 24 Sep 2024 17:48:22 +0530 Subject: [PATCH] [ADD] Support for the EA inheritance support from DNS and Host Address into Host record. --- plugins/module_utils/api.py | 17 +++++++++++++++-- plugins/modules/nios_host_record.py | 12 ++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/api.py b/plugins/module_utils/api.py index 491f85d0..2c1ecf09 100644 --- a/plugins/module_utils/api.py +++ b/plugins/module_utils/api.py @@ -514,6 +514,19 @@ def run(self, ib_obj_type, ib_spec): self.update_object(ref, proposed_object) result['changed'] = True + if ib_obj_type == NIOS_HOST_RECORD and res: + # 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 and 'use_for_ea_inheritance' in proposed: + 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: @@ -628,7 +641,7 @@ def issubset(self, item, objects): ''' for obj in objects: if isinstance(item, dict): - # Normalize MAC address for comparission + # Normalize MAC address for comparison if 'mac' in item: item['mac'] = item['mac'].replace('-', ':').lower() if all(entry in obj.items() for entry in item.items()): @@ -837,7 +850,7 @@ def get_object_ref(self, module, ib_obj_type, obj_filter, ib_spec): if ib_obj_type == NIOS_HOST_RECORD: ipv4addrs_return = [ 'ipv4addrs.ipv4addr', 'ipv4addrs.mac', 'ipv4addrs.configure_for_dhcp', 'ipv4addrs.host', - 'ipv4addrs.nextserver', 'ipv4addrs.use_nextserver' + 'ipv4addrs.nextserver', 'ipv4addrs.use_nextserver', 'ipv4addrs.use_for_ea_inheritance' ] ipv6addrs_return = [ 'ipv6addrs.ipv6addr', 'ipv6addrs.duid', 'ipv6addrs.configure_for_dhcp', 'ipv6addrs.host', diff --git a/plugins/modules/nios_host_record.py b/plugins/modules/nios_host_record.py index 36ab331c..44ac1c98 100644 --- a/plugins/modules/nios_host_record.py +++ b/plugins/modules/nios_host_record.py @@ -66,6 +66,11 @@ required: true aliases: - address + use_dns_ea_inheritance: + description: + - When use_dns_ea_inheritance is True, the EA is inherited from associated zone. The default value is False. + type: bool + default: false configure_for_dhcp: description: - Configure the host_record over DHCP instead of DNS, if user @@ -135,6 +140,11 @@ required: true aliases: - address + use_dns_ea_inheritance: + description: + - When use_dns_ea_inheritance is True, the EA is inherited from associated zone. The default value is False. + type: bool + default: false configure_for_dhcp: description: - Configure the host_record over DHCP instead of DNS, if user @@ -365,6 +375,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), remove=dict(type='bool', required=False) ) @@ -381,6 +392,7 @@ def main(): ipv4addrs=dict(type='list', aliases=['ipv4'], elements='dict', options=ipv4addr_spec, transform=ipv4addrs), ipv6addrs=dict(type='list', aliases=['ipv6'], elements='dict', options=ipv6addr_spec, transform=ipv6addrs), configure_for_dns=dict(type='bool', default=True, required=False, aliases=['dns'], ib_req=True), + use_dns_ea_inheritance=dict(type='bool', default=False, required=False), aliases=dict(type='list', elements='str'), ttl=dict(type='int'),