From e9b52aca64b5a026710b66521eb383dc4de043f5 Mon Sep 17 00:00:00 2001 From: Tim Rupp Date: Tue, 16 Jan 2018 21:02:33 -0800 Subject: [PATCH] Minor bigip fixes (#34971) Updating docs in modules. fixing imports --- lib/ansible/modules/network/f5/bigip_facts.py | 10 +- .../modules/network/f5/bigip_pool_member.py | 167 +++++++++--------- .../modules/network/f5/bigip_selfip.py | 4 +- 3 files changed, 95 insertions(+), 86 deletions(-) diff --git a/lib/ansible/modules/network/f5/bigip_facts.py b/lib/ansible/modules/network/f5/bigip_facts.py index 9eb0ca2cd2c..4da6d29dbfe 100644 --- a/lib/ansible/modules/network/f5/bigip_facts.py +++ b/lib/ansible/modules/network/f5/bigip_facts.py @@ -97,9 +97,14 @@ except ImportError: pass # Handle via f5_utils.bigsuds_found from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.f5_utils import bigip_api, bigsuds_found, f5_argument_spec +from ansible.module_utils.f5_utils import bigip_api, bigsuds_found from ansible.module_utils.six.moves import map, zip +try: + from library.module_utils.network.f5.common import f5_argument_spec +except ImportError: + from ansible.module_utils.network.f5.common import f5_argument_spec + class F5(object): """F5 iControl class. @@ -1640,8 +1645,7 @@ def generate_provision_dict(f5): def main(): - argument_spec = f5_argument_spec() - + argument_spec = f5_argument_spec meta_args = dict( session=dict(type='bool', default=False), include=dict(type='list', required=True), diff --git a/lib/ansible/modules/network/f5/bigip_pool_member.py b/lib/ansible/modules/network/f5/bigip_pool_member.py index 1307b25c681..46ddac397f4 100644 --- a/lib/ansible/modules/network/f5/bigip_pool_member.py +++ b/lib/ansible/modules/network/f5/bigip_pool_member.py @@ -5,16 +5,20 @@ # Copyright (c) 2013 Matt Hite # 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 + + ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community'} -DOCUMENTATION = ''' +DOCUMENTATION = r''' --- module: bigip_pool_member short_description: Manages F5 BIG-IP LTM pool members description: - - Manages F5 BIG-IP LTM pool members via iControl SOAP API + - Manages F5 BIG-IP LTM pool members via iControl SOAP API. version_added: 1.4 author: - Matt Hite (@mhite) @@ -29,134 +33,114 @@ requirements: options: state: description: - - Pool member state - required: true + - Pool member state. + required: True default: present choices: - present - absent session_state: description: - - Set new session availability status for pool member + - Set new session availability status for pool member. version_added: 2.0 - required: false - default: null choices: - enabled - disabled monitor_state: description: - - Set monitor availability status for pool member + - Set monitor availability status for pool member. version_added: 2.0 - required: false - default: null choices: - enabled - disabled pool: description: - Pool name. This pool must exist. - required: true + required: True partition: description: - Partition - required: false - default: 'Common' + default: Common host: description: - - Pool member IP - required: true + - Pool member IP. + required: True aliases: - address - name port: description: - - Pool member port - required: true + - Pool member port. + required: True connection_limit: description: - Pool member connection limit. Setting this to 0 disables the limit. - required: false - default: null description: description: - - Pool member description - required: false - default: null + - Pool member description. rate_limit: description: - Pool member rate limit (connections-per-second). Setting this to 0 disables the limit. - required: false - default: null ratio: description: - Pool member ratio weight. Valid values range from 1 through 100. New pool members -- unless overridden with this value -- default to 1. - required: false - default: null preserve_node: description: - When state is absent and the pool member is no longer referenced in other pools, the default behavior removes the unused node o bject. Setting this to 'yes' disables this behavior. - required: false - default: 'no' + default: no choices: - yes - no version_added: 2.1 - priority_group: - description: - - Sets priority group for a pool member. - required: false - default: null - version_added: 2.4 extends_documentation_fragment: f5 ''' EXAMPLES = ''' - name: Add pool member bigip_pool_member: - server: "lb.mydomain.com" - user: "admin" - password: "secret" - state: "present" - pool: "my-pool" - partition: "Common" - host: "{{ ansible_default_ipv4['address'] }}" - port: 80 - description: "web server" - connection_limit: 100 - rate_limit: 50 - ratio: 2 + server: lb.mydomain.com + user: admin + password: secret + state: present + pool: my-pool + partition: Common + host: "{{ ansible_default_ipv4['address'] }}" + port: 80 + description: web server + connection_limit: 100 + rate_limit: 50 + ratio: 2 delegate_to: localhost - name: Modify pool member ratio and description bigip_pool_member: - server: "lb.mydomain.com" - user: "admin" - password: "secret" - state: "present" - pool: "my-pool" - partition: "Common" - host: "{{ ansible_default_ipv4['address'] }}" - port: 80 - ratio: 1 - description: "nginx server" + server: lb.mydomain.com + user: admin + password: secret + state: present + pool: my-pool + partition: Common + host: "{{ ansible_default_ipv4['address'] }}" + port: 80 + ratio: 1 + description: nginx server delegate_to: localhost - name: Remove pool member from pool bigip_pool_member: - server: "lb.mydomain.com" - user: "admin" - password: "secret" - state: "absent" - pool: "my-pool" - partition: "Common" - host: "{{ ansible_default_ipv4['address'] }}" - port: 80 + server: lb.mydomain.com + user: admin + password: secret + state: absent + pool: my-pool + partition: Common + host: "{{ ansible_default_ipv4['address'] }}" + port: 80 delegate_to: localhost @@ -175,19 +159,38 @@ EXAMPLES = ''' - name: Force pool member offline bigip_pool_member: - server: "lb.mydomain.com" - user: "admin" - password: "secret" - state: "present" - session_state: "disabled" - monitor_state: "disabled" - pool: "my-pool" - partition: "Common" - host: "{{ ansible_default_ipv4['address'] }}" - port: 80 + server: lb.mydomain.com + user: admin + password: secret + state: present + session_state: disabled + monitor_state: disabled + pool: my-pool + partition: Common + host: "{{ ansible_default_ipv4['address'] }}" + port: 80 delegate_to: localhost ''' +try: + import bigsuds + HAS_BIGSUDS = True +except ImportError: + pass # Handled by f5_utils.bigsuds_found + +from ansible.module_utils.basic import AnsibleModule +from ansible.module_utils.f5_utils import bigip_api, bigsuds_found + +HAS_DEVEL_IMPORTS = False + +try: + from library.module_utils.network.f5.common import f5_argument_spec + from library.module_utils.network.f5.common import fqdn_name + HAS_DEVEL_IMPORTS = True +except ImportError: + from ansible.module_utils.network.f5.common import fqdn_name + from ansible.module_utils.network.f5.common import f5_argument_spec + def pool_exists(api, pool): # hack to determine if pool exists @@ -382,7 +385,8 @@ def get_member_monitor_status(api, pool, address, port): def main(): - argument_spec = f5_argument_spec() + result = {} + argument_spec = f5_argument_spec meta_args = dict( session_state=dict(type='str', choices=['enabled', 'disabled']), @@ -404,12 +408,15 @@ def main(): supports_check_mode=True ) + if not bigsuds_found: + module.fail_json(msg="the python bigsuds module is required") + if module.params['validate_certs']: import ssl if not hasattr(ssl, 'SSLContext'): module.fail_json( - msg='bigsuds does not support verifying certificates with python < 2.7.9. Either update python or set validate_certs=False on the task' - ) + msg='bigsuds does not support verifying certificates with python < 2.7.9. ' + 'Either update python or set validate_certs=False on the task') server = module.params['server'] server_port = module.params['server_port'] @@ -421,14 +428,14 @@ def main(): session_state = module.params['session_state'] monitor_state = module.params['monitor_state'] - pool = fq_name(partition, module.params['pool']) + pool = fqdn_name(partition, module.params['pool']) connection_limit = module.params['connection_limit'] description = module.params['description'] rate_limit = module.params['rate_limit'] ratio = module.params['ratio'] priority_group = module.params['priority_group'] host = module.params['host'] - address = fq_name(partition, host) + address = fqdn_name(partition, host) port = module.params['port'] preserve_node = module.params['preserve_node'] @@ -523,8 +530,6 @@ def main(): module.exit_json(**result) -from ansible.module_utils.basic import * -from ansible.module_utils.f5_utils import * if __name__ == '__main__': main() diff --git a/lib/ansible/modules/network/f5/bigip_selfip.py b/lib/ansible/modules/network/f5/bigip_selfip.py index 8de9b1b600c..4b2592dccfd 100644 --- a/lib/ansible/modules/network/f5/bigip_selfip.py +++ b/lib/ansible/modules/network/f5/bigip_selfip.py @@ -60,8 +60,8 @@ options: IP, this value is required. route_domain: description: - - The route domain id of the system. When creating a new Self IP, if - this value is not specified, a default value of C(0) will be used. + - The route domain id of the system. When creating a new Self IP, if + this value is not specified, a default value of C(0) will be used. version_added: 2.3 partition: description: