removes redundant functions (#53989)

This commit is contained in:
Wojciech Wypior 2019-03-20 15:44:41 +01:00 committed by John R Barker
parent e3b6a07f6e
commit 7592d486ed
3 changed files with 7 additions and 123 deletions

View file

@ -21,12 +21,6 @@ from ansible.module_utils.parsing.convert_bool import BOOLEANS_TRUE
from ansible.module_utils.parsing.convert_bool import BOOLEANS_FALSE
from collections import defaultdict
try:
from icontrol.exceptions import iControlUnexpectedHTTPError
HAS_F5SDK = True
except ImportError:
HAS_F5SDK = False
MANAGED_BY_ANNOTATION_VERSION = 'f5-ansible.version'
MANAGED_BY_ANNOTATION_MODIFIED = 'f5-ansible.last_modified'
@ -230,39 +224,6 @@ def flatten_boolean(value):
return 'no'
def cleanup_tokens(client=None):
# TODO(Remove this. No longer needed with iControlRestSession destructor)
if client is None:
return
try:
# isinstance cannot be used here because to import it creates a
# circular dependency with teh module_utils.network.f5.bigip file.
#
# TODO(consider refactoring cleanup_tokens)
if 'F5RestClient' in type(client).__name__:
token = client._client.headers.get('X-F5-Auth-Token', None)
if not token:
return
uri = "https://{0}:{1}/mgmt/shared/authz/tokens/{2}".format(
client.provider['server'],
client.provider['server_port'],
token
)
resp = client.api.delete(uri)
try:
resp.json()
except ValueError as ex:
raise F5ModuleError(str(ex))
return True
else:
resource = client.api.shared.authz.tokens_s.token.load(
name=client.api.icrs.token
)
resource.delete()
except Exception as ex:
pass
def is_cli(module):
transport = module.params['transport']
provider_transport = (module.params['provider'] or {}).get('transport')
@ -354,78 +315,12 @@ def transform_name(partition='', name='', sub_path=''):
return result
def compare_complex_list(want, have):
"""Performs a complex list comparison
A complex list is a list of dictionaries
Args:
want (list): List of dictionaries to compare with second parameter.
have (list): List of dictionaries compare with first parameter.
Returns:
bool:
"""
if want == [] and have is None:
return None
if want is None:
return None
w = []
h = []
for x in want:
tmp = [(str(k), str(v)) for k, v in iteritems(x)]
w += tmp
for x in have:
tmp = [(str(k), str(v)) for k, v in iteritems(x)]
h += tmp
if set(w) == set(h):
return None
else:
return want
def compare_dictionary(want, have):
"""Performs a dictionary comparison
Args:
want (dict): Dictionary to compare with second parameter.
have (dict): Dictionary to compare with first parameter.
Returns:
bool:
"""
if want == {} and have is None:
return None
if want is None:
return None
w = [(str(k), str(v)) for k, v in iteritems(want)]
h = [(str(k), str(v)) for k, v in iteritems(have)]
if set(w) == set(h):
return None
else:
return want
def is_ansible_debug(module):
if module._debug and module._verbosity >= 4:
return True
return False
def fail_json(module, ex, client=None):
# TODO(Remove this. No longer needed with iControlRestSession destructor)
if is_ansible_debug(module) and client:
module.fail_json(msg=str(ex), __f5debug__=client.api.debug_output)
module.fail_json(msg=str(ex))
def exit_json(module, results, client=None):
# TODO(Remove this. No longer needed with iControlRestSession destructor)
if is_ansible_debug(module) and client:
results['__f5debug__'] = client.api.debug_output
module.exit_json(**results)
def is_uuid(uuid=None):
"""Check to see if value is an F5 UUID

View file

@ -241,11 +241,8 @@ try:
from library.module_utils.network.f5.bigip import F5RestClient
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import fq_name
from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.common import exit_json
from library.module_utils.network.f5.common import fail_json
from library.module_utils.network.f5.icontrol import upload_file
from library.module_utils.network.f5.icontrol import tmos_version
from library.module_utils.network.f5.icontrol import module_provisioned
@ -253,11 +250,8 @@ except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import fq_name
from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.common import exit_json
from ansible.module_utils.network.f5.common import fail_json
from ansible.module_utils.network.f5.icontrol import upload_file
from ansible.module_utils.network.f5.icontrol import tmos_version
from ansible.module_utils.network.f5.icontrol import module_provisioned
@ -916,7 +910,8 @@ class BaseManager(object):
class ModuleManager(object):
def __init__(self, *args, **kwargs):
self.client = kwargs.get('client', None)
self.module = kwargs.get('module', None)
self.client = F5RestClient(**self.module.params)
self.kwargs = kwargs
def exec_module(self):
@ -946,8 +941,8 @@ class ModuleManager(object):
class V1Manager(BaseManager):
def __init__(self, *args, **kwargs):
client = kwargs.get('client', None)
module = kwargs.get('module', None)
client = F5RestClient(**module.params)
super(V1Manager, self).__init__(client=client, module=module)
self.want = V1Parameters(params=module.params, client=client)
@ -961,8 +956,8 @@ class V1Manager(BaseManager):
class V2Manager(BaseManager):
def __init__(self, *args, **kwargs):
client = kwargs.get('client', None)
module = kwargs.get('module', None)
client = F5RestClient(**module.params)
super(V2Manager, self).__init__(client=client, module=module)
self.want = V2Parameters(params=module.params, client=client)
@ -1055,13 +1050,11 @@ def main():
client = F5RestClient(**module.params)
try:
mm = ModuleManager(module=module, client=client)
mm = ModuleManager(module=module)
results = mm.exec_module()
cleanup_tokens(client)
exit_json(module, results, client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
fail_json(module, ex, client)
module.fail_json(msg=str(ex))
if __name__ == '__main__':

View file

@ -198,12 +198,10 @@ except ImportError:
try:
from library.module_utils.network.f5.common import F5ModuleError
from library.module_utils.network.f5.common import AnsibleF5Parameters
from library.module_utils.network.f5.common import cleanup_tokens
from library.module_utils.network.f5.common import f5_argument_spec
except ImportError:
from ansible.module_utils.network.f5.common import F5ModuleError
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
from ansible.module_utils.network.f5.common import cleanup_tokens
from ansible.module_utils.network.f5.common import f5_argument_spec
@ -978,10 +976,8 @@ def main():
try:
mm = ModuleManager(module=module, client=client)
results = mm.exec_module()
cleanup_tokens(client)
module.exit_json(**results)
except F5ModuleError as ex:
cleanup_tokens(client)
module.fail_json(msg=str(ex))