From a4921cd5d9bf970bea05e2a653feb1c56efc1d6e Mon Sep 17 00:00:00 2001 From: Tim Rupp Date: Fri, 16 Nov 2018 20:43:46 -0800 Subject: [PATCH] Removes more f5-sdk references from f5 modules (#48771) --- lib/ansible/module_utils/network/f5/bigip.py | 37 ------------ .../modules/network/f5/_bigip_gtm_facts.py | 60 ++++++++++++++----- 2 files changed, 44 insertions(+), 53 deletions(-) diff --git a/lib/ansible/module_utils/network/f5/bigip.py b/lib/ansible/module_utils/network/f5/bigip.py index 75e4e72a145..5f8001f3323 100644 --- a/lib/ansible/module_utils/network/f5/bigip.py +++ b/lib/ansible/module_utils/network/f5/bigip.py @@ -7,15 +7,6 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type -import re - -try: - from f5.bigip import ManagementRoot - from icontrol.exceptions import iControlUnexpectedHTTPError - HAS_F5SDK = True -except ImportError: - HAS_F5SDK = False - try: from library.module_utils.network.f5.common import F5BaseClient from library.module_utils.network.f5.common import F5ModuleError @@ -26,34 +17,6 @@ except ImportError: from ansible.module_utils.network.f5.icontrol import iControlRestSession -class F5Client(F5BaseClient): - def __init__(self, *args, **kwargs): - super(F5Client, self).__init__(*args, **kwargs) - self.provider = self.merge_provider_params() - - @property - def api(self): - if self._client: - return self._client - - try: - result = ManagementRoot( - self.provider['server'], - self.provider['user'], - self.provider['password'], - port=self.provider['server_port'], - verify=self.provider['validate_certs'], - token='tmos' - ) - self._client = result - return self._client - except Exception as ex: - error = 'Unable to connect to {0} on port {1}. The reported error was "{2}".'.format( - self.provider['server'], self.provider['server_port'], str(ex) - ) - raise F5ModuleError(error) - - class F5RestClient(F5BaseClient): def __init__(self, *args, **kwargs): super(F5RestClient, self).__init__(*args, **kwargs) diff --git a/lib/ansible/modules/network/f5/_bigip_gtm_facts.py b/lib/ansible/modules/network/f5/_bigip_gtm_facts.py index 8e1f23bbecc..7603d3e3796 100644 --- a/lib/ansible/modules/network/f5/_bigip_gtm_facts.py +++ b/lib/ansible/modules/network/f5/_bigip_gtm_facts.py @@ -1,7 +1,7 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # -# Copyright (c) 2017 F5 Networks Inc. +# Copyright: (c) 2017, F5 Networks Inc. # GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function @@ -183,29 +183,56 @@ from ansible.module_utils.parsing.convert_bool import BOOLEANS_TRUE from distutils.version import LooseVersion try: - from library.module_utils.network.f5.bigip import HAS_F5SDK - from library.module_utils.network.f5.bigip import F5Client + from f5.bigip import ManagementRoot + from icontrol.exceptions import iControlUnexpectedHTTPError + from f5.utils.responses.handlers import Stats + HAS_F5SDK = True +except ImportError: + HAS_F5SDK = False + +try: + from library.module_utils.network.f5.common import F5BaseClient +except ImportError: + from ansible.module_utils.network.f5.common import F5BaseClient + +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 - try: - from library.module_utils.network.f5.common import iControlUnexpectedHTTPError - from f5.utils.responses.handlers import Stats - except ImportError: - HAS_F5SDK = False except ImportError: - from ansible.module_utils.network.f5.bigip import HAS_F5SDK - from ansible.module_utils.network.f5.bigip import F5Client 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 - try: - from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError - from f5.utils.responses.handlers import Stats - except ImportError: - HAS_F5SDK = False + + +class F5Client(F5BaseClient): + def __init__(self, *args, **kwargs): + super(F5Client, self).__init__(*args, **kwargs) + self.provider = self.merge_provider_params() + + @property + def api(self): + if self._client: + return self._client + + try: + result = ManagementRoot( + self.provider['server'], + self.provider['user'], + self.provider['password'], + port=self.provider['server_port'], + verify=self.provider['validate_certs'], + token='tmos' + ) + self._client = result + return self._client + except Exception as ex: + error = 'Unable to connect to {0} on port {1}. The reported error was "{2}".'.format( + self.provider['server'], self.provider['server_port'], str(ex) + ) + raise F5ModuleError(error) class BaseManager(object): @@ -946,8 +973,9 @@ def main(): if not HAS_F5SDK: module.fail_json(msg="The python f5-sdk module is required") + client = F5Client(**module.params) + try: - client = F5Client(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() cleanup_tokens(client)