Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] nios_adminuser module #280

Merged
merged 11 commits into from
Jan 10, 2025
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The `infoblox.nios_modules` collection has the following content:

- `nios_a_record` – Configure Infoblox NIOS A records
- `nios_aaaa_record` – Configure Infoblox NIOS AAAA records
- `nios_adminuser` – Configure Infoblox NIOS Adminuser
- `nios_cname_record` – Configure Infoblox NIOS CNAME records
- `nios_dns_view` – Configure Infoblox NIOS DNS views
- `nios_dtc_lbdn` – Configure Infoblox NIOS DTC LBDN records
Expand Down
42 changes: 26 additions & 16 deletions plugins/module_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
NIOS_DTC_TOPOLOGY = 'dtc:topology'
NIOS_EXTENSIBLE_ATTRIBUTE = 'extensibleattributedef'
NIOS_VLAN = 'vlan'
NIOS_ADMINUSER = 'adminuser'

NIOS_PROVIDER_SPEC = {
'host': dict(fallback=(env_fallback, ['INFOBLOX_HOST'])),
Expand Down Expand Up @@ -700,27 +701,29 @@ def compare_objects(self, current_object, proposed_object):
# If the lists are of a different length, the objects cannot be
# equal, and False will be returned before comparing the list items
# this code part will work for members' assignment
if (key in ('members', 'options', 'delegate_to', 'forwarding_servers', 'stub_members', 'vlans')

if (key in ('members', 'options', 'delegate_to', 'forwarding_servers', 'stub_members', 'ssh_keys', 'vlans')
and (len(proposed_item) != len(current_item))):
return False

# Validate the Sequence of the List data
if key in ('external_servers', 'list_values') and not self.verify_list_order(proposed_item, current_item):
return False

for subitem in proposed_item:
if current_item:
# Host IPv4addrs wont contain use_nextserver and nextserver
# If DHCP is false.
dhcp_flag = current_item[0].get('configure_for_dhcp', False)
use_nextserver = subitem.get('use_nextserver', False)
if key == 'ipv4addrs' and not dhcp_flag:
subitem.pop('use_nextserver', None)
subitem.pop('nextserver', None)
elif key == 'ipv4addrs' and dhcp_flag and not use_nextserver:
subitem.pop('nextserver', None)
if not self.issubset(subitem, current_item):
return False
if key == 'ipv4addrs':
for subitem in proposed_item:
if current_item:
# Host IPv4addrs wont contain use_nextserver and nextserver
# If DHCP is false.
dhcp_flag = current_item[0].get('configure_for_dhcp', False)
use_nextserver = subitem.get('use_nextserver', False)
if key == 'ipv4addrs' and not dhcp_flag:
subitem.pop('use_nextserver', None)
subitem.pop('nextserver', None)
elif key == 'ipv4addrs' and dhcp_flag and not use_nextserver:
subitem.pop('nextserver', None)
if not self.issubset(subitem, current_item):
return False

# If the lists are of a different length, the objects and order of element mismatch
# Ignore DHCP options while comparing due to extra num param is get response
Expand Down Expand Up @@ -770,6 +773,12 @@ def get_object_ref(self, module, ib_obj_type, obj_filter, ib_spec):
except TypeError:
name = obj_filter['name']

return_fields = list(ib_spec.keys())

if (ib_obj_type == NIOS_ADMINUSER):
if 'password' in return_fields:
return_fields.remove('password')

if old_name and new_name:
if (ib_obj_type == NIOS_HOST_RECORD):
# to check only by old_name if dns bypassing is set
Expand All @@ -793,7 +802,7 @@ def get_object_ref(self, module, ib_obj_type, obj_filter, ib_spec):
else:
test_obj_filter = dict([('name', old_name)])
# get the object reference
ib_obj = self.get_object(ib_obj_type, test_obj_filter, return_fields=list(ib_spec.keys()))
ib_obj = self.get_object(ib_obj_type, test_obj_filter, return_fields=return_fields)
if ib_obj:
obj_filter['name'] = new_name
elif old_ipv4addr_exists and (len(ib_obj) == 0):
Expand Down Expand Up @@ -864,7 +873,7 @@ def get_object_ref(self, module, ib_obj_type, obj_filter, ib_spec):
# check if test_obj_filter is empty copy passed obj_filter
else:
test_obj_filter = obj_filter
return_fields = list(ib_spec.keys())

if ib_obj_type == NIOS_HOST_RECORD:
ipv4addrs_return = [
'ipv4addrs.ipv4addr', 'ipv4addrs.mac', 'ipv4addrs.configure_for_dhcp', 'ipv4addrs.host',
Expand All @@ -875,6 +884,7 @@ def get_object_ref(self, module, ib_obj_type, obj_filter, ib_spec):
]
return_fields.extend(ipv4addrs_return)
return_fields.extend(ipv6addrs_return)

ib_obj = self.get_object(ib_obj_type, test_obj_filter.copy(), return_fields=return_fields)

# prevents creation of a new A record with 'new_ipv4addr' when A record with a particular 'old_ipv4addr' is not found
Expand Down
Loading
Loading