From 07a011cd6fe59115d5597dfe5b27dd47611bfaf1 Mon Sep 17 00:00:00 2001 From: Tim Rupp Date: Tue, 21 Aug 2018 18:40:19 -0400 Subject: [PATCH] Various bigiq fixes (#44487) Fixes usage of the RestClient class. Documentation fixes. Removal of dependency code. --- .../network/f5/bigiq_application_fasthttp.py | 17 +++------ .../f5/bigiq_application_fastl4_tcp.py | 28 +++++--------- .../f5/bigiq_application_fastl4_udp.py | 28 +++++--------- .../network/f5/bigiq_application_http.py | 22 ++++------- .../f5/bigiq_application_https_offload.py | 20 +++------- .../network/f5/bigiq_application_https_waf.py | 20 +++------- .../f5/bigiq_regkey_license_assignment.py | 37 ++++++++++--------- .../network/f5/bigiq_utility_license.py | 2 +- .../network/f5/test_bigiq_regkey_license.py | 2 +- .../test_bigiq_regkey_license_assignment.py | 2 +- .../network/f5/test_bigiq_utility_license.py | 2 +- 11 files changed, 68 insertions(+), 112 deletions(-) diff --git a/lib/ansible/modules/network/f5/bigiq_application_fasthttp.py b/lib/ansible/modules/network/f5/bigiq_application_fasthttp.py index effe694600..5cfaf01951 100644 --- a/lib/ansible/modules/network/f5/bigiq_application_fasthttp.py +++ b/lib/ansible/modules/network/f5/bigiq_application_fasthttp.py @@ -186,6 +186,7 @@ try: from library.module_utils.network.f5.common import f5_argument_spec from library.module_utils.network.f5.common import exit_json from library.module_utils.network.f5.common import fail_json + from library.module_utils.network.f5.ipaddress import is_valid_ip except ImportError: from ansible.module_utils.network.f5.bigiq import F5RestClient from ansible.module_utils.network.f5.common import F5ModuleError @@ -193,12 +194,7 @@ except ImportError: 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 - -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False + from ansible.module_utils.network.f5.ipaddress import is_valid_ip class Parameters(AnsibleF5Parameters): @@ -275,11 +271,10 @@ class ModuleParameters(Parameters): @property def default_device_reference(self): - try: + if is_valid_ip(self.service_environment): # An IP address was specified - netaddr.IPAddress(self.service_environment) filter = "address+eq+'{0}'".format(self.service_environment) - except netaddr.core.AddrFormatError: + else: # Assume a hostname was specified filter = "hostname+eq+'{0}'".format(self.service_environment) @@ -731,11 +726,9 @@ def main(): argument_spec=spec.argument_spec, supports_check_mode=spec.supports_check_mode ) - if not HAS_NETADDR: - module.fail_json(msg="The python netaddr module is required") try: - client = F5RestClient(module=module) + client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() exit_json(module, results, client) diff --git a/lib/ansible/modules/network/f5/bigiq_application_fastl4_tcp.py b/lib/ansible/modules/network/f5/bigiq_application_fastl4_tcp.py index 82fb5e9a09..24d0b8482c 100644 --- a/lib/ansible/modules/network/f5/bigiq_application_fastl4_tcp.py +++ b/lib/ansible/modules/network/f5/bigiq_application_fastl4_tcp.py @@ -117,7 +117,7 @@ EXAMPLES = r''' port: 8080 - address: 5.6.7.8 port: 8080 - load_balancer: + inbound_virtual: name: foo destination: 2.2.2.2 netmask: 255.255.255.255 @@ -174,6 +174,8 @@ servers: sample: hash/dictionary of values ''' +import time + from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import env_fallback @@ -184,6 +186,7 @@ try: from library.module_utils.network.f5.common import f5_argument_spec from library.module_utils.network.f5.common import exit_json from library.module_utils.network.f5.common import fail_json + from library.module_utils.network.f5.ipaddress import is_valid_ip except ImportError: from ansible.module_utils.network.f5.bigiq import F5RestClient from ansible.module_utils.network.f5.common import F5ModuleError @@ -191,15 +194,7 @@ except ImportError: 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 - -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False - - -import time + from ansible.module_utils.network.f5.ipaddress import is_valid_ip class Parameters(AnsibleF5Parameters): @@ -274,11 +269,10 @@ class ModuleParameters(Parameters): @property def default_device_reference(self): - try: + if is_valid_ip(self.service_environment): # An IP address was specified - netaddr.IPAddress(self.service_environment) filter = "address+eq+'{0}'".format(self.service_environment) - except netaddr.core.AddrFormatError: + else: # Assume a hostname was specified filter = "hostname+eq+'{0}'".format(self.service_environment) @@ -338,7 +332,7 @@ class UsableChanges(Changes): name='virtual', destinationAddress=self.inbound_virtual['address'], mask=self.inbound_virtual['netmask'], - destinationPort=self.inbound_virtual['port'] + destinationPort=self.inbound_virtual.get('port', 8080) ), subcollectionResources=self.profiles ) @@ -376,7 +370,7 @@ class UsableChanges(Changes): for x in self.servers: member = dict( parameters=dict( - port=x['port'], + port=x.get('port', 8000), nodeReference=dict( link='#/resources/ltm:node:3e91bd30bbfb/{0}'.format(x['address']), fullPath='# {0}'.format(x['address']) @@ -678,11 +672,9 @@ def main(): argument_spec=spec.argument_spec, supports_check_mode=spec.supports_check_mode ) - if not HAS_NETADDR: - module.fail_json(msg="The python netaddr module is required") try: - client = F5RestClient(module=module) + client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() exit_json(module, results, client) diff --git a/lib/ansible/modules/network/f5/bigiq_application_fastl4_udp.py b/lib/ansible/modules/network/f5/bigiq_application_fastl4_udp.py index 50c6d7f36c..eaa6dfda16 100644 --- a/lib/ansible/modules/network/f5/bigiq_application_fastl4_udp.py +++ b/lib/ansible/modules/network/f5/bigiq_application_fastl4_udp.py @@ -117,7 +117,7 @@ EXAMPLES = r''' port: 8080 - address: 5.6.7.8 port: 8080 - load_balancer: + inbound_virtual: name: foo destination: 2.2.2.2 netmask: 255.255.255.255 @@ -174,6 +174,8 @@ servers: sample: hash/dictionary of values ''' +import time + from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import env_fallback @@ -184,6 +186,7 @@ try: from library.module_utils.network.f5.common import f5_argument_spec from library.module_utils.network.f5.common import exit_json from library.module_utils.network.f5.common import fail_json + from library.module_utils.network.f5.ipaddress import is_valid_ip except ImportError: from ansible.module_utils.network.f5.bigiq import F5RestClient from ansible.module_utils.network.f5.common import F5ModuleError @@ -191,15 +194,7 @@ except ImportError: 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 - -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False - - -import time + from ansible.module_utils.network.f5.ipaddress import is_valid_ip class Parameters(AnsibleF5Parameters): @@ -274,11 +269,10 @@ class ModuleParameters(Parameters): @property def default_device_reference(self): - try: + if is_valid_ip(self.service_environment): # An IP address was specified - netaddr.IPAddress(self.service_environment) filter = "address+eq+'{0}'".format(self.service_environment) - except netaddr.core.AddrFormatError: + else: # Assume a hostname was specified filter = "hostname+eq+'{0}'".format(self.service_environment) @@ -338,7 +332,7 @@ class UsableChanges(Changes): name='virtual', destinationAddress=self.inbound_virtual['address'], mask=self.inbound_virtual['netmask'], - destinationPort=self.inbound_virtual['port'] + destinationPort=self.inbound_virtual.get('port', 53) ), subcollectionResources=self.profiles ) @@ -376,7 +370,7 @@ class UsableChanges(Changes): for x in self.servers: member = dict( parameters=dict( - port=x['port'], + port=x.get('port', 8000), nodeReference=dict( link='#/resources/ltm:node:b19842fe713a/{0}'.format(x['address']), fullPath='# {0}'.format(x['address']) @@ -678,11 +672,9 @@ def main(): argument_spec=spec.argument_spec, supports_check_mode=spec.supports_check_mode ) - if not HAS_NETADDR: - module.fail_json(msg="The python netaddr module is required") try: - client = F5RestClient(module=module) + client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() exit_json(module, results, client) diff --git a/lib/ansible/modules/network/f5/bigiq_application_http.py b/lib/ansible/modules/network/f5/bigiq_application_http.py index bbae1a9584..94cef7e02e 100644 --- a/lib/ansible/modules/network/f5/bigiq_application_http.py +++ b/lib/ansible/modules/network/f5/bigiq_application_http.py @@ -186,6 +186,7 @@ try: from library.module_utils.network.f5.common import f5_argument_spec from library.module_utils.network.f5.common import exit_json from library.module_utils.network.f5.common import fail_json + from library.module_utils.network.f5.ipaddress import is_valid_ip except ImportError: from ansible.module_utils.network.f5.bigiq import F5RestClient from ansible.module_utils.network.f5.common import F5ModuleError @@ -193,12 +194,7 @@ except ImportError: 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 - -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False + from ansible.module_utils.network.f5.ipaddress import is_valid_ip class Parameters(AnsibleF5Parameters): @@ -275,11 +271,9 @@ class ModuleParameters(Parameters): @property def default_device_reference(self): - try: - # An IP address was specified - netaddr.IPAddress(self.service_environment) + if is_valid_ip(self.service_environment): filter = "address+eq+'{0}'".format(self.service_environment) - except netaddr.core.AddrFormatError: + else: # Assume a hostname was specified filter = "hostname+eq+'{0}'".format(self.service_environment) @@ -363,7 +357,7 @@ class UsableChanges(Changes): name='virtual', destinationAddress=self.inbound_virtual['address'], mask=self.inbound_virtual['netmask'], - destinationPort=self.inbound_virtual['port'] + destinationPort=self.inbound_virtual.get('port', 80) ), subcollectionResources=self.profiles ) @@ -406,7 +400,7 @@ class UsableChanges(Changes): for x in self.servers: member = dict( parameters=dict( - port=x['port'], + port=x.get('port', 80), nodeReference=dict( link='#/resources/ltm:node:9e76a6323321/{0}'.format(x['address']), fullPath='# {0}'.format(x['address']) @@ -731,11 +725,9 @@ def main(): argument_spec=spec.argument_spec, supports_check_mode=spec.supports_check_mode ) - if not HAS_NETADDR: - module.fail_json(msg="The python netaddr module is required") try: - client = F5RestClient(module=module) + client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() exit_json(module, results, client) diff --git a/lib/ansible/modules/network/f5/bigiq_application_https_offload.py b/lib/ansible/modules/network/f5/bigiq_application_https_offload.py index 901b23d5dd..862a23f3eb 100644 --- a/lib/ansible/modules/network/f5/bigiq_application_https_offload.py +++ b/lib/ansible/modules/network/f5/bigiq_application_https_offload.py @@ -107,8 +107,7 @@ options: per profile. - If you attempt to assign two RSA, DSA, or ECDSA certificate/key combo, the device will reject this. - - This list is a complex list that specifies a number of keys. There are - several supported keys. + - This list is a complex list that specifies a number of keys. - When creating a new profile, if this parameter is not specified, the default value of C(inherit) will be used. suboptions: @@ -245,6 +244,7 @@ try: 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 fq_name + from library.module_utils.network.f5.ipaddress import is_valid_ip except ImportError: from ansible.module_utils.network.f5.bigiq import F5RestClient from ansible.module_utils.network.f5.common import F5ModuleError @@ -253,12 +253,7 @@ except ImportError: 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 fq_name - -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False + from ansible.module_utils.network.f5.ipaddress import is_valid_ip class Parameters(AnsibleF5Parameters): @@ -335,11 +330,10 @@ class ModuleParameters(Parameters): @property def default_device_reference(self): - try: + if is_valid_ip(self.service_environment): # An IP address was specified - netaddr.IPAddress(self.service_environment) filter = "address+eq+'{0}'".format(self.service_environment) - except netaddr.core.AddrFormatError: + else: # Assume a hostname was specified filter = "hostname+eq+'{0}'".format(self.service_environment) @@ -974,11 +968,9 @@ def main(): argument_spec=spec.argument_spec, supports_check_mode=spec.supports_check_mode ) - if not HAS_NETADDR: - module.fail_json(msg="The python netaddr module is required") try: - client = F5RestClient(module=module) + client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() exit_json(module, results, client) diff --git a/lib/ansible/modules/network/f5/bigiq_application_https_waf.py b/lib/ansible/modules/network/f5/bigiq_application_https_waf.py index ce3a67082f..6c0568f58d 100644 --- a/lib/ansible/modules/network/f5/bigiq_application_https_waf.py +++ b/lib/ansible/modules/network/f5/bigiq_application_https_waf.py @@ -107,8 +107,7 @@ options: per profile. - If you attempt to assign two RSA, DSA, or ECDSA certificate/key combo, the device will reject this. - - This list is a complex list that specifies a number of keys. There are - several supported keys. + - This list is a complex list that specifies a number of keys. - When creating a new profile, if this parameter is not specified, the default value of C(inherit) will be used. suboptions: @@ -250,6 +249,7 @@ try: 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 fq_name + from library.module_utils.network.f5.ipaddress import is_valid_ip except ImportError: from ansible.module_utils.network.f5.bigiq import F5RestClient from ansible.module_utils.network.f5.common import F5ModuleError @@ -258,12 +258,7 @@ except ImportError: 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 fq_name - -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False + from ansible.module_utils.network.f5.ipaddress import is_valid_ip class Parameters(AnsibleF5Parameters): @@ -341,11 +336,10 @@ class ModuleParameters(Parameters): @property def default_device_reference(self): - try: + if is_valid_ip(self.service_environment): # An IP address was specified - netaddr.IPAddress(self.service_environment) filter = "address+eq+'{0}'".format(self.service_environment) - except netaddr.core.AddrFormatError: + else: # Assume a hostname was specified filter = "hostname+eq+'{0}'".format(self.service_environment) @@ -999,11 +993,9 @@ def main(): argument_spec=spec.argument_spec, supports_check_mode=spec.supports_check_mode ) - if not HAS_NETADDR: - module.fail_json(msg="The python netaddr module is required") try: - client = F5RestClient(module=module) + client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() exit_json(module, results, client) diff --git a/lib/ansible/modules/network/f5/bigiq_regkey_license_assignment.py b/lib/ansible/modules/network/f5/bigiq_regkey_license_assignment.py index e206352cd6..7e4542a676 100644 --- a/lib/ansible/modules/network/f5/bigiq_regkey_license_assignment.py +++ b/lib/ansible/modules/network/f5/bigiq_regkey_license_assignment.py @@ -15,7 +15,7 @@ ANSIBLE_METADATA = {'metadata_version': '1.1', DOCUMENTATION = r''' --- module: bigiq_regkey_license_assignment -short_description: Manage regkey license assignment on BIG-IPs from a BIG-IQ. +short_description: Manage regkey license assignment on BIG-IPs from a BIG-IQ description: - Manages the assignment of regkey licenses on a BIG-IQ. Assignment means that the license is assigned to a BIG-IP, or, it needs to be assigned to a BIG-IP. @@ -89,7 +89,7 @@ EXAMPLES = r''' user: admin delegate_to: localhost -- name: Register an managed device, by name +- name: Register a managed device, by name bigiq_regkey_license_assignment: pool: my-regkey-pool key: XXXX-XXXX-XXXX-XXXX-XXXX @@ -101,7 +101,7 @@ EXAMPLES = r''' user: admin delegate_to: localhost -- name: Register an managed device, by UUID +- name: Register a managed device, by UUID bigiq_regkey_license_assignment: pool: my-regkey-pool key: XXXX-XXXX-XXXX-XXXX-XXXX @@ -119,6 +119,7 @@ RETURN = r''' ''' import re +import time from ansible.module_utils.basic import AnsibleModule @@ -129,6 +130,7 @@ try: from library.module_utils.network.f5.common import f5_argument_spec from library.module_utils.network.f5.common import exit_json from library.module_utils.network.f5.common import fail_json + from library.module_utils.network.f5.ipaddress import is_valid_ip except ImportError: from ansible.module_utils.network.f5.bigiq import F5RestClient from ansible.module_utils.network.f5.common import F5ModuleError @@ -136,11 +138,7 @@ except ImportError: 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 -try: - import netaddr - HAS_NETADDR = True -except ImportError: - HAS_NETADDR = False + from ansible.module_utils.network.f5.ipaddress import is_valid_ip class Parameters(AnsibleF5Parameters): @@ -205,11 +203,9 @@ class ModuleParameters(Parameters): @property def device_is_address(self): - try: - netaddr.IPAddress(self.device) + if is_valid_ip(self.device): return True - except (ValueError, netaddr.core.AddrFormatError): - return False + return False @property def device_is_id(self): @@ -484,6 +480,10 @@ class ModuleManager(object): self.remove_from_device() if self.exists(): raise F5ModuleError("Failed to delete the resource.") + # Artificial sleeping to wait for remote licensing (on BIG-IP) to complete + # + # This should be something that BIG-IQ can do natively in 6.1-ish time. + time.sleep(60) return True def create(self): @@ -505,6 +505,11 @@ class ModuleManager(object): "Failed to license the remote device." ) self.wait_for_device_to_be_licensed() + + # Artificial sleeping to wait for remote licensing (on BIG-IP) to complete + # + # This should be something that BIG-IQ can do natively in 6.1-ish time. + time.sleep(60) return True def create_on_device(self): @@ -530,7 +535,7 @@ class ModuleManager(object): if 'message' in response: raise F5ModuleError(response['message']) else: - raise F5ModuleError(resp._content) + raise F5ModuleError(resp.content) def wait_for_device_to_be_licensed(self): count = 0 @@ -552,7 +557,7 @@ class ModuleManager(object): if 'message' in response: raise F5ModuleError(response['message']) else: - raise F5ModuleError(resp._content) + raise F5ModuleError(resp.content) if response['status'] == 'LICENSED': count += 1 else: @@ -611,11 +616,9 @@ def main(): supports_check_mode=spec.supports_check_mode, required_if=spec.required_if ) - if not HAS_NETADDR: - module.fail_json(msg="The python netaddr module is required") try: - client = F5RestClient(module=module) + client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() exit_json(module, results, client) diff --git a/lib/ansible/modules/network/f5/bigiq_utility_license.py b/lib/ansible/modules/network/f5/bigiq_utility_license.py index 824eb315c2..7b8a9e31a4 100644 --- a/lib/ansible/modules/network/f5/bigiq_utility_license.py +++ b/lib/ansible/modules/network/f5/bigiq_utility_license.py @@ -449,7 +449,7 @@ def main(): ) try: - client = F5RestClient(module=module) + client = F5RestClient(**module.params) mm = ModuleManager(module=module, client=client) results = mm.exec_module() exit_json(module, results, client) diff --git a/test/units/modules/network/f5/test_bigiq_regkey_license.py b/test/units/modules/network/f5/test_bigiq_regkey_license.py index ca5f531f9c..9301d512d1 100644 --- a/test/units/modules/network/f5/test_bigiq_regkey_license.py +++ b/test/units/modules/network/f5/test_bigiq_regkey_license.py @@ -100,7 +100,7 @@ class TestManager(unittest.TestCase): license_key='XXXX-XXXX-XXXX-XXXX-XXXX', accept_eula=True, description='this is a description', - password='passsword', + password='password', server='localhost', user='admin' )) diff --git a/test/units/modules/network/f5/test_bigiq_regkey_license_assignment.py b/test/units/modules/network/f5/test_bigiq_regkey_license_assignment.py index 5d96ac76cb..d4c7de4e2f 100644 --- a/test/units/modules/network/f5/test_bigiq_regkey_license_assignment.py +++ b/test/units/modules/network/f5/test_bigiq_regkey_license_assignment.py @@ -112,7 +112,7 @@ class TestManager(unittest.TestCase): device_password='secret', managed='no', state='present', - password='passsword', + password='password', server='localhost', user='admin' )) diff --git a/test/units/modules/network/f5/test_bigiq_utility_license.py b/test/units/modules/network/f5/test_bigiq_utility_license.py index efa6075e1d..1abead1c20 100644 --- a/test/units/modules/network/f5/test_bigiq_utility_license.py +++ b/test/units/modules/network/f5/test_bigiq_utility_license.py @@ -86,7 +86,7 @@ class TestManager(unittest.TestCase): set_module_args(dict( license_key='XXXX-XXXX-XXXX-XXXX-XXXX', accept_eula=True, - password='passsword', + password='password', server='localhost', user='admin' ))