From f4a1c8a41e0104f87f45db97434661895678ee41 Mon Sep 17 00:00:00 2001 From: Jeenitkumar Khatri Date: Thu, 7 Dec 2023 17:07:11 +0530 Subject: [PATCH] Fixed BUGS for ENV Variables wapi_version and max_results BUG #198 BUG #185 --- plugins/doc_fragments/nios.py | 2 +- plugins/module_utils/api.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/plugins/doc_fragments/nios.py b/plugins/doc_fragments/nios.py index bd1f02ea..bbecf7a6 100644 --- a/plugins/doc_fragments/nios.py +++ b/plugins/doc_fragments/nios.py @@ -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 diff --git a/plugins/module_utils/api.py b/plugins/module_utils/api.py index 8962703c..3a586193 100644 --- a/plugins/module_utils/api.py +++ b/plugins/module_utils/api.py @@ -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'])) } @@ -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'] @@ -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 @@ -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: