Skip to content

Commit

Permalink
[ADD] Support for the EA inheritance support from DNS and Host Addres…
Browse files Browse the repository at this point in the history
…s into Host record.
  • Loading branch information
JkhatriInfobox committed Sep 24, 2024
1 parent d0debc5 commit 67fdd6d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
17 changes: 15 additions & 2 deletions plugins/module_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()):
Expand Down Expand Up @@ -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',
Expand Down
12 changes: 12 additions & 0 deletions plugins/modules/nios_host_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
)

Expand All @@ -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'),
Expand Down

0 comments on commit 67fdd6d

Please sign in to comment.