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
pull/45633/head
Tim Rupp 6 years ago committed by GitHub
parent e68f895e61
commit e619052424
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -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)

@ -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)

@ -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:

@ -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)

@ -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

@ -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:

@ -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)

@ -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

@ -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

@ -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:

@ -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:

@ -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)

@ -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)

@ -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)

@ -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:

@ -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', [])

@ -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']:

@ -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']:

@ -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)

@ -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):

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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)

@ -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):
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)
)
resp = self.client.api.get(uri)
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
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)
)
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 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
)
resource = pool.members_s.members.load(
name=self.want.full_name,
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.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
)
resource = pool.members_s.members.load(
name=self.want.full_name,
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)
)
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
)
resource = pool.members_s.members.load(
name=self.want.full_name,
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)
)
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__':

@ -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)

@ -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

@ -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)

@ -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)

@ -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)

@ -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

@ -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:

@ -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):

@ -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 = {

@ -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):

@ -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

Loading…
Cancel
Save