1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Adds style conventions to bigip_pool_member (#2535)

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.
This commit is contained in:
Tim Rupp 2016-07-07 22:56:09 -07:00 committed by Matt Clay
parent 40bedf4f83
commit e28c285be7

View file

@ -1,6 +1,6 @@
#!/usr/bin/python #!/usr/bin/python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
#
# (c) 2013, Matt Hite <mhite@hotmail.com> # (c) 2013, Matt Hite <mhite@hotmail.com>
# #
# This file is part of Ansible # This file is part of Ansible
@ -21,19 +21,18 @@
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
module: bigip_pool_member module: bigip_pool_member
short_description: "Manages F5 BIG-IP LTM pool members" short_description: Manages F5 BIG-IP LTM pool members
description: 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" version_added: 1.4
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
- "Supersedes bigip_pool for managing pool members" - Supersedes bigip_pool for managing pool members
requirements: requirements:
- bigsuds - bigsuds
options: options:
@ -51,16 +50,10 @@ options:
description: description:
- BIG-IP username - BIG-IP username
required: true required: true
default: null
choices: []
aliases: []
password: password:
description: description:
- BIG-IP password - BIG-IP password
required: true required: true
default: null
choices: []
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
@ -68,144 +61,134 @@ options:
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
- no
version_added: 2.0
state: state:
description: description:
- Pool member state - Pool member state
required: true required: true
default: present default: present
choices: ['present', 'absent'] choices:
aliases: [] - present
- absent
session_state: session_state:
description: description:
- Set new session availability status for pool member - Set new session availability status for pool member
version_added: "1.9" version_added: 2.0
required: false required: false
default: null default: null
choices: ['enabled', 'disabled'] choices:
aliases: [] - enabled
- disabled
monitor_state: monitor_state:
description: description:
- Set monitor availability status for pool member - Set monitor availability status for pool member
version_added: "1.9" version_added: 2.0
required: false required: false
default: null default: null
choices: ['enabled', 'disabled'] choices:
aliases: [] - enabled
- disabled
pool: pool:
description: description:
- Pool name. This pool must exist. - Pool name. This pool must exist.
required: true required: true
default: null
choices: []
aliases: []
partition: partition:
description: description:
- Partition - Partition
required: false required: false
default: 'Common' default: 'Common'
choices: []
aliases: []
host: host:
description: description:
- Pool member IP - Pool member IP
required: true required: true
default: null aliases:
choices: [] - address
aliases: ['address', 'name'] - name
port: port:
description: description:
- Pool member port - Pool member port
required: true required: true
default: null
choices: []
aliases: []
connection_limit: connection_limit:
description: description:
- Pool member connection limit. Setting this to 0 disables the limit. - Pool member connection limit. Setting this to 0 disables the limit.
required: false required: false
default: null default: null
choices: []
aliases: []
description: description:
description: description:
- Pool member description - Pool member description
required: false required: false
default: null default: null
choices: []
aliases: []
rate_limit: rate_limit:
description: description:
- Pool member rate limit (connections-per-second). Setting this to 0 disables the limit. - Pool member rate limit (connections-per-second). Setting this to 0
disables the limit.
required: false required: false
default: null default: null
choices: []
aliases: []
ratio: ratio:
description: description:
- Pool member ratio weight. Valid values range from 1 through 100. New pool members -- unless overriden with this value -- default to 1. - Pool member ratio weight. Valid values range from 1 through 100.
New pool members -- unless overriden with this value -- default
to 1.
required: false required: false
default: null default: null
preserve_node: preserve_node:
description: description:
- When state is absent and the pool member is no longer referenced in other pools, the default behavior removes the unused node object. Setting this to 'yes' disables this behavior. - 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 required: false
default: 'no' default: 'no'
choices: ['yes', 'no'] choices:
- yes
- no
version_added: 2.1 version_added: 2.1
''' '''
EXAMPLES = ''' EXAMPLES = '''
## playbook task examples:
---
# file bigip-test.yml
# ...
- hosts: bigip-test
tasks:
- name: Add pool member - name: Add pool member
local_action: > bigip_pool_member:
bigip_pool_member server: "lb.mydomain.com"
server=lb.mydomain.com user: "admin"
user=admin password: "secret"
password=mysecret state: "present"
state=present pool: "my-pool"
pool=matthite-pool partition: "Common"
partition=matthite host: "{{ ansible_default_ipv4["address"] }}"
host="{{ ansible_default_ipv4["address"] }}" port: 80
port=80 description: "web server"
description="web server" connection_limit: 100
connection_limit=100 rate_limit: 50
rate_limit=50 ratio: 2
ratio=2 delegate_to: localhost
- name: Modify pool member ratio and description - name: Modify pool member ratio and description
local_action: > bigip_pool_member:
bigip_pool_member server: "lb.mydomain.com"
server=lb.mydomain.com user: "admin"
user=admin password: "secret"
password=mysecret state: "present"
state=present pool: "my-pool"
pool=matthite-pool partition: "Common"
partition=matthite host: "{{ ansible_default_ipv4["address"] }}"
host="{{ ansible_default_ipv4["address"] }}" port: 80
port=80 ratio: 1
ratio=1 description: "nginx server"
description="nginx server" delegate_to: localhost
- name: Remove pool member from pool - name: Remove pool member from pool
local_action: > bigip_pool_member:
bigip_pool_member server: "lb.mydomain.com"
server=lb.mydomain.com user: "admin"
user=admin password: "secret"
password=mysecret state: "absent"
state=absent pool: "my-pool"
pool=matthite-pool partition: "Common"
partition=matthite host: "{{ ansible_default_ipv4["address"] }}"
host="{{ ansible_default_ipv4["address"] }}" port: 80
port=80 delegate_to: localhost
# The BIG-IP GUI doesn't map directly to the API calls for "Pool -> # The BIG-IP GUI doesn't map directly to the API calls for "Pool ->
@ -222,28 +205,28 @@ EXAMPLES = '''
# See https://devcentral.f5.com/questions/icontrol-equivalent-call-for-b-node-down # See https://devcentral.f5.com/questions/icontrol-equivalent-call-for-b-node-down
- name: Force pool member offline - name: Force pool member offline
local_action: > bigip_pool_member:
bigip_pool_member server: "lb.mydomain.com"
server=lb.mydomain.com user: "admin"
user=admin password: "secret"
password=mysecret state: "present"
state=present session_state: "disabled"
session_state=disabled monitor_state: "disabled"
monitor_state=disabled pool: "my-pool"
pool=matthite-pool partition: "Common"
partition=matthite host: "{{ ansible_default_ipv4["address"] }}"
host="{{ ansible_default_ipv4["address"] }}" port: 80
port=80 delegate_to: localhost
''' '''
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:
@ -251,6 +234,7 @@ def pool_exists(api, pool):
raise raise
return result return result
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
@ -259,7 +243,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:
@ -267,12 +251,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:
@ -280,75 +265,139 @@ 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 get_connection_limit(api, pool, address, port): def get_connection_limit(api, pool, address, port):
members = [{'address': address, 'port': port}] members = [{'address': address, 'port': port}]
result = api.LocalLB.Pool.get_member_connection_limit(pool_names=[pool], members=[members])[0][0] result = api.LocalLB.Pool.get_member_connection_limit(
pool_names=[pool],
members=[members]
)[0][0]
return result return result
def set_connection_limit(api, pool, address, port, limit): def set_connection_limit(api, pool, address, port, limit):
members = [{'address': address, 'port': port}] members = [{'address': address, 'port': port}]
api.LocalLB.Pool.set_member_connection_limit(pool_names=[pool], members=[members], limits=[[limit]]) api.LocalLB.Pool.set_member_connection_limit(
pool_names=[pool],
members=[members],
limits=[[limit]]
)
def get_description(api, pool, address, port): def get_description(api, pool, address, port):
members = [{'address': address, 'port': port}] members = [{'address': address, 'port': port}]
result = api.LocalLB.Pool.get_member_description(pool_names=[pool], members=[members])[0][0] result = api.LocalLB.Pool.get_member_description(
pool_names=[pool],
members=[members]
)[0][0]
return result return result
def set_description(api, pool, address, port, description): def set_description(api, pool, address, port, description):
members = [{'address': address, 'port': port}] members = [{'address': address, 'port': port}]
api.LocalLB.Pool.set_member_description(pool_names=[pool], members=[members], descriptions=[[description]]) api.LocalLB.Pool.set_member_description(
pool_names=[pool],
members=[members],
descriptions=[[description]]
)
def get_rate_limit(api, pool, address, port): def get_rate_limit(api, pool, address, port):
members = [{'address': address, 'port': port}] members = [{'address': address, 'port': port}]
result = api.LocalLB.Pool.get_member_rate_limit(pool_names=[pool], members=[members])[0][0] result = api.LocalLB.Pool.get_member_rate_limit(
pool_names=[pool],
members=[members]
)[0][0]
return result return result
def set_rate_limit(api, pool, address, port, limit): def set_rate_limit(api, pool, address, port, limit):
members = [{'address': address, 'port': port}] members = [{'address': address, 'port': port}]
api.LocalLB.Pool.set_member_rate_limit(pool_names=[pool], members=[members], limits=[[limit]]) api.LocalLB.Pool.set_member_rate_limit(
pool_names=[pool],
members=[members],
limits=[[limit]]
)
def get_ratio(api, pool, address, port): def get_ratio(api, pool, address, port):
members = [{'address': address, 'port': port}] members = [{'address': address, 'port': port}]
result = api.LocalLB.Pool.get_member_ratio(pool_names=[pool], members=[members])[0][0] result = api.LocalLB.Pool.get_member_ratio(
pool_names=[pool],
members=[members]
)[0][0]
return result return result
def set_ratio(api, pool, address, port, ratio): def set_ratio(api, pool, address, port, ratio):
members = [{'address': address, 'port': port}] members = [{'address': address, 'port': port}]
api.LocalLB.Pool.set_member_ratio(pool_names=[pool], members=[members], ratios=[[ratio]]) api.LocalLB.Pool.set_member_ratio(
pool_names=[pool],
members=[members],
ratios=[[ratio]]
)
def set_member_session_enabled_state(api, pool, address, port, session_state): def set_member_session_enabled_state(api, pool, address, port, session_state):
members = [{'address': address, 'port': port}] members = [{'address': address, 'port': port}]
session_state = ["STATE_%s" % session_state.strip().upper()] session_state = ["STATE_%s" % session_state.strip().upper()]
api.LocalLB.Pool.set_member_session_enabled_state(pool_names=[pool], members=[members], session_states=[session_state]) api.LocalLB.Pool.set_member_session_enabled_state(
pool_names=[pool],
members=[members],
session_states=[session_state]
)
def get_member_session_status(api, pool, address, port): def get_member_session_status(api, pool, address, port):
members = [{'address': address, 'port': port}] members = [{'address': address, 'port': port}]
result = api.LocalLB.Pool.get_member_session_status(pool_names=[pool], members=[members])[0][0] result = api.LocalLB.Pool.get_member_session_status(
pool_names=[pool],
members=[members]
)[0][0]
result = result.split("SESSION_STATUS_")[-1].lower() result = result.split("SESSION_STATUS_")[-1].lower()
return result return result
def set_member_monitor_state(api, pool, address, port, monitor_state): def set_member_monitor_state(api, pool, address, port, monitor_state):
members = [{'address': address, 'port': port}] members = [{'address': address, 'port': port}]
monitor_state = ["STATE_%s" % monitor_state.strip().upper()] monitor_state = ["STATE_%s" % monitor_state.strip().upper()]
api.LocalLB.Pool.set_member_monitor_state(pool_names=[pool], members=[members], monitor_states=[monitor_state]) api.LocalLB.Pool.set_member_monitor_state(
pool_names=[pool],
members=[members],
monitor_states=[monitor_state]
)
def get_member_monitor_status(api, pool, address, port): def get_member_monitor_status(api, pool, address, port):
members = [{'address': address, 'port': port}] members = [{'address': address, 'port': port}]
result = api.LocalLB.Pool.get_member_monitor_status(pool_names=[pool], members=[members])[0][0] result = api.LocalLB.Pool.get_member_monitor_status(
pool_names=[pool],
members=[members]
)[0][0]
result = result.split("MONITOR_STATUS_")[-1].lower() result = result.split("MONITOR_STATUS_")[-1].lower()
return result return result
def main(): def main():
argument_spec = f5_argument_spec() argument_spec = f5_argument_spec()
argument_spec.update(dict(
meta_args = dict(
session_state=dict(type='str', choices=['enabled', 'disabled']), session_state=dict(type='str', choices=['enabled', 'disabled']),
monitor_state=dict(type='str', choices=['enabled', 'disabled']), monitor_state=dict(type='str', choices=['enabled', 'disabled']),
pool=dict(type='str', required=True), pool=dict(type='str', required=True),
@ -360,16 +409,13 @@ def main():
ratio=dict(type='int'), ratio=dict(type='int'),
preserve_node=dict(type='bool', default=False) preserve_node=dict(type='bool', default=False)
) )
) 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
) )
if not bigsuds_found:
module.fail_json(msg="the python bigsuds module is required")
if module.params['validate_certs']: if module.params['validate_certs']:
import ssl import ssl
if not hasattr(ssl, 'SSLContext'): if not hasattr(ssl, 'SSLContext'):
@ -395,9 +441,6 @@ def main():
port = module.params['port'] port = module.params['port']
preserve_node = module.params['preserve_node'] preserve_node = module.params['preserve_node']
# sanity check user supplied values
if (host and port is None) or (port is not None and not host): if (host and port is None) or (port is not None and not host):
module.fail_json(msg="both host and port must be supplied") module.fail_json(msg="both host and port must be supplied")
@ -478,12 +521,11 @@ def main():
set_member_monitor_state(api, pool, address, port, monitor_state) set_member_monitor_state(api, pool, address, port, monitor_state)
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 *