Adds style conventions to bigip_pool (#2537)

A number of coding conventions have been adopted for new F5 modules
that are in development. To ensure common usage across the modules,
this module needed to be updated to reflect those conventions.

No functional code changes were made.
pull/18777/head
Tim Rupp 8 years ago committed by Matt Clay
parent ec95c5d9b3
commit c2deb92f62

@ -23,235 +23,245 @@ DOCUMENTATION = '''
module: bigip_pool module: bigip_pool
short_description: "Manages F5 BIG-IP LTM pools" short_description: "Manages F5 BIG-IP LTM pools"
description: description:
- "Manages F5 BIG-IP LTM pools via iControl SOAP API" - Manages F5 BIG-IP LTM pools via iControl SOAP API
version_added: "1.2" version_added: 1.2
author: author:
- Matt Hite (@mhite) - Matt Hite (@mhite)
- Tim Rupp (@caphrim007) - Tim Rupp (@caphrim007)
notes: notes:
- "Requires BIG-IP software version >= 11" - Requires BIG-IP software version >= 11
- "F5 developed module 'bigsuds' required (see http://devcentral.f5.com)" - F5 developed module 'bigsuds' required (see http://devcentral.f5.com)
- "Best run as a local_action in your playbook" - Best run as a local_action in your playbook
requirements: requirements:
- bigsuds - bigsuds
options: options:
server: server:
description: description:
- BIG-IP host - BIG-IP host
required: true required: true
default: null default: null
choices: [] choices: []
aliases: [] aliases: []
server_port: server_port:
description: description:
- BIG-IP server port - BIG-IP server port
required: false required: false
default: 443 default: 443
version_added: "2.2" version_added: "2.2"
user: user:
description: description:
- BIG-IP username - BIG-IP username
required: true required: true
default: null default: null
choices: [] choices: []
aliases: [] aliases: []
password: password:
description: description:
- BIG-IP password - BIG-IP password
required: true required: true
default: null default: null
choices: [] choices: []
aliases: [] aliases: []
validate_certs: validate_certs:
description: description:
- If C(no), SSL certificates will not be validated. This should only be used - If C(no), SSL certificates will not be validated. This should only be used
on personally controlled sites. Prior to 2.0, this module would always on personally controlled sites. Prior to 2.0, this module would always
validate on python >= 2.7.9 and never validate on python <= 2.7.8 validate on python >= 2.7.9 and never validate on python <= 2.7.8
required: false required: false
default: 'yes' default: 'yes'
choices: ['yes', 'no'] choices:
version_added: 1.9.1 - yes
state: - no
description: version_added: 2.0
- Pool/pool member state state:
required: false description:
default: present - Pool/pool member state
choices: ['present', 'absent'] required: false
aliases: [] default: present
name: choices:
description: - present
- Pool name - absent
required: true aliases: []
default: null name:
choices: [] description:
aliases: ['pool'] - Pool name
partition: required: true
description: default: null
- Partition of pool/pool member choices: []
required: false aliases:
default: 'Common' - pool
choices: [] partition:
aliases: [] description:
lb_method: - Partition of pool/pool member
description: required: false
- Load balancing method default: 'Common'
version_added: "1.3" choices: []
required: False aliases: []
default: 'round_robin' lb_method:
choices: ['round_robin', 'ratio_member', 'least_connection_member', description:
'observed_member', 'predictive_member', 'ratio_node_address', - Load balancing method
'least_connection_node_address', 'fastest_node_address', version_added: "1.3"
'observed_node_address', 'predictive_node_address', required: False
'dynamic_ratio', 'fastest_app_response', 'least_sessions', default: 'round_robin'
'dynamic_ratio_member', 'l3_addr', choices:
'weighted_least_connection_member', - round_robin
'weighted_least_connection_node_address', - ratio_member
'ratio_session', 'ratio_least_connection_member', - least_connection_member
'ratio_least_connection_node_address'] - observed_member
aliases: [] - predictive_member
monitor_type: - ratio_node_address
description: - least_connection_node_address
- Monitor rule type when monitors > 1 - fastest_node_address
version_added: "1.3" - observed_node_address
required: False - predictive_node_address
default: null - dynamic_ratio
choices: ['and_list', 'm_of_n'] - fastest_app_response
aliases: [] - least_sessions
quorum: - dynamic_ratio_member
description: - l3_addr
- Monitor quorum value when monitor_type is m_of_n - weighted_least_connection_member
version_added: "1.3" - weighted_least_connection_node_address
required: False - ratio_session
default: null - ratio_least_connection_member
choices: [] - ratio_least_connection_node_address
aliases: [] aliases: []
monitors: monitor_type:
description: description:
- Monitor template name list. Always use the full path to the monitor. - Monitor rule type when monitors > 1
version_added: "1.3" version_added: "1.3"
required: False required: False
default: null default: null
choices: [] choices: ['and_list', 'm_of_n']
aliases: [] aliases: []
slow_ramp_time: quorum:
description: description:
- Sets the ramp-up time (in seconds) to gradually ramp up the load on newly added or freshly detected up pool members - Monitor quorum value when monitor_type is m_of_n
version_added: "1.3" version_added: "1.3"
required: False required: False
default: null default: null
choices: [] choices: []
aliases: [] aliases: []
reselect_tries: monitors:
description: description:
- Sets the number of times the system tries to contact a pool member after a passive failure - Monitor template name list. Always use the full path to the monitor.
version_added: "2.2" version_added: "1.3"
required: False required: False
default: null default: null
choices: [] choices: []
aliases: [] aliases: []
service_down_action: slow_ramp_time:
description: description:
- Sets the action to take when node goes down in pool - Sets the ramp-up time (in seconds) to gradually ramp up the load on
version_added: "1.3" newly added or freshly detected up pool members
required: False version_added: "1.3"
default: null required: False
choices: ['none', 'reset', 'drop', 'reselect'] default: null
aliases: [] choices: []
host: aliases: []
description: reselect_tries:
- "Pool member IP" description:
required: False - Sets the number of times the system tries to contact a pool member
default: null after a passive failure
choices: [] version_added: "2.2"
aliases: ['address'] required: False
port: default: null
description: choices: []
- "Pool member port" aliases: []
required: False service_down_action:
default: null description:
choices: [] - Sets the action to take when node goes down in pool
aliases: [] version_added: "1.3"
required: False
default: null
choices:
- none
- reset
- drop
- reselect
aliases: []
host:
description:
- "Pool member IP"
required: False
default: null
choices: []
aliases:
- address
port:
description:
- Pool member port
required: False
default: null
choices: []
aliases: []
''' '''
EXAMPLES = ''' EXAMPLES = '''
- name: Create pool
bigip_pool:
server: "lb.mydomain.com"
user: "admin"
password: "secret"
state: "present"
name: "my-pool"
partition: "Common"
lb_method: "least_connection_member"
slow_ramp_time: 120
delegate_to: localhost
- name: Modify load balancer method
bigip_pool:
server: "lb.mydomain.com"
user: "admin"
password: "secret"
state: "present"
name: "my-pool"
partition: "Common"
lb_method: "round_robin"
- name: Add pool member
bigip_pool:
server: "lb.mydomain.com"
user: "admin"
password: "secret"
state: "present"
name: "my-pool"
partition: "Common"
host: "{{ ansible_default_ipv4["address"] }}"
port: 80
- name: Remove pool member from pool
bigip_pool:
server: "lb.mydomain.com"
user: "admin"
password: "secret"
state: "absent"
name: "my-pool"
partition: "Common"
host: "{{ ansible_default_ipv4["address"] }}"
port: 80
- name: Delete pool
bigip_pool:
server: "lb.mydomain.com"
user: "admin"
password: "secret"
state: "absent"
name: "my-pool"
partition: "Common"
'''
## playbook task examples: RETURN = '''
---
# file bigip-test.yml
# ...
- hosts: localhost
tasks:
- name: Create pool
local_action: >
bigip_pool
server=lb.mydomain.com
user=admin
password=mysecret
state=present
name=matthite-pool
partition=matthite
lb_method=least_connection_member
slow_ramp_time=120
- name: Modify load balancer method
local_action: >
bigip_pool
server=lb.mydomain.com
user=admin
password=mysecret
state=present
name=matthite-pool
partition=matthite
lb_method=round_robin
- hosts: bigip-test
tasks:
- name: Add pool member
local_action: >
bigip_pool
server=lb.mydomain.com
user=admin
password=mysecret
state=present
name=matthite-pool
partition=matthite
host="{{ ansible_default_ipv4["address"] }}"
port=80
- name: Remove pool member from pool
local_action: >
bigip_pool
server=lb.mydomain.com
user=admin
password=mysecret
state=absent
name=matthite-pool
partition=matthite
host="{{ ansible_default_ipv4["address"] }}"
port=80
- hosts: localhost
tasks:
- name: Delete pool
local_action: >
bigip_pool
server=lb.mydomain.com
user=admin
password=mysecret
state=absent
name=matthite-pool
partition=matthite
''' '''
def pool_exists(api, pool): def pool_exists(api, pool):
# hack to determine if pool exists # hack to determine if pool exists
result = False result = False
try: try:
api.LocalLB.Pool.get_object_status(pool_names=[pool]) api.LocalLB.Pool.get_object_status(pool_names=[pool])
result = True result = True
except bigsuds.OperationFailed, e: except bigsuds.OperationFailed as e:
if "was not found" in str(e): if "was not found" in str(e):
result = False result = False
else: else:
@ -259,6 +269,7 @@ def pool_exists(api, pool):
raise raise
return result return result
def create_pool(api, pool, lb_method): def create_pool(api, pool, lb_method):
# create requires lb_method but we don't want to default # create requires lb_method but we don't want to default
# to a value on subsequent runs # to a value on subsequent runs
@ -268,18 +279,22 @@ def create_pool(api, pool, lb_method):
api.LocalLB.Pool.create_v2(pool_names=[pool], lb_methods=[lb_method], api.LocalLB.Pool.create_v2(pool_names=[pool], lb_methods=[lb_method],
members=[[]]) members=[[]])
def remove_pool(api, pool): def remove_pool(api, pool):
api.LocalLB.Pool.delete_pool(pool_names=[pool]) api.LocalLB.Pool.delete_pool(pool_names=[pool])
def get_lb_method(api, pool): def get_lb_method(api, pool):
lb_method = api.LocalLB.Pool.get_lb_method(pool_names=[pool])[0] lb_method = api.LocalLB.Pool.get_lb_method(pool_names=[pool])[0]
lb_method = lb_method.strip().replace('LB_METHOD_', '').lower() lb_method = lb_method.strip().replace('LB_METHOD_', '').lower()
return lb_method return lb_method
def set_lb_method(api, pool, lb_method): def set_lb_method(api, pool, lb_method):
lb_method = "LB_METHOD_%s" % lb_method.strip().upper() lb_method = "LB_METHOD_%s" % lb_method.strip().upper()
api.LocalLB.Pool.set_lb_method(pool_names=[pool], lb_methods=[lb_method]) api.LocalLB.Pool.set_lb_method(pool_names=[pool], lb_methods=[lb_method])
def get_monitors(api, pool): def get_monitors(api, pool):
result = api.LocalLB.Pool.get_monitor_association(pool_names=[pool])[0]['monitor_rule'] result = api.LocalLB.Pool.get_monitor_association(pool_names=[pool])[0]['monitor_rule']
monitor_type = result['type'].split("MONITOR_RULE_TYPE_")[-1].lower() monitor_type = result['type'].split("MONITOR_RULE_TYPE_")[-1].lower()
@ -287,35 +302,43 @@ def get_monitors(api, pool):
monitor_templates = result['monitor_templates'] monitor_templates = result['monitor_templates']
return (monitor_type, quorum, monitor_templates) return (monitor_type, quorum, monitor_templates)
def set_monitors(api, pool, monitor_type, quorum, monitor_templates): def set_monitors(api, pool, monitor_type, quorum, monitor_templates):
monitor_type = "MONITOR_RULE_TYPE_%s" % monitor_type.strip().upper() monitor_type = "MONITOR_RULE_TYPE_%s" % monitor_type.strip().upper()
monitor_rule = {'type': monitor_type, 'quorum': quorum, 'monitor_templates': monitor_templates} monitor_rule = {'type': monitor_type, 'quorum': quorum, 'monitor_templates': monitor_templates}
monitor_association = {'pool_name': pool, 'monitor_rule': monitor_rule} monitor_association = {'pool_name': pool, 'monitor_rule': monitor_rule}
api.LocalLB.Pool.set_monitor_association(monitor_associations=[monitor_association]) api.LocalLB.Pool.set_monitor_association(monitor_associations=[monitor_association])
def get_slow_ramp_time(api, pool): def get_slow_ramp_time(api, pool):
result = api.LocalLB.Pool.get_slow_ramp_time(pool_names=[pool])[0] result = api.LocalLB.Pool.get_slow_ramp_time(pool_names=[pool])[0]
return result return result
def set_slow_ramp_time(api, pool, seconds): def set_slow_ramp_time(api, pool, seconds):
api.LocalLB.Pool.set_slow_ramp_time(pool_names=[pool], values=[seconds]) api.LocalLB.Pool.set_slow_ramp_time(pool_names=[pool], values=[seconds])
def get_reselect_tries(api, pool): def get_reselect_tries(api, pool):
result = api.LocalLB.Pool.get_reselect_tries(pool_names=[pool])[0] result = api.LocalLB.Pool.get_reselect_tries(pool_names=[pool])[0]
return result return result
def set_reselect_tries(api, pool, tries): def set_reselect_tries(api, pool, tries):
api.LocalLB.Pool.set_reselect_tries(pool_names=[pool], values=[tries]) api.LocalLB.Pool.set_reselect_tries(pool_names=[pool], values=[tries])
def get_action_on_service_down(api, pool): def get_action_on_service_down(api, pool):
result = api.LocalLB.Pool.get_action_on_service_down(pool_names=[pool])[0] result = api.LocalLB.Pool.get_action_on_service_down(pool_names=[pool])[0]
result = result.split("SERVICE_DOWN_ACTION_")[-1].lower() result = result.split("SERVICE_DOWN_ACTION_")[-1].lower()
return result return result
def set_action_on_service_down(api, pool, action): def set_action_on_service_down(api, pool, action):
action = "SERVICE_DOWN_ACTION_%s" % action.strip().upper() action = "SERVICE_DOWN_ACTION_%s" % action.strip().upper()
api.LocalLB.Pool.set_action_on_service_down(pool_names=[pool], actions=[action]) api.LocalLB.Pool.set_action_on_service_down(pool_names=[pool], actions=[action])
def member_exists(api, pool, address, port): def member_exists(api, pool, address, port):
# hack to determine if member exists # hack to determine if member exists
result = False result = False
@ -324,7 +347,7 @@ def member_exists(api, pool, address, port):
api.LocalLB.Pool.get_member_object_status(pool_names=[pool], api.LocalLB.Pool.get_member_object_status(pool_names=[pool],
members=[members]) members=[members])
result = True result = True
except bigsuds.OperationFailed, e: except bigsuds.OperationFailed as e:
if "was not found" in str(e): if "was not found" in str(e):
result = False result = False
else: else:
@ -332,12 +355,13 @@ def member_exists(api, pool, address, port):
raise raise
return result return result
def delete_node_address(api, address): def delete_node_address(api, address):
result = False result = False
try: try:
api.LocalLB.NodeAddressV2.delete_node_address(nodes=[address]) api.LocalLB.NodeAddressV2.delete_node_address(nodes=[address])
result = True result = True
except bigsuds.OperationFailed, e: except bigsuds.OperationFailed as e:
if "is referenced by a member of pool" in str(e): if "is referenced by a member of pool" in str(e):
result = False result = False
else: else:
@ -345,14 +369,17 @@ def delete_node_address(api, address):
raise raise
return result return result
def remove_pool_member(api, pool, address, port): def remove_pool_member(api, pool, address, port):
members = [{'address': address, 'port': port}] members = [{'address': address, 'port': port}]
api.LocalLB.Pool.remove_member_v2(pool_names=[pool], members=[members]) api.LocalLB.Pool.remove_member_v2(pool_names=[pool], members=[members])
def add_pool_member(api, pool, address, port): def add_pool_member(api, pool, address, port):
members = [{'address': address, 'port': port}] members = [{'address': address, 'port': port}]
api.LocalLB.Pool.add_member_v2(pool_names=[pool], members=[members]) api.LocalLB.Pool.add_member_v2(pool_names=[pool], members=[members])
def main(): def main():
lb_method_choices = ['round_robin', 'ratio_member', lb_method_choices = ['round_robin', 'ratio_member',
'least_connection_member', 'observed_member', 'least_connection_member', 'observed_member',
@ -371,23 +398,24 @@ def main():
service_down_choices = ['none', 'reset', 'drop', 'reselect'] service_down_choices = ['none', 'reset', 'drop', 'reselect']
argument_spec=f5_argument_spec(); argument_spec = f5_argument_spec()
argument_spec.update(dict(
name = dict(type='str', required=True, aliases=['pool']), meta_args = dict(
lb_method = dict(type='str', choices=lb_method_choices), name=dict(type='str', required=True, aliases=['pool']),
monitor_type = dict(type='str', choices=monitor_type_choices), lb_method=dict(type='str', choices=lb_method_choices),
quorum = dict(type='int'), monitor_type=dict(type='str', choices=monitor_type_choices),
monitors = dict(type='list'), quorum=dict(type='int'),
slow_ramp_time = dict(type='int'), monitors=dict(type='list'),
reselect_tries = dict(type='int'), slow_ramp_time=dict(type='int'),
service_down_action = dict(type='str', choices=service_down_choices), reselect_tries=dict(type='int'),
host = dict(type='str', aliases=['address']), service_down_action=dict(type='str', choices=service_down_choices),
port = dict(type='int') host=dict(type='str', aliases=['address']),
) port=dict(type='int')
) )
argument_spec.update(meta_args)
module = AnsibleModule( module = AnsibleModule(
argument_spec = argument_spec, argument_spec=argument_spec,
supports_check_mode=True supports_check_mode=True
) )
@ -408,7 +436,7 @@ def main():
validate_certs = module.params['validate_certs'] validate_certs = module.params['validate_certs']
name = module.params['name'] name = module.params['name']
pool = fq_name(partition,name) pool = fq_name(partition, name)
lb_method = module.params['lb_method'] lb_method = module.params['lb_method']
if lb_method: if lb_method:
lb_method = lb_method.lower() lb_method = lb_method.lower()
@ -427,7 +455,7 @@ def main():
if service_down_action: if service_down_action:
service_down_action = service_down_action.lower() service_down_action = service_down_action.lower()
host = module.params['host'] host = module.params['host']
address = fq_name(partition,host) address = fq_name(partition, host)
port = module.params['port'] port = module.params['port']
# sanity check user supplied values # sanity check user supplied values
@ -479,7 +507,7 @@ def main():
try: try:
remove_pool(api, pool) remove_pool(api, pool)
result = {'changed': True} result = {'changed': True}
except bigsuds.OperationFailed, e: except bigsuds.OperationFailed as e:
if "was not found" in str(e): if "was not found" in str(e):
result = {'changed': False} result = {'changed': False}
else: else:
@ -502,7 +530,7 @@ def main():
try: try:
create_pool(api, pool, lb_method) create_pool(api, pool, lb_method)
result = {'changed': True} result = {'changed': True}
except bigsuds.OperationFailed, e: except bigsuds.OperationFailed as e:
if "already exists" in str(e): if "already exists" in str(e):
update = True update = True
else: else:
@ -558,12 +586,11 @@ def main():
add_pool_member(api, pool, address, port) add_pool_member(api, pool, address, port)
result = {'changed': True} result = {'changed': True}
except Exception, e: except Exception as e:
module.fail_json(msg="received exception: %s" % e) module.fail_json(msg="received exception: %s" % e)
module.exit_json(**result) module.exit_json(**result)
# import module snippets
from ansible.module_utils.basic import * from ansible.module_utils.basic import *
from ansible.module_utils.f5 import * from ansible.module_utils.f5 import *

Loading…
Cancel
Save