From e6190524248ef2747c70e5c04377e78eb63e4d76 Mon Sep 17 00:00:00 2001 From: Tim Rupp Date: Thu, 13 Sep 2018 15:26:17 -0400 Subject: [PATCH] Fixes multiple lgtm issues (#45629) Most of the issues were just inclusions of code that were not used. This cleans those up. Other alerts were semi-false-positives for now --- .../module_utils/network/f5/compare.py | 21 ++ .../modules/network/f5/bigip_cli_alias.py | 4 +- .../modules/network/f5/bigip_cli_script.py | 6 +- .../modules/network/f5/bigip_data_group.py | 6 - .../modules/network/f5/bigip_device_auth.py | 4 +- .../modules/network/f5/bigip_device_dns.py | 4 +- .../modules/network/f5/bigip_device_group.py | 2 +- .../modules/network/f5/bigip_device_httpd.py | 2 + .../network/f5/bigip_device_license.py | 8 - .../modules/network/f5/bigip_device_ntp.py | 4 +- .../modules/network/f5/bigip_device_sshd.py | 2 +- .../network/f5/bigip_firewall_address_list.py | 2 - .../network/f5/bigip_firewall_dos_profile.py | 4 +- .../network/f5/bigip_firewall_policy.py | 4 +- .../network/f5/bigip_firewall_rule_list.py | 4 +- .../modules/network/f5/bigip_gtm_global.py | 5 +- .../network/f5/bigip_gtm_monitor_bigip.py | 6 +- .../network/f5/bigip_gtm_monitor_firepass.py | 2 +- .../network/f5/bigip_gtm_monitor_http.py | 2 +- .../network/f5/bigip_log_destination.py | 28 +- .../modules/network/f5/bigip_log_publisher.py | 14 +- .../modules/network/f5/bigip_monitor_http.py | 2 - .../modules/network/f5/bigip_monitor_https.py | 2 - .../network/f5/bigip_monitor_snmp_dca.py | 2 - .../modules/network/f5/bigip_monitor_tcp.py | 2 - .../network/f5/bigip_monitor_tcp_echo.py | 4 - .../network/f5/bigip_monitor_tcp_half_open.py | 4 - lib/ansible/modules/network/f5/bigip_node.py | 2 + .../modules/network/f5/bigip_pool_member.py | 245 +++++++++++------- .../f5/bigip_profile_persistence_src_addr.py | 4 +- .../modules/network/f5/bigip_provision.py | 2 - .../modules/network/f5/bigip_qkview.py | 3 +- .../modules/network/f5/bigip_remote_role.py | 5 +- .../modules/network/f5/bigip_static_route.py | 4 +- .../modules/network/f5/bigip_sys_global.py | 1 - .../modules/network/f5/bigip_timer_policy.py | 2 - lib/ansible/modules/network/f5/bigip_trunk.py | 17 +- lib/ansible/modules/network/f5/bigip_user.py | 5 - .../network/f5/bigip_virtual_server.py | 14 +- lib/ansible/modules/network/f5/bigip_vlan.py | 40 ++- 40 files changed, 255 insertions(+), 239 deletions(-) create mode 100644 lib/ansible/module_utils/network/f5/compare.py diff --git a/lib/ansible/module_utils/network/f5/compare.py b/lib/ansible/module_utils/network/f5/compare.py new file mode 100644 index 0000000000..cbe920f6ac --- /dev/null +++ b/lib/ansible/module_utils/network/f5/compare.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# +# 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 +__metaclass__ = type + + +def cmp_simple_list(want, have): + if want is None: + return None + if have is None and want == '': + return None + if have is not None and want == '': + return [] + if have is None: + return want + if set(want) != set(have): + return want + return None diff --git a/lib/ansible/modules/network/f5/bigip_cli_alias.py b/lib/ansible/modules/network/f5/bigip_cli_alias.py index f8e8e06b2e..ca648f1c87 100644 --- a/lib/ansible/modules/network/f5/bigip_cli_alias.py +++ b/lib/ansible/modules/network/f5/bigip_cli_alias.py @@ -90,7 +90,6 @@ 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 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 @@ -100,7 +99,6 @@ 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 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 @@ -411,8 +409,10 @@ def main(): client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() + cleanup_tokens(client) exit_json(module, results, client) except F5ModuleError as ex: + cleanup_tokens(client) fail_json(module, ex, client) diff --git a/lib/ansible/modules/network/f5/bigip_cli_script.py b/lib/ansible/modules/network/f5/bigip_cli_script.py index c4dd7cc18d..b8ffef9cf6 100644 --- a/lib/ansible/modules/network/f5/bigip_cli_script.py +++ b/lib/ansible/modules/network/f5/bigip_cli_script.py @@ -95,7 +95,6 @@ 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 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 @@ -105,7 +104,6 @@ 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 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 @@ -401,7 +399,7 @@ class ModuleManager(object): if resp.status == 200: return True - def read_current_from_device(self): + def read_current_from_device(self): # lgtm [py/similar-function] uri = "https://{0}:{1}/mgmt/tm/cli/script/{2}".format( self.client.provider['server'], self.client.provider['server_port'], @@ -454,8 +452,10 @@ def main(): client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() + cleanup_tokens(client) exit_json(module, results, client) except F5ModuleError as ex: + cleanup_tokens(client) fail_json(module, ex, client) diff --git a/lib/ansible/modules/network/f5/bigip_data_group.py b/lib/ansible/modules/network/f5/bigip_data_group.py index 4fb605f68b..b9c88bdca4 100644 --- a/lib/ansible/modules/network/f5/bigip_data_group.py +++ b/lib/ansible/modules/network/f5/bigip_data_group.py @@ -267,10 +267,7 @@ try: from library.module_utils.network.f5.common import cleanup_tokens from library.module_utils.network.f5.common import compare_complex_list from library.module_utils.network.f5.common import f5_argument_spec - from library.module_utils.network.f5.ipaddress import is_valid_ip - from library.module_utils.network.f5.ipaddress import is_valid_ip_network from library.module_utils.network.f5.ipaddress import is_valid_ip_interface - from library.module_utils.compat.ipaddress import ip_address from library.module_utils.compat.ipaddress import ip_network from library.module_utils.compat.ipaddress import ip_interface try: @@ -285,10 +282,7 @@ except ImportError: from ansible.module_utils.network.f5.common import cleanup_tokens from ansible.module_utils.network.f5.common import compare_complex_list from ansible.module_utils.network.f5.common import f5_argument_spec - from ansible.module_utils.network.f5.ipaddress import is_valid_ip - from ansible.module_utils.network.f5.ipaddress import is_valid_ip_network from ansible.module_utils.network.f5.ipaddress import is_valid_ip_interface - from ansible.module_utils.compat.ipaddress import ip_address from ansible.module_utils.compat.ipaddress import ip_network from ansible.module_utils.compat.ipaddress import ip_interface try: diff --git a/lib/ansible/modules/network/f5/bigip_device_auth.py b/lib/ansible/modules/network/f5/bigip_device_auth.py index 2c4cb313bf..cd21b93abf 100644 --- a/lib/ansible/modules/network/f5/bigip_device_auth.py +++ b/lib/ansible/modules/network/f5/bigip_device_auth.py @@ -210,7 +210,6 @@ 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 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 @@ -219,7 +218,6 @@ 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 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 @@ -796,8 +794,10 @@ def main(): client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() + cleanup_tokens(client) exit_json(module, results, client) except F5ModuleError as ex: + cleanup_tokens(client) fail_json(module, ex, client) diff --git a/lib/ansible/modules/network/f5/bigip_device_dns.py b/lib/ansible/modules/network/f5/bigip_device_dns.py index e1aec2ce54..92ac4eb65e 100644 --- a/lib/ansible/modules/network/f5/bigip_device_dns.py +++ b/lib/ansible/modules/network/f5/bigip_device_dns.py @@ -206,7 +206,7 @@ class ModuleManager(object): self.have = None self.changes = Parameters() - def _update_changed_options(self): + def _update_changed_options(self): # lgtm [py/similar-function] changed = {} for key in Parameters.updatables: if getattr(self.want, key) is not None: @@ -219,7 +219,7 @@ class ModuleManager(object): return True return False - def exec_module(self): + def exec_module(self): # lgtm [py/similar-function] changed = False result = dict() state = self.want.state diff --git a/lib/ansible/modules/network/f5/bigip_device_group.py b/lib/ansible/modules/network/f5/bigip_device_group.py index a7f5529468..37d8c01253 100644 --- a/lib/ansible/modules/network/f5/bigip_device_group.py +++ b/lib/ansible/modules/network/f5/bigip_device_group.py @@ -378,7 +378,7 @@ class ModuleManager(object): if changed: self.changes = UsableChanges(params=changed) - def _update_changed_options(self): + def _update_changed_options(self): # lgtm [py/similar-function] changed = {} for key in Parameters.updatables: if getattr(self.want, key) is not None: diff --git a/lib/ansible/modules/network/f5/bigip_device_httpd.py b/lib/ansible/modules/network/f5/bigip_device_httpd.py index bf333118ca..bc7f70853d 100644 --- a/lib/ansible/modules/network/f5/bigip_device_httpd.py +++ b/lib/ansible/modules/network/f5/bigip_device_httpd.py @@ -688,8 +688,10 @@ def main(): client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() + cleanup_tokens(client) exit_json(module, results, client) except F5ModuleError as ex: + cleanup_tokens(client) fail_json(module, ex, client) diff --git a/lib/ansible/modules/network/f5/bigip_device_license.py b/lib/ansible/modules/network/f5/bigip_device_license.py index cd6f016b91..ad6278285c 100644 --- a/lib/ansible/modules/network/f5/bigip_device_license.py +++ b/lib/ansible/modules/network/f5/bigip_device_license.py @@ -83,11 +83,9 @@ RETURN = r''' ''' from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.urls import open_url from ansible.module_utils.six import iteritems import re -import sys import time import xml.etree.ElementTree @@ -97,11 +95,8 @@ 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 fq_name from library.module_utils.network.f5.common import f5_argument_spec from library.module_utils.network.f5.icontrol import iControlRestSession - from library.module_utils.network.f5.icontrol import Request - from library.module_utils.network.f5.icontrol import Response try: from library.module_utils.network.f5.common import iControlUnexpectedHTTPError from f5.sdk_exception import UtilError @@ -113,11 +108,8 @@ 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 fq_name from ansible.module_utils.network.f5.common import f5_argument_spec from ansible.module_utils.network.f5.icontrol import iControlRestSession - from ansible.module_utils.network.f5.icontrol import Request - from ansible.module_utils.network.f5.icontrol import Response try: from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError from f5.sdk_exception import UtilError diff --git a/lib/ansible/modules/network/f5/bigip_device_ntp.py b/lib/ansible/modules/network/f5/bigip_device_ntp.py index a5bd49da90..ff39940c1d 100644 --- a/lib/ansible/modules/network/f5/bigip_device_ntp.py +++ b/lib/ansible/modules/network/f5/bigip_device_ntp.py @@ -139,7 +139,7 @@ class ModuleManager(object): self.want = Parameters(params=self.module.params) self.changes = Parameters() - def _update_changed_options(self): + def _update_changed_options(self): # lgtm [py/similar-function] changed = {} for key in Parameters.updatables: if getattr(self.want, key) is not None: @@ -165,7 +165,7 @@ class ModuleManager(object): return True return False - def exec_module(self): + def exec_module(self): # lgtm [py/similar-function] changed = False result = dict() state = self.want.state diff --git a/lib/ansible/modules/network/f5/bigip_device_sshd.py b/lib/ansible/modules/network/f5/bigip_device_sshd.py index 5f8511f250..c2f533ef7c 100644 --- a/lib/ansible/modules/network/f5/bigip_device_sshd.py +++ b/lib/ansible/modules/network/f5/bigip_device_sshd.py @@ -249,7 +249,7 @@ class ModuleManager(object): self.want = ModuleParameters(params=self.module.params) self.changes = UsableChanges() - def _update_changed_options(self): + def _update_changed_options(self): # lgtm [py/similar-function] changed = {} for key in Parameters.updatables: if getattr(self.want, key) is not None: diff --git a/lib/ansible/modules/network/f5/bigip_firewall_address_list.py b/lib/ansible/modules/network/f5/bigip_firewall_address_list.py index d157a735b4..173e24d938 100644 --- a/lib/ansible/modules/network/f5/bigip_firewall_address_list.py +++ b/lib/ansible/modules/network/f5/bigip_firewall_address_list.py @@ -165,7 +165,6 @@ try: from library.module_utils.compat.ipaddress import ip_interface from library.module_utils.network.f5.ipaddress import is_valid_ip from library.module_utils.network.f5.ipaddress import is_valid_ip_interface - from library.module_utils.network.f5.ipaddress import is_valid_ip_network try: from library.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: @@ -182,7 +181,6 @@ except ImportError: from ansible.module_utils.compat.ipaddress import ip_interface from ansible.module_utils.network.f5.ipaddress import is_valid_ip from ansible.module_utils.network.f5.ipaddress import is_valid_ip_interface - from ansible.module_utils.network.f5.ipaddress import is_valid_ip_network try: from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: diff --git a/lib/ansible/modules/network/f5/bigip_firewall_dos_profile.py b/lib/ansible/modules/network/f5/bigip_firewall_dos_profile.py index a3580706fa..da33d1e9c2 100644 --- a/lib/ansible/modules/network/f5/bigip_firewall_dos_profile.py +++ b/lib/ansible/modules/network/f5/bigip_firewall_dos_profile.py @@ -364,7 +364,7 @@ class ModuleManager(object): return True raise F5ModuleError(resp.content) - def read_current_from_device(self): + def read_current_from_device(self): # lgtm [py/similar-function] uri = "https://{0}:{1}/mgmt/tm/security/dos/profile/{2}".format( self.client.provider['server'], self.client.provider['server_port'], @@ -420,8 +420,10 @@ def main(): client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() + cleanup_tokens(client) exit_json(module, results, client) except F5ModuleError as ex: + cleanup_tokens(client) fail_json(module, ex, client) diff --git a/lib/ansible/modules/network/f5/bigip_firewall_policy.py b/lib/ansible/modules/network/f5/bigip_firewall_policy.py index 5ece6620ce..cbd775d682 100644 --- a/lib/ansible/modules/network/f5/bigip_firewall_policy.py +++ b/lib/ansible/modules/network/f5/bigip_firewall_policy.py @@ -89,7 +89,6 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import env_fallback try: - from library.module_utils.network.f5.bigip import HAS_F5SDK 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 @@ -99,7 +98,6 @@ try: from library.module_utils.network.f5.common import exit_json from library.module_utils.network.f5.common import transform_name except ImportError: - from ansible.module_utils.network.f5.bigip import HAS_F5SDK 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 @@ -527,8 +525,10 @@ def main(): client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() + cleanup_tokens(client) exit_json(module, results, client) except F5ModuleError as ex: + cleanup_tokens(client) fail_json(module, ex, client) diff --git a/lib/ansible/modules/network/f5/bigip_firewall_rule_list.py b/lib/ansible/modules/network/f5/bigip_firewall_rule_list.py index 26f7f3b68a..0a05f80f90 100644 --- a/lib/ansible/modules/network/f5/bigip_firewall_rule_list.py +++ b/lib/ansible/modules/network/f5/bigip_firewall_rule_list.py @@ -89,7 +89,6 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import env_fallback try: - from library.module_utils.network.f5.bigip import HAS_F5SDK 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 @@ -99,7 +98,6 @@ try: from library.module_utils.network.f5.common import exit_json from library.module_utils.network.f5.common import transform_name except ImportError: - from ansible.module_utils.network.f5.bigip import HAS_F5SDK 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 @@ -527,8 +525,10 @@ def main(): client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() + cleanup_tokens(client) exit_json(module, results, client) except F5ModuleError as ex: + cleanup_tokens(client) fail_json(module, ex, client) diff --git a/lib/ansible/modules/network/f5/bigip_gtm_global.py b/lib/ansible/modules/network/f5/bigip_gtm_global.py index fef2af4d9b..4838adb9f4 100644 --- a/lib/ansible/modules/network/f5/bigip_gtm_global.py +++ b/lib/ansible/modules/network/f5/bigip_gtm_global.py @@ -75,7 +75,6 @@ synchronize_zone_files: ''' from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.basic import env_fallback try: from library.module_utils.network.f5.bigip import HAS_F5SDK @@ -83,7 +82,6 @@ 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 fq_name from library.module_utils.network.f5.common import f5_argument_spec try: from library.module_utils.network.f5.common import iControlUnexpectedHTTPError @@ -95,7 +93,6 @@ 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 fq_name from ansible.module_utils.network.f5.common import f5_argument_spec try: from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError @@ -251,7 +248,7 @@ class ModuleManager(object): return True return False - def exec_module(self): + def exec_module(self): # lgtm [py/similar-function] result = dict() try: diff --git a/lib/ansible/modules/network/f5/bigip_gtm_monitor_bigip.py b/lib/ansible/modules/network/f5/bigip_gtm_monitor_bigip.py index e2e317d84e..7c86192618 100644 --- a/lib/ansible/modules/network/f5/bigip_gtm_monitor_bigip.py +++ b/lib/ansible/modules/network/f5/bigip_gtm_monitor_bigip.py @@ -304,7 +304,7 @@ class ModuleParameters(Parameters): return result @property - def ip(self): + def ip(self): # lgtm [py/similar-function] if self._values['ip'] is None: return None if self._values['ip'] in ['*', '0.0.0.0']: @@ -424,7 +424,7 @@ class ModuleManager(object): if changed: self.changes = UsableChanges(params=changed) - def _update_changed_options(self): + def _update_changed_options(self): # lgtm [py/similar-function] diff = Difference(self.want, self.have) updatables = Parameters.updatables changed = dict() @@ -439,7 +439,7 @@ class ModuleManager(object): return True return False - def _announce_deprecations(self): + def _announce_deprecations(self): # lgtm [py/similar-function] warnings = [] if self.want: warnings += self.want._values.get('__warnings', []) diff --git a/lib/ansible/modules/network/f5/bigip_gtm_monitor_firepass.py b/lib/ansible/modules/network/f5/bigip_gtm_monitor_firepass.py index 780a4ed4f4..eab466a90a 100644 --- a/lib/ansible/modules/network/f5/bigip_gtm_monitor_firepass.py +++ b/lib/ansible/modules/network/f5/bigip_gtm_monitor_firepass.py @@ -344,7 +344,7 @@ class ModuleParameters(Parameters): return int(self._values['timeout']) @property - def ip(self): + def ip(self): # lgtm [py/similar-function] if self._values['ip'] is None: return None if self._values['ip'] in ['*', '0.0.0.0']: diff --git a/lib/ansible/modules/network/f5/bigip_gtm_monitor_http.py b/lib/ansible/modules/network/f5/bigip_gtm_monitor_http.py index 0dd9594f88..cd5a07dd9f 100644 --- a/lib/ansible/modules/network/f5/bigip_gtm_monitor_http.py +++ b/lib/ansible/modules/network/f5/bigip_gtm_monitor_http.py @@ -370,7 +370,7 @@ class ModuleParameters(Parameters): return int(self._values['timeout']) @property - def ip(self): + def ip(self): # lgtm [py/similar-function] if self._values['ip'] is None: return None if self._values['ip'] in ['*', '0.0.0.0']: diff --git a/lib/ansible/modules/network/f5/bigip_log_destination.py b/lib/ansible/modules/network/f5/bigip_log_destination.py index d8d6b1b28c..c98efca519 100644 --- a/lib/ansible/modules/network/f5/bigip_log_destination.py +++ b/lib/ansible/modules/network/f5/bigip_log_destination.py @@ -362,21 +362,6 @@ class BaseManager(object): def __init__(self, *args, **kwargs): self.module = kwargs.get('module', None) self.client = kwargs.get('client', None) - self.want = self.get_module_params(params=self.module.params) - self.have = self.get_api_params() - self.changes = self.get_usable_changes() - - def get_usable_changes(self, params=None): - pass - - def get_api_params(self, params=None): - pass - - def get_module_params(self, params=None): - pass - - def get_reportable_changes(self, params=None): - pass def _set_changed_options(self): changed = {} @@ -482,6 +467,13 @@ class V1Manager(BaseManager): """Manages remote-syslog settings """ + + def __init__(self, *args, **kwargs): + super(V1Manager, self).__init__(*args, **kwargs) + self.want = self.get_module_params(params=self.module.params) + self.have = self.get_api_params() + self.changes = self.get_usable_changes() + def _validate_creation_parameters(self): if self.want.syslog_format is None: self.want.update({'syslog_format': 'bsd-syslog'}) @@ -560,6 +552,12 @@ class V2Manager(BaseManager): """Manages remote-high-speed-log settings """ + def __init__(self, *args, **kwargs): + super(V2Manager, self).__init__(*args, **kwargs) + self.want = self.get_module_params(params=self.module.params) + self.have = self.get_api_params() + self.changes = self.get_usable_changes() + def get_reportable_changes(self, params=None): if params: return V2ReportableChanges(params=params) diff --git a/lib/ansible/modules/network/f5/bigip_log_publisher.py b/lib/ansible/modules/network/f5/bigip_log_publisher.py index cbb4223b5a..1216ae0181 100644 --- a/lib/ansible/modules/network/f5/bigip_log_publisher.py +++ b/lib/ansible/modules/network/f5/bigip_log_publisher.py @@ -85,6 +85,7 @@ try: 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.compare import cmp_simple_list try: from library.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: @@ -97,6 +98,7 @@ except ImportError: 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.compare import cmp_simple_list try: from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: @@ -193,16 +195,8 @@ class Difference(object): @property def destinations(self): - if self.want.destinations is None: - return None - if self.have.destinations is None and self.want.destinations == '': - return None - if self.have.destinations is not None and self.want.destinations == '': - return [] - if self.have.destinations is None: - return self.want.destinations - if set(self.want.destinations) != set(self.have.destinations): - return self.want.destinations + result = cmp_simple_list(self.want.destinations, self.have.destinations) + return result class ModuleManager(object): diff --git a/lib/ansible/modules/network/f5/bigip_monitor_http.py b/lib/ansible/modules/network/f5/bigip_monitor_http.py index bd990ccef0..dc494c2d2b 100644 --- a/lib/ansible/modules/network/f5/bigip_monitor_http.py +++ b/lib/ansible/modules/network/f5/bigip_monitor_http.py @@ -183,7 +183,6 @@ try: 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 transform_name - from library.module_utils.network.f5.common import flatten_boolean 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.ipaddress import is_valid_ip @@ -195,7 +194,6 @@ except ImportError: 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 transform_name - from ansible.module_utils.network.f5.common import flatten_boolean 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.ipaddress import is_valid_ip diff --git a/lib/ansible/modules/network/f5/bigip_monitor_https.py b/lib/ansible/modules/network/f5/bigip_monitor_https.py index 0f61d6810e..83347597c2 100644 --- a/lib/ansible/modules/network/f5/bigip_monitor_https.py +++ b/lib/ansible/modules/network/f5/bigip_monitor_https.py @@ -171,7 +171,6 @@ try: 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 transform_name - from library.module_utils.network.f5.common import flatten_boolean 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.ipaddress import is_valid_ip @@ -184,7 +183,6 @@ except ImportError: 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 transform_name - from ansible.module_utils.network.f5.common import flatten_boolean 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.common import f5_argument_spec diff --git a/lib/ansible/modules/network/f5/bigip_monitor_snmp_dca.py b/lib/ansible/modules/network/f5/bigip_monitor_snmp_dca.py index 084f35b091..286ee1a529 100644 --- a/lib/ansible/modules/network/f5/bigip_monitor_snmp_dca.py +++ b/lib/ansible/modules/network/f5/bigip_monitor_snmp_dca.py @@ -236,7 +236,6 @@ try: 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 transform_name - from library.module_utils.network.f5.common import flatten_boolean from library.module_utils.network.f5.common import exit_json from library.module_utils.network.f5.common import fail_json @@ -248,7 +247,6 @@ except ImportError: 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 transform_name - from ansible.module_utils.network.f5.common import flatten_boolean from ansible.module_utils.network.f5.common import exit_json from ansible.module_utils.network.f5.common import fail_json diff --git a/lib/ansible/modules/network/f5/bigip_monitor_tcp.py b/lib/ansible/modules/network/f5/bigip_monitor_tcp.py index cabfc740fe..3b678ed493 100644 --- a/lib/ansible/modules/network/f5/bigip_monitor_tcp.py +++ b/lib/ansible/modules/network/f5/bigip_monitor_tcp.py @@ -179,7 +179,6 @@ try: 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 transform_name - from library.module_utils.network.f5.common import flatten_boolean 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.ipaddress import is_valid_ip @@ -192,7 +191,6 @@ except ImportError: 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 transform_name - from ansible.module_utils.network.f5.common import flatten_boolean 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.ipaddress import is_valid_ip diff --git a/lib/ansible/modules/network/f5/bigip_monitor_tcp_echo.py b/lib/ansible/modules/network/f5/bigip_monitor_tcp_echo.py index 724c28d290..d92f4ea731 100644 --- a/lib/ansible/modules/network/f5/bigip_monitor_tcp_echo.py +++ b/lib/ansible/modules/network/f5/bigip_monitor_tcp_echo.py @@ -148,10 +148,8 @@ 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 fq_name from library.module_utils.network.f5.common import f5_argument_spec from library.module_utils.network.f5.common import transform_name - from library.module_utils.network.f5.common import flatten_boolean 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.ipaddress import is_valid_ip @@ -160,10 +158,8 @@ 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 fq_name from ansible.module_utils.network.f5.common import f5_argument_spec from ansible.module_utils.network.f5.common import transform_name - from ansible.module_utils.network.f5.common import flatten_boolean 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.ipaddress import is_valid_ip diff --git a/lib/ansible/modules/network/f5/bigip_monitor_tcp_half_open.py b/lib/ansible/modules/network/f5/bigip_monitor_tcp_half_open.py index 4762493b28..6f0bce54fe 100644 --- a/lib/ansible/modules/network/f5/bigip_monitor_tcp_half_open.py +++ b/lib/ansible/modules/network/f5/bigip_monitor_tcp_half_open.py @@ -165,10 +165,8 @@ 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 fq_name from library.module_utils.network.f5.common import f5_argument_spec from library.module_utils.network.f5.common import transform_name - from library.module_utils.network.f5.common import flatten_boolean 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.ipaddress import is_valid_ip @@ -177,10 +175,8 @@ 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 fq_name from ansible.module_utils.network.f5.common import f5_argument_spec from ansible.module_utils.network.f5.common import transform_name - from ansible.module_utils.network.f5.common import flatten_boolean 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.ipaddress import is_valid_ip diff --git a/lib/ansible/modules/network/f5/bigip_node.py b/lib/ansible/modules/network/f5/bigip_node.py index 9fa725e8b5..ec65a407c8 100644 --- a/lib/ansible/modules/network/f5/bigip_node.py +++ b/lib/ansible/modules/network/f5/bigip_node.py @@ -1103,8 +1103,10 @@ def main(): client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() + cleanup_tokens(client) exit_json(module, results, client) except F5ModuleError as ex: + cleanup_tokens(client) fail_json(module, ex, client) diff --git a/lib/ansible/modules/network/f5/bigip_pool_member.py b/lib/ansible/modules/network/f5/bigip_pool_member.py index 155b629ccc..79ad0ac6ea 100644 --- a/lib/ansible/modules/network/f5/bigip_pool_member.py +++ b/lib/ansible/modules/network/f5/bigip_pool_member.py @@ -264,37 +264,32 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import env_fallback try: - from library.module_utils.network.f5.bigip import HAS_F5SDK - from library.module_utils.network.f5.bigip import F5Client + 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 is_valid_hostname + from library.module_utils.network.f5.common import cleanup_tokens + from library.module_utils.network.f5.common import transform_name + 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.common import f5_argument_spec + from library.module_utils.network.f5.common import is_valid_hostname from library.module_utils.network.f5.ipaddress import is_valid_ip - from library.module_utils.network.f5.ipaddress import validate_ip_address from library.module_utils.network.f5.ipaddress import validate_ip_v6_address - try: - from library.module_utils.network.f5.common import iControlUnexpectedHTTPError - 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.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 cleanup_tokens + from ansible.module_utils.network.f5.common import transform_name + 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.common import f5_argument_spec from ansible.module_utils.network.f5.common import is_valid_hostname from ansible.module_utils.network.f5.common import f5_argument_spec from ansible.module_utils.network.f5.ipaddress import is_valid_ip - from ansible.module_utils.network.f5.ipaddress import validate_ip_address from ansible.module_utils.network.f5.ipaddress import validate_ip_v6_address - try: - from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError - except ImportError: - HAS_F5SDK = False class Parameters(AnsibleF5Parameters): @@ -306,17 +301,17 @@ class Parameters(AnsibleF5Parameters): api_attributes = [ 'rateLimit', 'connectionLimit', 'description', 'ratio', 'priorityGroup', - 'address', 'fqdn', 'session', 'state' + 'address', 'fqdn', 'session', 'state', ] returnables = [ 'rate_limit', 'connection_limit', 'description', 'ratio', 'priority_group', - 'fqdn_auto_populate', 'session', 'state', 'fqdn', 'address' + 'fqdn_auto_populate', 'session', 'state', 'fqdn', 'address', ] updatables = [ 'rate_limit', 'connection_limit', 'description', 'ratio', 'priority_group', - 'fqdn_auto_populate', 'state' + 'fqdn_auto_populate', 'state', ] @@ -573,13 +568,10 @@ class ModuleManager(object): result = dict() state = self.want.state - try: - if state in ['present', 'present', 'enabled', 'disabled', 'forced_offline']: - changed = self.present() - elif state == "absent": - changed = self.absent() - except iControlUnexpectedHTTPError as e: - raise F5ModuleError(str(e)) + if state in ['present', 'present', 'enabled', 'disabled', 'forced_offline']: + changed = self.present() + elif state == "absent": + changed = self.absent() reportable = ReportableChanges(params=self.changes.to_return()) changes = reportable.to_return() @@ -603,25 +595,53 @@ class ModuleManager(object): return self.create() def exists(self): - try: - pool = self.client.api.tm.ltm.pools.pool.load( - name=self.want.pool, - partition=self.want.partition - ) - except Exception as ex: - raise F5ModuleError('The specified pool does not exist') - result = pool.members_s.members.exists( - name=self.want.full_name, - partition=self.want.partition + if not self.pool_exist(): + F5ModuleError('The specified pool does not exist') + + uri = "https://{0}:{1}/mgmt/tm/ltm/pool/{2}/members/{3}".format( + self.client.provider['server'], + self.client.provider['server_port'], + transform_name(self.want.partition, self.want.pool), + transform_name(self.want.partition, self.want.full_name) ) - return result + resp = self.client.api.get(uri) + try: + response = resp.json() + except ValueError: + return False + if resp.status == 404 or 'code' in response and response['code'] == 404: + return False + return True + + def pool_exist(self): + uri = "https://{0}:{1}/mgmt/tm/ltm/pool/{2}".format( + self.client.provider['server'], + self.client.provider['server_port'], + transform_name(self.want.partition, self.want.pool) + ) + resp = self.client.api.get(uri) + try: + response = resp.json() + except ValueError: + return False + if resp.status == 404 or 'code' in response and response['code'] == 404: + return False + return True def node_exists(self): - resource = self.client.api.tm.ltm.nodes.node.exists( - name=self.want.node_name, - partition=self.want.partition + uri = "https://{0}:{1}/mgmt/tm/ltm/node/{2}".format( + self.client.provider['server'], + self.client.provider['server_port'], + transform_name(self.want.partition, self.want.node_name) ) - return resource + resp = self.client.api.get(uri) + try: + response = resp.json() + except ValueError: + return False + if resp.status == 404 or 'code' in response and response['code'] == 404: + return False + return True def update(self): self.have = self.read_current_from_device() @@ -711,27 +731,47 @@ class ModuleManager(object): def create_on_device(self): params = self.changes.api_params() - pool = self.client.api.tm.ltm.pools.pool.load( - name=self.want.pool, - partition=self.want.partition - ) - pool.members_s.members.create( - name=self.want.full_name, - partition=self.want.partition, - **params + params['name'] = self.want.full_name + params['partition'] = self.want.partition + uri = "https://{0}:{1}/mgmt/tm/ltm/pool/{2}/members".format( + self.client.provider['server'], + self.client.provider['server_port'], + transform_name(self.want.partition, self.want.pool), + ) + resp = self.client.api.post(uri, json=params) + try: + response = resp.json() + except ValueError as ex: + raise F5ModuleError(str(ex)) + + if 'code' in response and response['code'] in [400, 403]: + if 'message' in response: + raise F5ModuleError(response['message']) + else: + raise F5ModuleError(resp.content) + return response['selfLink'] def update_on_device(self): params = self.changes.api_params() - pool = self.client.api.tm.ltm.pools.pool.load( - name=self.want.pool, - partition=self.want.partition + uri = "https://{0}:{1}/mgmt/tm/ltm/pool/{2}/members/{3}".format( + self.client.provider['server'], + self.client.provider['server_port'], + transform_name(self.want.partition, self.want.pool), + transform_name(self.want.partition, self.want.full_name) + ) - resource = pool.members_s.members.load( - name=self.want.full_name, - partition=self.want.partition - ) - resource.modify(**params) + resp = self.client.api.patch(uri, json=params) + try: + response = resp.json() + except ValueError as ex: + raise F5ModuleError(str(ex)) + + if 'code' in response and response['code'] == 400: + if 'message' in response: + raise F5ModuleError(response['message']) + else: + raise F5ModuleError(resp.content) def absent(self): if self.exists(): @@ -741,42 +781,68 @@ class ModuleManager(object): return False def remove_from_device(self): - pool = self.client.api.tm.ltm.pools.pool.load( - name=self.want.pool, - partition=self.want.partition + uri = "https://{0}:{1}/mgmt/tm/ltm/pool/{2}/members/{3}".format( + self.client.provider['server'], + self.client.provider['server_port'], + transform_name(self.want.partition, self.want.pool), + transform_name(self.want.partition, self.want.full_name) + ) - resource = pool.members_s.members.load( - name=self.want.full_name, - partition=self.want.partition - ) - if resource: - resource.delete() + response = self.client.api.delete(uri) + if response.status == 200: + return True + raise F5ModuleError(response.content) def remove_node_from_device(self): - resource = self.client.api.tm.ltm.nodes.node.load( - name=self.want.node_name, - partition=self.want.partition + uri = "https://{0}:{1}/mgmt/tm/ltm/node/{2}".format( + self.client.provider['server'], + self.client.provider['server_port'], + transform_name(self.want.partition, self.want.node_name) ) - if resource: - resource.delete() + response = self.client.api.delete(uri) + if response.status == 200: + return True + raise F5ModuleError(response.content) def read_current_from_device(self): - pool = self.client.api.tm.ltm.pools.pool.load( - name=self.want.pool, - partition=self.want.partition + uri = "https://{0}:{1}/mgmt/tm/ltm/pool/{2}/members/{3}".format( + self.client.provider['server'], + self.client.provider['server_port'], + transform_name(self.want.partition, self.want.pool), + transform_name(self.want.partition, self.want.full_name) + ) - resource = pool.members_s.members.load( - name=self.want.full_name, - partition=self.want.partition - ) - return ApiParameters(params=resource.attrs) + resp = self.client.api.get(uri) + try: + response = resp.json() + except ValueError as ex: + raise F5ModuleError(str(ex)) + + if 'code' in response and response['code'] == 400: + if 'message' in response: + raise F5ModuleError(response['message']) + else: + raise F5ModuleError(resp.content) + return ApiParameters(params=response) def read_current_node_from_device(self, node): - resource = self.client.api.tm.ltm.nodes.node.load( - name=node, - partition=self.want.partition + uri = "https://{0}:{1}/mgmt/tm/ltm/node/{2}".format( + self.client.provider['server'], + self.client.provider['server_port'], + transform_name(self.want.partition, node) ) - return NodeApiParameters(params=resource.attrs) + resp = self.client.api.get(uri) + try: + response = resp.json() + except ValueError as ex: + raise F5ModuleError(str(ex)) + + if 'code' in response and response['code'] == 400: + if 'message' in response: + raise F5ModuleError(response['message']) + else: + raise F5ModuleError(resp.content) + return NodeApiParameters(params=response) class ArgumentSpec(object): @@ -823,20 +889,19 @@ def main(): module = AnsibleModule( argument_spec=spec.argument_spec, - supports_check_mode=spec.supports_check_mode + supports_check_mode=spec.supports_check_mode, ) - if not HAS_F5SDK: - module.fail_json(msg="The python f5-sdk module is required") + + client = F5RestClient(**module.params) try: - client = F5Client(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() cleanup_tokens(client) - module.exit_json(**results) + exit_json(module, results, client) except F5ModuleError as ex: cleanup_tokens(client) - module.fail_json(msg=str(ex)) + fail_json(module, ex, client) if __name__ == '__main__': diff --git a/lib/ansible/modules/network/f5/bigip_profile_persistence_src_addr.py b/lib/ansible/modules/network/f5/bigip_profile_persistence_src_addr.py index 91c28f38d6..ee49e9adc8 100644 --- a/lib/ansible/modules/network/f5/bigip_profile_persistence_src_addr.py +++ b/lib/ansible/modules/network/f5/bigip_profile_persistence_src_addr.py @@ -124,7 +124,6 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import env_fallback try: - from library.module_utils.network.f5.bigip import HAS_F5SDK 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 @@ -136,7 +135,6 @@ try: from library.module_utils.network.f5.common import exit_json from library.module_utils.network.f5.common import fail_json except ImportError: - from ansible.module_utils.network.f5.bigip import HAS_F5SDK 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 @@ -557,8 +555,10 @@ def main(): client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() + cleanup_tokens(client) exit_json(module, results, client) except F5ModuleError as ex: + cleanup_tokens(client) fail_json(module, ex, client) diff --git a/lib/ansible/modules/network/f5/bigip_provision.py b/lib/ansible/modules/network/f5/bigip_provision.py index 73beae6106..63506cb38b 100644 --- a/lib/ansible/modules/network/f5/bigip_provision.py +++ b/lib/ansible/modules/network/f5/bigip_provision.py @@ -117,7 +117,6 @@ try: try: from library.module_utils.network.f5.common import iControlUnexpectedHTTPError from f5.bigip.contexts import TransactionContextManager - from f5.sdk_exception import LazyAttributesRequired except ImportError: HAS_F5SDK = False except ImportError: @@ -130,7 +129,6 @@ except ImportError: try: from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError from f5.bigip.contexts import TransactionContextManager - from f5.sdk_exception import LazyAttributesRequired except ImportError: HAS_F5SDK = False diff --git a/lib/ansible/modules/network/f5/bigip_qkview.py b/lib/ansible/modules/network/f5/bigip_qkview.py index 55e4dc4e77..23054c8e47 100644 --- a/lib/ansible/modules/network/f5/bigip_qkview.py +++ b/lib/ansible/modules/network/f5/bigip_qkview.py @@ -95,7 +95,6 @@ import socket import time from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.six import string_types from distutils.version import LooseVersion try: @@ -582,8 +581,10 @@ def main(): client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() + cleanup_tokens(client) exit_json(module, results, client) except F5ModuleError as ex: + cleanup_tokens(client) fail_json(module, ex, client) diff --git a/lib/ansible/modules/network/f5/bigip_remote_role.py b/lib/ansible/modules/network/f5/bigip_remote_role.py index ce880aaa20..d32a888395 100644 --- a/lib/ansible/modules/network/f5/bigip_remote_role.py +++ b/lib/ansible/modules/network/f5/bigip_remote_role.py @@ -144,7 +144,6 @@ remote_access: ''' from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.basic import env_fallback from ansible.module_utils.six import iteritems try: @@ -152,7 +151,6 @@ 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 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 @@ -163,7 +161,6 @@ 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 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 @@ -547,8 +544,10 @@ def main(): client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() + cleanup_tokens(client) exit_json(module, results, client) except F5ModuleError as ex: + cleanup_tokens(client) fail_json(module, ex, client) diff --git a/lib/ansible/modules/network/f5/bigip_static_route.py b/lib/ansible/modules/network/f5/bigip_static_route.py index 484af8d846..e223fe3194 100644 --- a/lib/ansible/modules/network/f5/bigip_static_route.py +++ b/lib/ansible/modules/network/f5/bigip_static_route.py @@ -166,7 +166,6 @@ try: from library.module_utils.network.f5.ipaddress import ipv6_netmask_to_cidr from library.module_utils.compat.ipaddress import ip_address from library.module_utils.compat.ipaddress import ip_network - from library.module_utils.compat.ipaddress import ip_interface except ImportError: from ansible.module_utils.network.f5.bigip import F5RestClient from ansible.module_utils.network.f5.common import F5ModuleError @@ -181,7 +180,6 @@ except ImportError: from ansible.module_utils.network.f5.ipaddress import ipv6_netmask_to_cidr from ansible.module_utils.compat.ipaddress import ip_address from ansible.module_utils.compat.ipaddress import ip_network - from ansible.module_utils.compat.ipaddress import ip_interface class Parameters(AnsibleF5Parameters): @@ -684,8 +682,10 @@ def main(): client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() + cleanup_tokens(client) exit_json(module, results, client) except F5ModuleError as ex: + cleanup_tokens(client) fail_json(module, ex, client) diff --git a/lib/ansible/modules/network/f5/bigip_sys_global.py b/lib/ansible/modules/network/f5/bigip_sys_global.py index 0d7a45bb6d..41aa488b47 100644 --- a/lib/ansible/modules/network/f5/bigip_sys_global.py +++ b/lib/ansible/modules/network/f5/bigip_sys_global.py @@ -136,7 +136,6 @@ security_banner: ''' from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.parsing.convert_bool import BOOLEANS from ansible.module_utils.parsing.convert_bool import BOOLEANS_TRUE from ansible.module_utils.parsing.convert_bool import BOOLEANS_FALSE diff --git a/lib/ansible/modules/network/f5/bigip_timer_policy.py b/lib/ansible/modules/network/f5/bigip_timer_policy.py index 458c7917ba..6f129f28aa 100644 --- a/lib/ansible/modules/network/f5/bigip_timer_policy.py +++ b/lib/ansible/modules/network/f5/bigip_timer_policy.py @@ -150,7 +150,6 @@ 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 fq_name from library.module_utils.network.f5.common import f5_argument_spec from library.module_utils.network.f5.common import compare_complex_list try: @@ -163,7 +162,6 @@ 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 fq_name from ansible.module_utils.network.f5.common import f5_argument_spec from ansible.module_utils.network.f5.common import compare_complex_list try: diff --git a/lib/ansible/modules/network/f5/bigip_trunk.py b/lib/ansible/modules/network/f5/bigip_trunk.py index 59ee294645..9b7e730c07 100644 --- a/lib/ansible/modules/network/f5/bigip_trunk.py +++ b/lib/ansible/modules/network/f5/bigip_trunk.py @@ -184,7 +184,6 @@ qinq_ethertype: ''' from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.basic import env_fallback try: from library.module_utils.network.f5.bigip import HAS_F5SDK @@ -192,8 +191,8 @@ 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 fq_name from library.module_utils.network.f5.common import f5_argument_spec + from library.module_utils.network.f5.compare import cmp_simple_list try: from library.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: @@ -204,8 +203,8 @@ 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 fq_name from ansible.module_utils.network.f5.common import f5_argument_spec + from ansible.module_utils.network.f5.compare import cmp_simple_list try: from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError except ImportError: @@ -364,16 +363,8 @@ class Difference(object): @property def interfaces(self): - if self.want.interfaces is None: - return None - if self.have.interfaces is None and self.want.interfaces == '': - return None - if self.have.interfaces is not None and self.want.interfaces == '': - return [] - if self.have.interfaces is None: - return self.want.interfaces - if set(self.want.interfaces) != set(self.have.interfaces): - return self.want.interfaces + result = cmp_simple_list(self.want.interfaces, self.have.interfaces) + return result class ModuleManager(object): diff --git a/lib/ansible/modules/network/f5/bigip_user.py b/lib/ansible/modules/network/f5/bigip_user.py index 657b4a1f97..0dc13c65e8 100644 --- a/lib/ansible/modules/network/f5/bigip_user.py +++ b/lib/ansible/modules/network/f5/bigip_user.py @@ -218,11 +218,6 @@ except ImportError: except ImportError: HAS_F5SDK = False -try: - from StringIO import StringIO -except ImportError: - from io import StringIO - class Parameters(AnsibleF5Parameters): api_map = { diff --git a/lib/ansible/modules/network/f5/bigip_virtual_server.py b/lib/ansible/modules/network/f5/bigip_virtual_server.py index b625831704..1687857a16 100644 --- a/lib/ansible/modules/network/f5/bigip_virtual_server.py +++ b/lib/ansible/modules/network/f5/bigip_virtual_server.py @@ -650,6 +650,7 @@ try: from library.module_utils.network.f5.common import transform_name from library.module_utils.network.f5.common import mark_managed_by from library.module_utils.network.f5.common import only_has_managed_metadata + from library.module_utils.network.f5.compare import cmp_simple_list from library.module_utils.network.f5.ipaddress import is_valid_ip from library.module_utils.network.f5.ipaddress import ip_interface from library.module_utils.network.f5.ipaddress import validate_ip_v6_address @@ -667,6 +668,7 @@ except ImportError: from ansible.module_utils.network.f5.common import transform_name from ansible.module_utils.network.f5.common import mark_managed_by from ansible.module_utils.network.f5.common import only_has_managed_metadata + from ansible.module_utils.network.f5.compare import cmp_simple_list from ansible.module_utils.network.f5.ipaddress import is_valid_ip from ansible.module_utils.network.f5.ipaddress import ip_interface from ansible.module_utils.network.f5.ipaddress import validate_ip_v6_address @@ -2754,16 +2756,8 @@ class Difference(object): @property def security_log_profiles(self): - if self.want.security_log_profiles is None: - return None - if self.have.security_log_profiles is None and self.want.security_log_profiles == '': - return None - if self.have.security_log_profiles is not None and self.want.security_log_profiles == '': - return [] - if self.have.security_log_profiles is None: - return self.want.security_log_profiles - if set(self.want.security_log_profiles) != set(self.have.security_log_profiles): - return self.want.security_log_profiles + result = cmp_simple_list(self.want.security_log_profiles, self.have.security_log_profiles) + return result @property def security_nat_policy(self): diff --git a/lib/ansible/modules/network/f5/bigip_vlan.py b/lib/ansible/modules/network/f5/bigip_vlan.py index 8423632dcc..9f712ed6e1 100644 --- a/lib/ansible/modules/network/f5/bigip_vlan.py +++ b/lib/ansible/modules/network/f5/bigip_vlan.py @@ -385,41 +385,33 @@ class Difference(object): @property def untagged_interfaces(self): - result = [] - if self.want.untagged_interfaces is None: - return None - elif self.want.untagged_interfaces == '' and self.have.untagged_interfaces is None: - return None - elif self.want.untagged_interfaces == '' and len(self.have.untagged_interfaces) > 0: - pass - elif not self.have.untagged_interfaces: - result = dict( - interfaces=[dict(name=x, untagged=True) for x in self.want.untagged_interfaces] - ) - elif set(self.want.untagged_interfaces) != set(self.have.untagged_interfaces): - result = dict( - interfaces=[dict(name=x, untagged=True) for x in self.want.untagged_interfaces] - ) - else: - return None + result = self.cmp_interfaces(self.want.untagged_interfaces, self.have.untagged_interfaces, False) return result @property def tagged_interfaces(self): + result = self.cmp_interfaces(self.want.tagged_interfaces, self.have.tagged_interfaces, True) + return result + + def cmp_interfaces(self, want, have, tagged): result = [] - if self.want.tagged_interfaces is None: + if tagged: + tag_key = 'tagged' + else: + tag_key = 'untagged' + if want is None: return None - elif self.want.tagged_interfaces == '' and self.have.tagged_interfaces is None: + elif want == '' and have is None: return None - elif self.want.tagged_interfaces == '' and len(self.have.tagged_interfaces) > 0: + elif want == '' and len(have) > 0: pass - elif not self.have.tagged_interfaces: + elif not have: result = dict( - interfaces=[dict(name=x, tagged=True) for x in self.want.tagged_interfaces] + interfaces=[{'name': x, tag_key: True} for x in want] ) - elif set(self.want.tagged_interfaces) != set(self.have.tagged_interfaces): + elif set(want) != set(have): result = dict( - interfaces=[dict(name=x, tagged=True) for x in self.want.tagged_interfaces] + interfaces=[{'name': x, tag_key: True} for x in want] ) else: return None