From 6531777cbe9db043d249f12749ecc948b5b96273 Mon Sep 17 00:00:00 2001 From: Jeenitkumar Khatri <58591067+JkhatriInfobox@users.noreply.github.com> Date: Thu, 14 Nov 2024 15:56:34 +0530 Subject: [PATCH] Fixed Host record with IPV6 (#274) * [FIX] Updated return fields for Host record to fix unsupported use_nextserver fieild for Ipv6Host. * [FIX] Changed mac to duid for Host record IPv6. * [IMP] Normalize duid and added alias for configure_for_dhcp * [FIX] KeyError: 'ipv4addrs' for IPv6 Host Record. --- plugins/module_utils/api.py | 7 ++++--- plugins/modules/nios_host_record.py | 16 +++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/plugins/module_utils/api.py b/plugins/module_utils/api.py index 9a325ad6..41924dcb 100644 --- a/plugins/module_utils/api.py +++ b/plugins/module_utils/api.py @@ -530,7 +530,7 @@ def run(self, ib_obj_type, ib_spec): # 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(obj_type=str(res), return_fields=['ipv4addrs']) - if host_ref: + if host_ref and 'ipv4addrs' in host_ref: # Create a dictionary for quick lookups ref_dict = {obj['ipv4addr']: obj['_ref'] for obj in host_ref['ipv4addrs']} sorted_ipv4addrs = sorted(proposed_object['ipv4addrs'], key=lambda x: x.get('use_for_ea_inheritance', False)) @@ -655,6 +655,8 @@ def issubset(self, item, objects): # Normalize MAC address for comparison if 'mac' in item: item['mac'] = item['mac'].replace('-', ':').lower() + elif 'duid' in item: + item['duid'] = item['duid'].replace('-', ':').lower() if all(entry in obj.items() for entry in item.items()): return True else: @@ -864,8 +866,7 @@ def get_object_ref(self, module, ib_obj_type, obj_filter, ib_spec): 'ipv4addrs.nextserver', 'ipv4addrs.use_nextserver', 'ipv4addrs.use_for_ea_inheritance' ] ipv6addrs_return = [ - 'ipv6addrs.ipv6addr', 'ipv6addrs.duid', 'ipv6addrs.configure_for_dhcp', 'ipv6addrs.host', - 'ipv6addrs.use_nextserver', 'ipv6addrs.nextserver' + 'ipv6addrs.ipv6addr', 'ipv6addrs.duid', 'ipv6addrs.configure_for_dhcp', 'ipv6addrs.host' ] return_fields.extend(ipv4addrs_return) return_fields.extend(ipv6addrs_return) diff --git a/plugins/modules/nios_host_record.py b/plugins/modules/nios_host_record.py index a5ae78cf..d633ec7b 100644 --- a/plugins/modules/nios_host_record.py +++ b/plugins/modules/nios_host_record.py @@ -151,17 +151,19 @@ configure_for_dhcp: description: - Configure the host_record over DHCP instead of DNS, if user - changes it to true, user need to mention MAC address to configure. + changes it to true, user need to mention DUID address to configure. type: bool required: false - mac: + aliases: + - dhcp + duid: description: - - Configures the hardware MAC address for the host record. If user makes - DHCP to true, user need to mention MAC address. + - Configures the hardware DUID address for the host record. If user makes + DHCP to true, user need to mention DUID address. type: str required: false aliases: - - mac + - duid aliases: description: - Configures an optional list of additional aliases to add to the host @@ -415,8 +417,8 @@ def main(): ipv6addr_spec = dict( ipv6addr=dict(required=True, aliases=['address']), - configure_for_dhcp=dict(type='bool', required=False), - mac=dict(required=False) + configure_for_dhcp=dict(type='bool', required=False, aliases=['dhcp']), + duid=dict(required=False) ) ib_spec = dict(