Skip to content

Commit

Permalink
Support wapi function call as payload of ipv4addr when creating a hos…
Browse files Browse the repository at this point in the history
…t record
  • Loading branch information
hmalphettes committed Jul 27, 2024
1 parent 3f5025e commit b1fbf71
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
21 changes: 21 additions & 0 deletions plugins/module_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,8 @@ def run(self, ib_obj_type, ib_spec):

# Checks if nios_next_ip param is passed in ipv4addrs/ipv4addr args
proposed_object = self.check_if_nios_next_ip_exists(proposed_object)
# Checks if a wapi function call is the payload of ipv4addrs/ipv4addr args
proposed_object = self.check_if_ipv4addr_object_function_exists(proposed_object)

if state == 'present':
if ref is None:
Expand Down Expand Up @@ -558,6 +560,23 @@ def check_for_new_ipv4addr(self, proposed_object):

return proposed_object

def check_if_ipv4addr_object_function_exists(self, proposed_object):
''' Check if _object_function argument is passed in ipaddr
while creating host record, if yes then format proposed object ipv4addrs
to create hostrecord with next available ip in one call to avoid any race condition
This format support the exclude parameters unlike nextavailableip
It also supports DHCP ranges, dynamic selection of ranges and networks '''

if 'ipv4addrs' in proposed_object:
for ipv4addr_payload in proposed_object['ipv4addrs']:
if '_object_function' in ipv4addr_payload['ipv4addr']:
ipv4addr_payload['ipv4addr'] = check_type_dict(ipv4addr_payload['ipv4addr'])
elif 'ipv4addr' in proposed_object:
if '_object_function' in proposed_object['ipv4addr']:
proposed_object['ipv4addr'] = check_type_dict(proposed_object['ipv4addr'])

return proposed_object

def check_if_add_remove_ip_arg_exists(self, proposed_object):
'''
This function shall check if add/remove param is set to true and
Expand Down Expand Up @@ -592,6 +611,8 @@ def check_next_ip_status(self, obj_filter):
if 'ipv4addr' in obj_filter:
if 'nios_next_ip' in obj_filter['ipv4addr']:
return True
if '_object_function' in obj_filter['ipv4addr'] and check_type_dict(obj_filter['ipv4addr'])['_object_function'] == 'next_available_ip':
return True
return False

def issubset(self, item, objects):
Expand Down
27 changes: 26 additions & 1 deletion plugins/modules/nios_host_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
description:
- Configures the IPv4 address for the host record. Users can dynamically
allocate ipv4 address to host record by passing dictionary containing,
I(nios_next_ip) and I(CIDR network range). If user wants to add or
I(nios_next_ip) and I(CIDR network range). It supports _object_function
calls to dynamic select an ipv4address from a network/dhcp-range and
exclude a list of IPs from the selection. If user wants to add or
remove the ipv4 address from existing record, I(add/remove)
params need to be used. See examples.
type: str
Expand Down Expand Up @@ -258,6 +260,29 @@
password: admin
connection: local
- name: >
Dynamically add host record to next available ip in
a network and excluding a list of IPs
see https://ipam.illinois.edu/wapidoc/objects/record.host_ipv4addr.html
infoblox.nios_modules.nios_host_record:
name: host.ansible.com
ipv4:
- address:
_object_function: next_available_ip
_parameters:
exclude: ['192.168.10.1', '192.168.10.2', '192.168.10.3'],
_result_fields: ips
_object: network
_object_parameters:
network: 192.168.10.0/24
comment: this is a test comment
state: present
provider:
host: "{{ inventory_hostname_short }}"
username: admin
password: admin
connection: local
- name: Add ip to host record
infoblox.nios_modules.nios_host_record:
name: host.ansible.com
Expand Down

0 comments on commit b1fbf71

Please sign in to comment.