Skip to content

Commit

Permalink
Fixed Host record with IPV6 (#274)
Browse files Browse the repository at this point in the history
* [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.
  • Loading branch information
JkhatriInfobox authored Nov 14, 2024
1 parent d15c4b6 commit 6531777
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
7 changes: 4 additions & 3 deletions plugins/module_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 9 additions & 7 deletions plugins/modules/nios_host_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 6531777

Please sign in to comment.