Skip to content

Commit

Permalink
Fix/dtc objects (infobloxopen#209)
Browse files Browse the repository at this point in the history
* Fixed LBDN and Pool Object for transform fields
[FIX] LBDN: auth_zone and pool field
[FIX] POOL: servers and monitors field

* Fixed BUGS for ENV Variables wapi_version and max_results

BUG infobloxopen#198
BUG infobloxopen#185

* Resolve Issue infobloxopen#116
[ADD] Version to infoblox-client in requirement.txt
  • Loading branch information
JkhatriInfobox authored Dec 12, 2023
1 parent 02fda4e commit eca5194
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion plugins/doc_fragments/nios.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ModuleDocFragment(object):
wapi_version:
description:
- Specifies the version of WAPI to use
- Value can also be specified using C(INFOBLOX_WAP_VERSION) environment
- Value can also be specified using C(INFOBLOX_WAPI_VERSION) environment
variable.
- Until ansible 2.8 the default WAPI was 1.4
type: str
Expand Down
16 changes: 9 additions & 7 deletions plugins/module_utils/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@
'http_pool_connections': dict(type='int', default=10),
'http_pool_maxsize': dict(type='int', default=10),
'max_retries': dict(type='int', default=3, fallback=(env_fallback, ['INFOBLOX_MAX_RETRIES'])),
'wapi_version': dict(default='2.9', fallback=(env_fallback, ['INFOBLOX_WAP_VERSION'])),
'max_results': dict(type='int', default=1000, fallback=(env_fallback, ['INFOBLOX_MAX_RETRIES']))
'wapi_version': dict(default='2.9', fallback=(env_fallback, ['INFOBLOX_WAPI_VERSION'])),
'max_results': dict(type='int', default=1000, fallback=(env_fallback, ['INFOBLOX_MAX_RESULTS']))
}


Expand Down Expand Up @@ -120,7 +120,12 @@ def get_connector(*args, **kwargs):
# explicitly set
env = ('INFOBLOX_%s' % key).upper()
if env in os.environ:
kwargs[key] = os.environ.get(env)
if NIOS_PROVIDER_SPEC[key].get('type') == 'bool':
kwargs[key] = eval(os.environ.get(env).title())
elif NIOS_PROVIDER_SPEC[key].get('type') == 'int':
kwargs[key] = eval(os.environ.get(env))
else:
kwargs[key] = os.environ.get(env)

if 'validate_certs' in kwargs.keys():
kwargs['ssl_verify'] = kwargs['validate_certs']
Expand Down Expand Up @@ -755,7 +760,7 @@ def get_object_ref(self, module, ib_obj_type, obj_filter, ib_spec):
test_obj_filter['text'] = txt

# removing Port param from get params for NIOS_DTC_MONITOR_TCP
if (ib_obj_type == NIOS_DTC_MONITOR_TCP):
elif (ib_obj_type == NIOS_DTC_MONITOR_TCP):
test_obj_filter = dict([('name', obj_filter['name'])])

# check if test_obj_filter is empty copy passed obj_filter
Expand All @@ -779,9 +784,6 @@ def get_object_ref(self, module, ib_obj_type, obj_filter, ib_spec):
except TypeError:
ipaddr = obj_filter['ipv4addr']
test_obj_filter['ipv4addr'] = ipaddr
# prevents creation of a new A record with 'new_ipv4addr' when A record with a particular 'old_ipv4addr' is not found
if old_ipv4addr_exists and ib_obj is None:
raise Exception("A Record with ipv4addr: '%s' is not found" % (ipaddr))
ib_obj = self.get_object(ib_obj_type, test_obj_filter.copy(), return_fields=list(ib_spec.keys()))
# prevents creation of a new A record with 'new_ipv4addr' when A record with a particular 'old_ipv4addr' is not found
if old_ipv4addr_exists and ib_obj is None:
Expand Down
4 changes: 2 additions & 2 deletions plugins/modules/nios_dtc_lbdn.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def auth_zones_transform(module):
for zone in module.params['auth_zones']:
zone_obj = wapi.get_object('zone_auth',
{'fqdn': zone})
if zone_obj is not None:
if zone_obj:
zone_list.append(zone_obj[0]['_ref'])
else:
module.fail_json(
Expand All @@ -194,7 +194,7 @@ def pools_transform(module):
{'name': pool['pool']})
if 'ratio' not in pool:
pool['ratio'] = 1
if pool_obj is not None:
if pool_obj:
pool_list.append({'pool': pool_obj[0]['_ref'],
'ratio': pool['ratio']})
else:
Expand Down
9 changes: 7 additions & 2 deletions plugins/modules/nios_dtc_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ def servers_transform(module):
for server in module.params['servers']:
server_obj = wapi.get_object('dtc:server',
{'name': server['server']})
if server_obj is not None:
if server_obj:
server_list.append({'server': server_obj[0]['_ref'],
'ratio': server['ratio']})
else:
module.fail_json(msg='Server %s cannot be found.' % server)
return server_list

def monitors_transform(module):
Expand All @@ -187,8 +189,11 @@ def monitors_transform(module):
for monitor in module.params['monitors']:
monitor_obj = wapi.get_object('dtc:monitor:' + monitor['type'],
{'name': monitor['name']})
if monitor_obj is not None:
if monitor_obj:
monitor_list.append(monitor_obj[0]['_ref'])
else:
module.fail_json(
msg='monitor %s cannot be found.' % monitor)
return monitor_list

def topology_transform(module):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
infoblox-client
infoblox-client==0.6.0

0 comments on commit eca5194

Please sign in to comment.