2014-09-26 01:01:01 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
2016-07-08 05:56:09 +00:00
|
|
|
#
|
2017-10-04 19:16:17 +00:00
|
|
|
# Copyright (c) 2017 F5 Networks Inc.
|
|
|
|
# Copyright (c) 2013 Matt Hite <mhite@hotmail.com>
|
|
|
|
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
2014-09-26 01:01:01 +00:00
|
|
|
|
2018-01-17 05:02:33 +00:00
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
|
2017-08-16 03:16:38 +00:00
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
2017-03-14 16:07:22 +00:00
|
|
|
'status': ['preview'],
|
|
|
|
'supported_by': 'community'}
|
|
|
|
|
2018-01-17 05:02:33 +00:00
|
|
|
DOCUMENTATION = r'''
|
2014-09-26 01:01:01 +00:00
|
|
|
---
|
|
|
|
module: bigip_pool_member
|
2016-07-08 05:56:09 +00:00
|
|
|
short_description: Manages F5 BIG-IP LTM pool members
|
2014-09-26 01:01:01 +00:00
|
|
|
description:
|
2018-01-17 05:02:33 +00:00
|
|
|
- Manages F5 BIG-IP LTM pool members via iControl SOAP API.
|
2016-07-08 05:56:09 +00:00
|
|
|
version_added: 1.4
|
2016-06-23 09:33:49 +00:00
|
|
|
author:
|
2016-07-08 05:56:09 +00:00
|
|
|
- Matt Hite (@mhite)
|
|
|
|
- Tim Rupp (@caphrim007)
|
2014-09-26 01:01:01 +00:00
|
|
|
notes:
|
2016-07-08 05:56:09 +00:00
|
|
|
- Requires BIG-IP software version >= 11
|
|
|
|
- F5 developed module 'bigsuds' required (see http://devcentral.f5.com)
|
|
|
|
- Best run as a local_action in your playbook
|
|
|
|
- Supersedes bigip_pool for managing pool members
|
2014-09-26 01:01:01 +00:00
|
|
|
requirements:
|
2016-07-08 05:56:09 +00:00
|
|
|
- bigsuds
|
2014-09-26 01:01:01 +00:00
|
|
|
options:
|
2016-07-08 05:56:09 +00:00
|
|
|
state:
|
|
|
|
description:
|
2018-01-17 05:02:33 +00:00
|
|
|
- Pool member state.
|
|
|
|
required: True
|
2016-07-08 05:56:09 +00:00
|
|
|
default: present
|
|
|
|
choices:
|
|
|
|
- present
|
|
|
|
- absent
|
|
|
|
session_state:
|
|
|
|
description:
|
2018-01-17 05:02:33 +00:00
|
|
|
- Set new session availability status for pool member.
|
2016-07-08 05:56:09 +00:00
|
|
|
version_added: 2.0
|
|
|
|
choices:
|
|
|
|
- enabled
|
|
|
|
- disabled
|
|
|
|
monitor_state:
|
|
|
|
description:
|
2018-01-17 05:02:33 +00:00
|
|
|
- Set monitor availability status for pool member.
|
2016-07-08 05:56:09 +00:00
|
|
|
version_added: 2.0
|
|
|
|
choices:
|
|
|
|
- enabled
|
|
|
|
- disabled
|
|
|
|
pool:
|
|
|
|
description:
|
|
|
|
- Pool name. This pool must exist.
|
2018-01-17 05:02:33 +00:00
|
|
|
required: True
|
2016-07-08 05:56:09 +00:00
|
|
|
partition:
|
|
|
|
description:
|
|
|
|
- Partition
|
2018-01-17 05:02:33 +00:00
|
|
|
default: Common
|
2016-07-08 05:56:09 +00:00
|
|
|
host:
|
|
|
|
description:
|
2018-01-17 05:02:33 +00:00
|
|
|
- Pool member IP.
|
|
|
|
required: True
|
2016-07-08 05:56:09 +00:00
|
|
|
aliases:
|
|
|
|
- address
|
|
|
|
- name
|
|
|
|
port:
|
2014-09-26 01:01:01 +00:00
|
|
|
description:
|
2018-01-17 05:02:33 +00:00
|
|
|
- Pool member port.
|
|
|
|
required: True
|
2016-07-08 05:56:09 +00:00
|
|
|
connection_limit:
|
|
|
|
description:
|
|
|
|
- Pool member connection limit. Setting this to 0 disables the limit.
|
|
|
|
description:
|
|
|
|
description:
|
2018-01-17 05:02:33 +00:00
|
|
|
- Pool member description.
|
2016-07-08 05:56:09 +00:00
|
|
|
rate_limit:
|
|
|
|
description:
|
|
|
|
- Pool member rate limit (connections-per-second). Setting this to 0
|
|
|
|
disables the limit.
|
|
|
|
ratio:
|
|
|
|
description:
|
|
|
|
- Pool member ratio weight. Valid values range from 1 through 100.
|
2016-12-11 02:50:09 +00:00
|
|
|
New pool members -- unless overridden with this value -- default
|
2016-07-08 05:56:09 +00:00
|
|
|
to 1.
|
|
|
|
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.
|
2018-01-17 05:02:33 +00:00
|
|
|
default: no
|
2016-07-08 05:56:09 +00:00
|
|
|
choices:
|
|
|
|
- yes
|
|
|
|
- no
|
|
|
|
version_added: 2.1
|
2018-01-20 18:40:20 +00:00
|
|
|
priority_group:
|
|
|
|
description:
|
|
|
|
- Specifies a number representing the priority group for the pool member.
|
|
|
|
- When adding a new member, the default is 0, meaning that the member has no priority.
|
|
|
|
- To specify a priority, you must activate priority group usage when you
|
|
|
|
create a new pool or when adding or removing pool members. When activated,
|
|
|
|
the system load balances traffic according to the priority group number
|
|
|
|
assigned to the pool member.
|
|
|
|
- The higher the number, the higher the priority, so a member with a priority
|
|
|
|
of 3 has higher priority than a member with a priority of 1.
|
|
|
|
version_added: 2.5
|
2016-08-23 17:08:41 +00:00
|
|
|
extends_documentation_fragment: f5
|
2014-09-26 01:01:01 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = '''
|
2016-07-08 05:56:09 +00:00
|
|
|
- name: Add pool member
|
|
|
|
bigip_pool_member:
|
2018-01-17 05:02:33 +00:00
|
|
|
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
|
2016-07-08 05:56:09 +00:00
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
- name: Modify pool member ratio and description
|
|
|
|
bigip_pool_member:
|
2018-01-17 05:02:33 +00:00
|
|
|
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
|
2016-07-08 05:56:09 +00:00
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
- name: Remove pool member from pool
|
|
|
|
bigip_pool_member:
|
2018-01-17 05:02:33 +00:00
|
|
|
server: lb.mydomain.com
|
|
|
|
user: admin
|
|
|
|
password: secret
|
|
|
|
state: absent
|
|
|
|
pool: my-pool
|
|
|
|
partition: Common
|
|
|
|
host: "{{ ansible_default_ipv4['address'] }}"
|
|
|
|
port: 80
|
2016-07-08 05:56:09 +00:00
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
|
|
|
|
# The BIG-IP GUI doesn't map directly to the API calls for "Pool ->
|
|
|
|
# Members -> State". The following states map to API monitor
|
|
|
|
# and session states.
|
|
|
|
#
|
|
|
|
# Enabled (all traffic allowed):
|
|
|
|
# monitor_state=enabled, session_state=enabled
|
|
|
|
# Disabled (only persistent or active connections allowed):
|
|
|
|
# monitor_state=enabled, session_state=disabled
|
|
|
|
# Forced offline (only active connections allowed):
|
|
|
|
# monitor_state=disabled, session_state=disabled
|
|
|
|
#
|
|
|
|
# See https://devcentral.f5.com/questions/icontrol-equivalent-call-for-b-node-down
|
|
|
|
|
|
|
|
- name: Force pool member offline
|
|
|
|
bigip_pool_member:
|
2018-01-17 05:02:33 +00:00
|
|
|
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
|
2016-07-08 05:56:09 +00:00
|
|
|
delegate_to: localhost
|
2014-09-26 01:01:01 +00:00
|
|
|
'''
|
|
|
|
|
2018-01-17 05:02:33 +00:00
|
|
|
try:
|
|
|
|
import bigsuds
|
|
|
|
HAS_BIGSUDS = True
|
|
|
|
except ImportError:
|
|
|
|
pass # Handled by f5_utils.bigsuds_found
|
|
|
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
2018-01-20 04:25:47 +00:00
|
|
|
from ansible.module_utils.basic import env_fallback
|
2018-01-17 05:02:33 +00:00
|
|
|
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
|
|
|
|
|
2016-07-08 05:56:09 +00:00
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
def pool_exists(api, pool):
|
|
|
|
# hack to determine if pool exists
|
|
|
|
result = False
|
|
|
|
try:
|
|
|
|
api.LocalLB.Pool.get_object_status(pool_names=[pool])
|
|
|
|
result = True
|
2016-07-08 05:56:09 +00:00
|
|
|
except bigsuds.OperationFailed as e:
|
2014-09-26 01:01:01 +00:00
|
|
|
if "was not found" in str(e):
|
|
|
|
result = False
|
|
|
|
else:
|
|
|
|
# genuine exception
|
|
|
|
raise
|
|
|
|
return result
|
|
|
|
|
2016-07-08 05:56:09 +00:00
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
def member_exists(api, pool, address, port):
|
|
|
|
# hack to determine if member exists
|
|
|
|
result = False
|
|
|
|
try:
|
|
|
|
members = [{'address': address, 'port': port}]
|
|
|
|
api.LocalLB.Pool.get_member_object_status(pool_names=[pool],
|
|
|
|
members=[members])
|
|
|
|
result = True
|
2016-07-08 05:56:09 +00:00
|
|
|
except bigsuds.OperationFailed as e:
|
2014-09-26 01:01:01 +00:00
|
|
|
if "was not found" in str(e):
|
|
|
|
result = False
|
|
|
|
else:
|
|
|
|
# genuine exception
|
|
|
|
raise
|
|
|
|
return result
|
|
|
|
|
2016-07-08 05:56:09 +00:00
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
def delete_node_address(api, address):
|
|
|
|
result = False
|
|
|
|
try:
|
|
|
|
api.LocalLB.NodeAddressV2.delete_node_address(nodes=[address])
|
|
|
|
result = True
|
2016-07-08 05:56:09 +00:00
|
|
|
except bigsuds.OperationFailed as e:
|
2014-09-26 01:01:01 +00:00
|
|
|
if "is referenced by a member of pool" in str(e):
|
|
|
|
result = False
|
|
|
|
else:
|
|
|
|
# genuine exception
|
|
|
|
raise
|
|
|
|
return result
|
|
|
|
|
2016-07-08 05:56:09 +00:00
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
def remove_pool_member(api, pool, address, port):
|
|
|
|
members = [{'address': address, 'port': port}]
|
2016-07-08 05:56:09 +00:00
|
|
|
api.LocalLB.Pool.remove_member_v2(
|
|
|
|
pool_names=[pool],
|
|
|
|
members=[members]
|
|
|
|
)
|
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
|
|
|
|
def add_pool_member(api, pool, address, port):
|
|
|
|
members = [{'address': address, 'port': port}]
|
2016-07-08 05:56:09 +00:00
|
|
|
api.LocalLB.Pool.add_member_v2(
|
|
|
|
pool_names=[pool],
|
|
|
|
members=[members]
|
|
|
|
)
|
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
|
|
|
|
def get_connection_limit(api, pool, address, port):
|
|
|
|
members = [{'address': address, 'port': port}]
|
2016-07-08 05:56:09 +00:00
|
|
|
result = api.LocalLB.Pool.get_member_connection_limit(
|
|
|
|
pool_names=[pool],
|
|
|
|
members=[members]
|
|
|
|
)[0][0]
|
2014-09-26 01:01:01 +00:00
|
|
|
return result
|
|
|
|
|
2016-07-08 05:56:09 +00:00
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
def set_connection_limit(api, pool, address, port, limit):
|
|
|
|
members = [{'address': address, 'port': port}]
|
2016-07-08 05:56:09 +00:00
|
|
|
api.LocalLB.Pool.set_member_connection_limit(
|
|
|
|
pool_names=[pool],
|
|
|
|
members=[members],
|
|
|
|
limits=[[limit]]
|
|
|
|
)
|
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
|
|
|
|
def get_description(api, pool, address, port):
|
|
|
|
members = [{'address': address, 'port': port}]
|
2016-07-08 05:56:09 +00:00
|
|
|
result = api.LocalLB.Pool.get_member_description(
|
|
|
|
pool_names=[pool],
|
|
|
|
members=[members]
|
|
|
|
)[0][0]
|
2014-09-26 01:01:01 +00:00
|
|
|
return result
|
|
|
|
|
2016-07-08 05:56:09 +00:00
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
def set_description(api, pool, address, port, description):
|
|
|
|
members = [{'address': address, 'port': port}]
|
2016-07-08 05:56:09 +00:00
|
|
|
api.LocalLB.Pool.set_member_description(
|
|
|
|
pool_names=[pool],
|
|
|
|
members=[members],
|
|
|
|
descriptions=[[description]]
|
|
|
|
)
|
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
|
|
|
|
def get_rate_limit(api, pool, address, port):
|
|
|
|
members = [{'address': address, 'port': port}]
|
2016-07-08 05:56:09 +00:00
|
|
|
result = api.LocalLB.Pool.get_member_rate_limit(
|
|
|
|
pool_names=[pool],
|
|
|
|
members=[members]
|
|
|
|
)[0][0]
|
2014-09-26 01:01:01 +00:00
|
|
|
return result
|
|
|
|
|
2016-07-08 05:56:09 +00:00
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
def set_rate_limit(api, pool, address, port, limit):
|
|
|
|
members = [{'address': address, 'port': port}]
|
2016-07-08 05:56:09 +00:00
|
|
|
api.LocalLB.Pool.set_member_rate_limit(
|
|
|
|
pool_names=[pool],
|
|
|
|
members=[members],
|
|
|
|
limits=[[limit]]
|
|
|
|
)
|
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
|
|
|
|
def get_ratio(api, pool, address, port):
|
|
|
|
members = [{'address': address, 'port': port}]
|
2016-07-08 05:56:09 +00:00
|
|
|
result = api.LocalLB.Pool.get_member_ratio(
|
|
|
|
pool_names=[pool],
|
|
|
|
members=[members]
|
|
|
|
)[0][0]
|
2014-09-26 01:01:01 +00:00
|
|
|
return result
|
|
|
|
|
2016-07-08 05:56:09 +00:00
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
def set_ratio(api, pool, address, port, ratio):
|
|
|
|
members = [{'address': address, 'port': port}]
|
2016-07-08 05:56:09 +00:00
|
|
|
api.LocalLB.Pool.set_member_ratio(
|
|
|
|
pool_names=[pool],
|
|
|
|
members=[members],
|
|
|
|
ratios=[[ratio]]
|
|
|
|
)
|
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
|
2017-08-01 14:15:54 +00:00
|
|
|
def get_priority_group(api, pool, address, port):
|
|
|
|
members = [{'address': address, 'port': port}]
|
|
|
|
result = api.LocalLB.Pool.get_member_priority(
|
|
|
|
pool_names=[pool],
|
|
|
|
members=[members]
|
|
|
|
)[0][0]
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def set_priority_group(api, pool, address, port, priority_group):
|
|
|
|
members = [{'address': address, 'port': port}]
|
|
|
|
api.LocalLB.Pool.set_member_priority(
|
|
|
|
pool_names=[pool],
|
|
|
|
members=[members],
|
|
|
|
priorities=[[priority_group]]
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2015-02-25 23:48:19 +00:00
|
|
|
def set_member_session_enabled_state(api, pool, address, port, session_state):
|
|
|
|
members = [{'address': address, 'port': port}]
|
|
|
|
session_state = ["STATE_%s" % session_state.strip().upper()]
|
2016-07-08 05:56:09 +00:00
|
|
|
api.LocalLB.Pool.set_member_session_enabled_state(
|
|
|
|
pool_names=[pool],
|
|
|
|
members=[members],
|
|
|
|
session_states=[session_state]
|
|
|
|
)
|
|
|
|
|
2015-02-25 23:48:19 +00:00
|
|
|
|
|
|
|
def get_member_session_status(api, pool, address, port):
|
|
|
|
members = [{'address': address, 'port': port}]
|
2016-07-08 05:56:09 +00:00
|
|
|
result = api.LocalLB.Pool.get_member_session_status(
|
|
|
|
pool_names=[pool],
|
|
|
|
members=[members]
|
|
|
|
)[0][0]
|
2015-02-25 23:48:19 +00:00
|
|
|
result = result.split("SESSION_STATUS_")[-1].lower()
|
|
|
|
return result
|
|
|
|
|
2016-07-08 05:56:09 +00:00
|
|
|
|
2015-02-25 23:48:19 +00:00
|
|
|
def set_member_monitor_state(api, pool, address, port, monitor_state):
|
|
|
|
members = [{'address': address, 'port': port}]
|
|
|
|
monitor_state = ["STATE_%s" % monitor_state.strip().upper()]
|
2016-07-08 05:56:09 +00:00
|
|
|
api.LocalLB.Pool.set_member_monitor_state(
|
|
|
|
pool_names=[pool],
|
|
|
|
members=[members],
|
|
|
|
monitor_states=[monitor_state]
|
|
|
|
)
|
|
|
|
|
2015-02-25 23:48:19 +00:00
|
|
|
|
|
|
|
def get_member_monitor_status(api, pool, address, port):
|
|
|
|
members = [{'address': address, 'port': port}]
|
2016-07-08 05:56:09 +00:00
|
|
|
result = api.LocalLB.Pool.get_member_monitor_status(
|
|
|
|
pool_names=[pool],
|
|
|
|
members=[members]
|
|
|
|
)[0][0]
|
2015-02-25 23:48:19 +00:00
|
|
|
result = result.split("MONITOR_STATUS_")[-1].lower()
|
|
|
|
return result
|
|
|
|
|
2016-07-08 05:56:09 +00:00
|
|
|
|
2014-09-26 01:01:01 +00:00
|
|
|
def main():
|
2018-01-17 05:02:33 +00:00
|
|
|
result = {}
|
|
|
|
argument_spec = f5_argument_spec
|
2016-07-08 05:56:09 +00:00
|
|
|
|
|
|
|
meta_args = dict(
|
|
|
|
session_state=dict(type='str', choices=['enabled', 'disabled']),
|
|
|
|
monitor_state=dict(type='str', choices=['enabled', 'disabled']),
|
|
|
|
pool=dict(type='str', required=True),
|
|
|
|
host=dict(type='str', required=True, aliases=['address', 'name']),
|
|
|
|
port=dict(type='int', required=True),
|
|
|
|
connection_limit=dict(type='int'),
|
|
|
|
description=dict(type='str'),
|
|
|
|
rate_limit=dict(type='int'),
|
|
|
|
ratio=dict(type='int'),
|
2017-08-01 14:15:54 +00:00
|
|
|
preserve_node=dict(type='bool', default=False),
|
2018-01-20 04:25:47 +00:00
|
|
|
priority_group=dict(type='int'),
|
|
|
|
state=dict(default='present', choices=['absent', 'present']),
|
|
|
|
partition=dict(
|
|
|
|
default='Common',
|
|
|
|
fallback=(env_fallback, ['F5_PARTITION'])
|
|
|
|
)
|
2014-09-26 01:01:01 +00:00
|
|
|
)
|
2016-07-08 05:56:09 +00:00
|
|
|
argument_spec.update(meta_args)
|
2014-09-26 01:01:01 +00:00
|
|
|
|
2015-06-03 06:22:18 +00:00
|
|
|
module = AnsibleModule(
|
2016-07-08 05:56:09 +00:00
|
|
|
argument_spec=argument_spec,
|
2015-06-03 06:22:18 +00:00
|
|
|
supports_check_mode=True
|
|
|
|
)
|
2014-09-26 01:01:01 +00:00
|
|
|
|
2018-01-17 05:02:33 +00:00
|
|
|
if not bigsuds_found:
|
|
|
|
module.fail_json(msg="the python bigsuds module is required")
|
|
|
|
|
2016-05-04 05:50:45 +00:00
|
|
|
if module.params['validate_certs']:
|
|
|
|
import ssl
|
|
|
|
if not hasattr(ssl, 'SSLContext'):
|
2017-03-23 01:50:28 +00:00
|
|
|
module.fail_json(
|
2018-01-17 05:02:33 +00:00
|
|
|
msg='bigsuds does not support verifying certificates with python < 2.7.9. '
|
|
|
|
'Either update python or set validate_certs=False on the task')
|
2016-05-04 05:50:45 +00:00
|
|
|
|
|
|
|
server = module.params['server']
|
2016-06-23 09:33:49 +00:00
|
|
|
server_port = module.params['server_port']
|
2016-05-04 05:50:45 +00:00
|
|
|
user = module.params['user']
|
|
|
|
password = module.params['password']
|
|
|
|
state = module.params['state']
|
|
|
|
partition = module.params['partition']
|
|
|
|
validate_certs = module.params['validate_certs']
|
|
|
|
|
2015-02-25 23:48:19 +00:00
|
|
|
session_state = module.params['session_state']
|
|
|
|
monitor_state = module.params['monitor_state']
|
2018-01-17 05:02:33 +00:00
|
|
|
pool = fqdn_name(partition, module.params['pool'])
|
2014-09-26 01:01:01 +00:00
|
|
|
connection_limit = module.params['connection_limit']
|
|
|
|
description = module.params['description']
|
|
|
|
rate_limit = module.params['rate_limit']
|
|
|
|
ratio = module.params['ratio']
|
2017-08-01 14:15:54 +00:00
|
|
|
priority_group = module.params['priority_group']
|
2014-09-26 01:01:01 +00:00
|
|
|
host = module.params['host']
|
2018-01-17 05:02:33 +00:00
|
|
|
address = fqdn_name(partition, host)
|
2014-09-26 01:01:01 +00:00
|
|
|
port = module.params['port']
|
2016-04-11 06:00:30 +00:00
|
|
|
preserve_node = module.params['preserve_node']
|
2014-09-26 01:01:01 +00:00
|
|
|
|
2016-03-30 16:29:34 +00:00
|
|
|
if (host and port is None) or (port is not None and not host):
|
2014-09-26 01:01:01 +00:00
|
|
|
module.fail_json(msg="both host and port must be supplied")
|
|
|
|
|
2016-03-30 16:29:34 +00:00
|
|
|
if 0 > port or port > 65535:
|
|
|
|
module.fail_json(msg="valid ports must be in range 0 - 65535")
|
2014-09-26 01:01:01 +00:00
|
|
|
|
|
|
|
try:
|
2016-06-23 09:33:49 +00:00
|
|
|
api = bigip_api(server, user, password, validate_certs, port=server_port)
|
2014-09-26 01:01:01 +00:00
|
|
|
if not pool_exists(api, pool):
|
|
|
|
module.fail_json(msg="pool %s does not exist" % pool)
|
|
|
|
result = {'changed': False} # default
|
|
|
|
|
|
|
|
if state == 'absent':
|
|
|
|
if member_exists(api, pool, address, port):
|
|
|
|
if not module.check_mode:
|
|
|
|
remove_pool_member(api, pool, address, port)
|
2016-04-11 06:00:30 +00:00
|
|
|
if preserve_node:
|
|
|
|
result = {'changed': True}
|
|
|
|
else:
|
|
|
|
deleted = delete_node_address(api, address)
|
|
|
|
result = {'changed': True, 'deleted': deleted}
|
2014-09-26 01:01:01 +00:00
|
|
|
else:
|
|
|
|
result = {'changed': True}
|
|
|
|
|
|
|
|
elif state == 'present':
|
|
|
|
if not member_exists(api, pool, address, port):
|
|
|
|
if not module.check_mode:
|
|
|
|
add_pool_member(api, pool, address, port)
|
|
|
|
if connection_limit is not None:
|
|
|
|
set_connection_limit(api, pool, address, port, connection_limit)
|
|
|
|
if description is not None:
|
|
|
|
set_description(api, pool, address, port, description)
|
|
|
|
if rate_limit is not None:
|
|
|
|
set_rate_limit(api, pool, address, port, rate_limit)
|
|
|
|
if ratio is not None:
|
|
|
|
set_ratio(api, pool, address, port, ratio)
|
2015-02-25 23:48:19 +00:00
|
|
|
if session_state is not None:
|
|
|
|
set_member_session_enabled_state(api, pool, address, port, session_state)
|
|
|
|
if monitor_state is not None:
|
|
|
|
set_member_monitor_state(api, pool, address, port, monitor_state)
|
2017-08-01 14:15:54 +00:00
|
|
|
if priority_group is not None:
|
|
|
|
set_priority_group(api, pool, address, port, priority_group)
|
2014-09-26 01:01:01 +00:00
|
|
|
result = {'changed': True}
|
|
|
|
else:
|
|
|
|
# pool member exists -- potentially modify attributes
|
|
|
|
if connection_limit is not None and connection_limit != get_connection_limit(api, pool, address, port):
|
|
|
|
if not module.check_mode:
|
|
|
|
set_connection_limit(api, pool, address, port, connection_limit)
|
|
|
|
result = {'changed': True}
|
|
|
|
if description is not None and description != get_description(api, pool, address, port):
|
|
|
|
if not module.check_mode:
|
|
|
|
set_description(api, pool, address, port, description)
|
|
|
|
result = {'changed': True}
|
|
|
|
if rate_limit is not None and rate_limit != get_rate_limit(api, pool, address, port):
|
|
|
|
if not module.check_mode:
|
|
|
|
set_rate_limit(api, pool, address, port, rate_limit)
|
|
|
|
result = {'changed': True}
|
|
|
|
if ratio is not None and ratio != get_ratio(api, pool, address, port):
|
|
|
|
if not module.check_mode:
|
|
|
|
set_ratio(api, pool, address, port, ratio)
|
|
|
|
result = {'changed': True}
|
2015-02-25 23:48:19 +00:00
|
|
|
if session_state is not None:
|
|
|
|
session_status = get_member_session_status(api, pool, address, port)
|
|
|
|
if session_state == 'enabled' and session_status == 'forced_disabled':
|
|
|
|
if not module.check_mode:
|
|
|
|
set_member_session_enabled_state(api, pool, address, port, session_state)
|
|
|
|
result = {'changed': True}
|
2016-08-23 07:26:40 +00:00
|
|
|
elif session_state == 'disabled' and session_status != 'forced_disabled':
|
2015-02-25 23:48:19 +00:00
|
|
|
if not module.check_mode:
|
|
|
|
set_member_session_enabled_state(api, pool, address, port, session_state)
|
|
|
|
result = {'changed': True}
|
|
|
|
if monitor_state is not None:
|
|
|
|
monitor_status = get_member_monitor_status(api, pool, address, port)
|
|
|
|
if monitor_state == 'enabled' and monitor_status == 'forced_down':
|
|
|
|
if not module.check_mode:
|
|
|
|
set_member_monitor_state(api, pool, address, port, monitor_state)
|
|
|
|
result = {'changed': True}
|
|
|
|
elif monitor_state == 'disabled' and monitor_status != 'forced_down':
|
|
|
|
if not module.check_mode:
|
|
|
|
set_member_monitor_state(api, pool, address, port, monitor_state)
|
|
|
|
result = {'changed': True}
|
2017-08-01 14:15:54 +00:00
|
|
|
if priority_group is not None and priority_group != get_priority_group(api, pool, address, port):
|
|
|
|
if not module.check_mode:
|
|
|
|
set_priority_group(api, pool, address, port, priority_group)
|
|
|
|
result = {'changed': True}
|
2014-09-26 01:01:01 +00:00
|
|
|
|
2016-07-08 05:56:09 +00:00
|
|
|
except Exception as e:
|
2014-09-26 01:01:01 +00:00
|
|
|
module.fail_json(msg="received exception: %s" % e)
|
|
|
|
|
|
|
|
module.exit_json(**result)
|
|
|
|
|
2016-04-25 19:34:18 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|