Skip to content

Commit 735351d

Browse files
committed
Support wapi function call as payload of ipv4addr when creating a host record
1 parent 3f5025e commit 735351d

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

plugins/module_utils/api.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,8 @@ def run(self, ib_obj_type, ib_spec):
439439

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

443445
if state == 'present':
444446
if ref is None:
@@ -548,6 +550,23 @@ def check_if_nios_next_ip_exists(self, proposed_object):
548550

549551
return proposed_object
550552

553+
def check_if_ipv4addr_object_function_exists(self, proposed_object):
554+
''' Check if _object_function argument is passed in ipaddr
555+
while creating host record, if yes then format proposed object ipv4addrs
556+
to create hostrecord with next available ip in one call to avoid any race condition
557+
This format support the exclude parameters unlike nextavailableip
558+
It also supports DHCP ranges, dynamic selection of ranges and networks '''
559+
560+
if 'ipv4addrs' in proposed_object:
561+
for ipv4addr_payload in proposed_object['ipv4addrs']:
562+
if '_object_function' in ipv4addr_payload['ipv4addr']:
563+
ipv4addr_payload['ipv4addr'] = check_type_dict(ipv4addr_payload['ipv4addr'])
564+
elif 'ipv4addr' in proposed_object:
565+
if '_object_function' in proposed_object['ipv4addr']:
566+
proposed_object['ipv4addr'] = check_type_dict(proposed_object['ipv4addr'])
567+
568+
return proposed_object
569+
551570
def check_for_new_ipv4addr(self, proposed_object):
552571
''' Checks if new_ipv4addr parameter is passed in the argument
553572
while updating the record with new ipv4addr with static allocation'''
@@ -592,6 +611,8 @@ def check_next_ip_status(self, obj_filter):
592611
if 'ipv4addr' in obj_filter:
593612
if 'nios_next_ip' in obj_filter['ipv4addr']:
594613
return True
614+
if '_object_function' in obj_filter['ipv4addr'] and check_type_dict(obj_filter['ipv4addr'])['_object_function'] == 'next_available_ip':
615+
return True
595616
return False
596617

597618
def issubset(self, item, objects):

plugins/modules/nios_host_record.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
description:
6060
- Configures the IPv4 address for the host record. Users can dynamically
6161
allocate ipv4 address to host record by passing dictionary containing,
62-
I(nios_next_ip) and I(CIDR network range). If user wants to add or
62+
I(nios_next_ip) and I(CIDR network range). It supports _object_function
63+
calls to dynamic select an ipv4address from a network/dhcp-range and
64+
exclude a list of IPs from the selection. If user wants to add or
6365
remove the ipv4 address from existing record, I(add/remove)
6466
params need to be used. See examples.
6567
type: str
@@ -258,6 +260,29 @@
258260
password: admin
259261
connection: local
260262
263+
- name: >
264+
Dynamically add host record to next available ip in
265+
a network and excluding a list of IPs
266+
see https://ipam.illinois.edu/wapidoc/objects/record.host_ipv4addr.html
267+
infoblox.nios_modules.nios_host_record:
268+
name: host.ansible.com
269+
ipv4:
270+
- address:
271+
_object_function: next_available_ip
272+
_parameters:
273+
exclude: ['192.168.10.1', '192.168.10.2', '192.168.10.3'],
274+
_result_fields: ips
275+
_object: network
276+
_object_parameters:
277+
network: 192.168.10.0/24
278+
comment: this is a test comment
279+
state: present
280+
provider:
281+
host: "{{ inventory_hostname_short }}"
282+
username: admin
283+
password: admin
284+
connection: local
285+
261286
- name: Add ip to host record
262287
infoblox.nios_modules.nios_host_record:
263288
name: host.ansible.com

0 commit comments

Comments
 (0)