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

Added support for infoblox member object #53174

Merged
merged 17 commits into from
Mar 12, 2019
Merged
28 changes: 28 additions & 0 deletions lib/ansible/module_utils/net_tools/nios/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
NIOS_NEXT_AVAILABLE_IP = 'func:nextavailableip'
NIOS_IPV4_NETWORK_CONTAINER = 'networkcontainer'
NIOS_IPV6_NETWORK_CONTAINER = 'ipv6networkcontainer'
NIOS_MEMBER = 'member'

NIOS_PROVIDER_SPEC = {
'host': dict(fallback=(env_fallback, ['INFOBLOX_HOST'])),
Expand Down Expand Up @@ -136,6 +137,29 @@ def flatten_extattrs(value):
return dict([(k, v['value']) for k, v in iteritems(value)])


def member_normalize(member_spec):
''' Transforms the member module arguments into a valid WAPI struct
justjais marked this conversation as resolved.
Show resolved Hide resolved
This function will transform the arguments into a structure that
is a valid WAPI structure in the format of:
{
key: <value>,
}
It will remove any arguments that are set to None since WAPI will error on
that condition.
The remainder of the value validation is performed by WAPI
'''
for key in member_spec.keys():
if isinstance(member_spec[key], dict):
member_spec[key] = member_normalize(member_spec[key])
elif isinstance(member_spec[key], list):
for x in member_spec[key]:
if isinstance(x, dict):
x = member_normalize(x)
elif member_spec[key] is None:
del member_spec[key]
return member_spec


class WapiBase(object):
''' Base class for implementing Infoblox WAPI API '''
provider_spec = {'provider': dict(type='dict', options=NIOS_PROVIDER_SPEC)}
Expand Down Expand Up @@ -245,6 +269,10 @@ def run(self, ib_obj_type, ib_spec):
current_object = obj_filter
ref = None

# checks if the object type is member to normalize the attributes being passed
if (ib_obj_type == NIOS_MEMBER):
proposed_object = member_normalize(proposed_object)

# checks if the name's field has been updated
if update and new_name:
proposed_object['name'] = new_name
Expand Down