|
|
@ -94,21 +94,20 @@ options:
|
|
|
|
- reset
|
|
|
|
- reset
|
|
|
|
- drop
|
|
|
|
- drop
|
|
|
|
- reselect
|
|
|
|
- reselect
|
|
|
|
host:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- Pool member IP.
|
|
|
|
|
|
|
|
- Deprecated in 2.4. Use the C(bigip_pool_member) module instead.
|
|
|
|
|
|
|
|
aliases:
|
|
|
|
|
|
|
|
- address
|
|
|
|
|
|
|
|
port:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- Pool member port.
|
|
|
|
|
|
|
|
- Deprecated in 2.4. Use the C(bigip_pool_member) module instead.
|
|
|
|
|
|
|
|
partition:
|
|
|
|
partition:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Device partition to manage resources on.
|
|
|
|
- Device partition to manage resources on.
|
|
|
|
default: Common
|
|
|
|
default: Common
|
|
|
|
version_added: 2.5
|
|
|
|
version_added: 2.5
|
|
|
|
|
|
|
|
metdata:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- Arbitrary key/value pairs that you can attach to a pool. This is useful in
|
|
|
|
|
|
|
|
situations where you might want to annotate a pool to me managed by Ansible.
|
|
|
|
|
|
|
|
- Key names will be stored as strings; this includes names that are numbers.
|
|
|
|
|
|
|
|
- Values for all of the keys will be stored as strings; this includes values
|
|
|
|
|
|
|
|
that are numbers.
|
|
|
|
|
|
|
|
- Data will be persisted, not ephemeral.
|
|
|
|
|
|
|
|
version_added: 2.5
|
|
|
|
notes:
|
|
|
|
notes:
|
|
|
|
- Requires BIG-IP software version >= 12.
|
|
|
|
- Requires BIG-IP software version >= 12.
|
|
|
|
- F5 developed module 'F5-SDK' required (https://github.com/F5Networks/f5-common-python).
|
|
|
|
- F5 developed module 'F5-SDK' required (https://github.com/F5Networks/f5-common-python).
|
|
|
@ -131,7 +130,7 @@ EXAMPLES = r'''
|
|
|
|
state: present
|
|
|
|
state: present
|
|
|
|
name: my-pool
|
|
|
|
name: my-pool
|
|
|
|
partition: Common
|
|
|
|
partition: Common
|
|
|
|
lb_method: least_connection_member
|
|
|
|
lb_method: least-connection-member
|
|
|
|
slow_ramp_time: 120
|
|
|
|
slow_ramp_time: 120
|
|
|
|
delegate_to: localhost
|
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
|
|
|
@ -143,16 +142,16 @@ EXAMPLES = r'''
|
|
|
|
state: present
|
|
|
|
state: present
|
|
|
|
name: my-pool
|
|
|
|
name: my-pool
|
|
|
|
partition: Common
|
|
|
|
partition: Common
|
|
|
|
lb_method: round_robin
|
|
|
|
lb_method: round-robin
|
|
|
|
delegate_to: localhost
|
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
|
|
|
|
- name: Add pool member
|
|
|
|
- name: Add pool member
|
|
|
|
bigip_pool:
|
|
|
|
bigip_pool_member:
|
|
|
|
server: lb.mydomain.com
|
|
|
|
server: lb.mydomain.com
|
|
|
|
user: admin
|
|
|
|
user: admin
|
|
|
|
password: secret
|
|
|
|
password: secret
|
|
|
|
state: present
|
|
|
|
state: present
|
|
|
|
name: my-pool
|
|
|
|
pool: my-pool
|
|
|
|
partition: Common
|
|
|
|
partition: Common
|
|
|
|
host: "{{ ansible_default_ipv4['address'] }}"
|
|
|
|
host: "{{ ansible_default_ipv4['address'] }}"
|
|
|
|
port: 80
|
|
|
|
port: 80
|
|
|
@ -213,12 +212,12 @@ EXAMPLES = r'''
|
|
|
|
delegate_to: localhost
|
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
|
|
|
|
- name: Remove pool member from pool
|
|
|
|
- name: Remove pool member from pool
|
|
|
|
bigip_pool:
|
|
|
|
bigip_pool_member:
|
|
|
|
server: lb.mydomain.com
|
|
|
|
server: lb.mydomain.com
|
|
|
|
user: admin
|
|
|
|
user: admin
|
|
|
|
password: secret
|
|
|
|
password: secret
|
|
|
|
state: absent
|
|
|
|
state: absent
|
|
|
|
name: my-pool
|
|
|
|
pool: my-pool
|
|
|
|
partition: Common
|
|
|
|
partition: Common
|
|
|
|
host: "{{ ansible_default_ipv4['address'] }}"
|
|
|
|
host: "{{ ansible_default_ipv4['address'] }}"
|
|
|
|
port: 80
|
|
|
|
port: 80
|
|
|
@ -233,6 +232,19 @@ EXAMPLES = r'''
|
|
|
|
name: my-pool
|
|
|
|
name: my-pool
|
|
|
|
partition: Common
|
|
|
|
partition: Common
|
|
|
|
delegate_to: localhost
|
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Add metadata to pool
|
|
|
|
|
|
|
|
bigip_pool:
|
|
|
|
|
|
|
|
server: lb.mydomain.com
|
|
|
|
|
|
|
|
user: admin
|
|
|
|
|
|
|
|
password: secret
|
|
|
|
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
name: my-pool
|
|
|
|
|
|
|
|
partition: Common
|
|
|
|
|
|
|
|
metadata:
|
|
|
|
|
|
|
|
ansible: 2.4
|
|
|
|
|
|
|
|
updated_at: 2017-12-20T17:50:46Z
|
|
|
|
|
|
|
|
delegate_to: localhost
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
RETURN = r'''
|
|
|
|
RETURN = r'''
|
|
|
@ -266,16 +278,6 @@ lb_method:
|
|
|
|
returned: changed
|
|
|
|
returned: changed
|
|
|
|
type: string
|
|
|
|
type: string
|
|
|
|
sample: round-robin
|
|
|
|
sample: round-robin
|
|
|
|
host:
|
|
|
|
|
|
|
|
description: IP of pool member included in pool.
|
|
|
|
|
|
|
|
returned: changed
|
|
|
|
|
|
|
|
type: string
|
|
|
|
|
|
|
|
sample: 10.10.10.10
|
|
|
|
|
|
|
|
port:
|
|
|
|
|
|
|
|
description: Port of pool member included in pool.
|
|
|
|
|
|
|
|
returned: changed
|
|
|
|
|
|
|
|
type: int
|
|
|
|
|
|
|
|
sample: 80
|
|
|
|
|
|
|
|
slow_ramp_time:
|
|
|
|
slow_ramp_time:
|
|
|
|
description: The new value that is set for the slow ramp-up time.
|
|
|
|
description: The new value that is set for the slow ramp-up time.
|
|
|
|
returned: changed
|
|
|
|
returned: changed
|
|
|
@ -286,6 +288,11 @@ reselect_tries:
|
|
|
|
returned: changed
|
|
|
|
returned: changed
|
|
|
|
type: int
|
|
|
|
type: int
|
|
|
|
sample: 10
|
|
|
|
sample: 10
|
|
|
|
|
|
|
|
metadata:
|
|
|
|
|
|
|
|
description: The new value of the pool.
|
|
|
|
|
|
|
|
returned: changed
|
|
|
|
|
|
|
|
type: dict
|
|
|
|
|
|
|
|
sample: {'key1': 'foo', 'key2': 'bar'}
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
import re
|
|
|
|
import re
|
|
|
@ -320,19 +327,19 @@ class Parameters(AnsibleF5Parameters):
|
|
|
|
|
|
|
|
|
|
|
|
api_attributes = [
|
|
|
|
api_attributes = [
|
|
|
|
'description', 'name', 'loadBalancingMode', 'monitor', 'slowRampTime',
|
|
|
|
'description', 'name', 'loadBalancingMode', 'monitor', 'slowRampTime',
|
|
|
|
'reselectTries', 'serviceDownAction'
|
|
|
|
'reselectTries', 'serviceDownAction', 'metadata'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
returnables = [
|
|
|
|
returnables = [
|
|
|
|
'monitor_type', 'quorum', 'monitors', 'service_down_action',
|
|
|
|
'monitor_type', 'quorum', 'monitors', 'service_down_action',
|
|
|
|
'description', 'lb_method', 'host', 'port', 'slow_ramp_time',
|
|
|
|
'description', 'lb_method', 'slow_ramp_time',
|
|
|
|
'reselect_tries', 'monitor', 'member_name', 'name', 'partition'
|
|
|
|
'reselect_tries', 'monitor', 'name', 'partition', 'metadata'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
updatables = [
|
|
|
|
updatables = [
|
|
|
|
'monitor_type', 'quorum', 'monitors', 'service_down_action',
|
|
|
|
'monitor_type', 'quorum', 'monitors', 'service_down_action',
|
|
|
|
'description', 'lb_method', 'slow_ramp_time', 'reselect_tries',
|
|
|
|
'description', 'lb_method', 'slow_ramp_time', 'reselect_tries',
|
|
|
|
'host', 'port'
|
|
|
|
'metadata'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, params=None):
|
|
|
|
def __init__(self, params=None):
|
|
|
@ -366,36 +373,11 @@ class Parameters(AnsibleF5Parameters):
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def lb_method(self):
|
|
|
|
def lb_method(self):
|
|
|
|
lb_map = {
|
|
|
|
|
|
|
|
'ratio_node_address': 'ratio-node',
|
|
|
|
|
|
|
|
'dynamic_ratio': 'dynamic-ratio-node',
|
|
|
|
|
|
|
|
'least_connection_member': 'least-connections-member',
|
|
|
|
|
|
|
|
'least_connection_node_address': 'least-connections-node',
|
|
|
|
|
|
|
|
'fastest_node_address': 'fastest-node',
|
|
|
|
|
|
|
|
'observed_node_address': 'observed-node',
|
|
|
|
|
|
|
|
'predictive_node_address': 'predictive-node',
|
|
|
|
|
|
|
|
'weighted_least_connection_member': 'weighted-least-connections-member',
|
|
|
|
|
|
|
|
'weighted_least_connection_node_address': 'weighted-least-connections-node',
|
|
|
|
|
|
|
|
'ratio_least_connection_member': 'ratio-least-connections-member',
|
|
|
|
|
|
|
|
'ratio_least_connection_node_address': 'ratio-least-connections-node'
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
lb_method = self._values['lb_method']
|
|
|
|
lb_method = self._values['lb_method']
|
|
|
|
if lb_method is None:
|
|
|
|
if lb_method is None:
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
spec = ArgumentSpec()
|
|
|
|
spec = ArgumentSpec()
|
|
|
|
if lb_method in spec.lb_choice_removed:
|
|
|
|
|
|
|
|
raise F5ModuleError(
|
|
|
|
|
|
|
|
"The provided lb_method is not supported"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
if lb_method in spec.lb_choice_deprecated:
|
|
|
|
|
|
|
|
self._values['__warnings'].append(
|
|
|
|
|
|
|
|
dict(
|
|
|
|
|
|
|
|
msg="The provided lb_method '{0}' is deprecated".format(lb_method),
|
|
|
|
|
|
|
|
version='2.4'
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
lb_method = lb_map.get(lb_method, lb_method.replace('_', '-'))
|
|
|
|
|
|
|
|
if lb_method not in spec.lb_choice:
|
|
|
|
if lb_method not in spec.lb_choice:
|
|
|
|
raise F5ModuleError('Provided lb_method is unknown')
|
|
|
|
raise F5ModuleError('Provided lb_method is unknown')
|
|
|
|
return lb_method
|
|
|
|
return lb_method
|
|
|
@ -405,16 +387,6 @@ class Parameters(AnsibleF5Parameters):
|
|
|
|
return '/{0}/{1}'.format(self.partition, value)
|
|
|
|
return '/{0}/{1}'.format(self.partition, value)
|
|
|
|
return value
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
|
|
|
def monitors_list(self):
|
|
|
|
|
|
|
|
if self._values['monitors'] is None:
|
|
|
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
result = re.findall(r'/\w+/[^\s}]+', self._values['monitors'])
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
|
|
return self._values['monitors']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def monitors(self):
|
|
|
|
def monitors(self):
|
|
|
|
if self._values['monitors'] is None:
|
|
|
|
if self._values['monitors'] is None:
|
|
|
@ -425,12 +397,34 @@ class Parameters(AnsibleF5Parameters):
|
|
|
|
result = 'min %s of { %s }' % (self.quorum, monitors)
|
|
|
|
result = 'min %s of { %s }' % (self.quorum, monitors)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
result = ' and '.join(monitors).strip()
|
|
|
|
result = ' and '.join(monitors).strip()
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def api_params(self):
|
|
|
|
|
|
|
|
result = {}
|
|
|
|
|
|
|
|
for api_attribute in self.api_attributes:
|
|
|
|
|
|
|
|
if self.api_map is not None and api_attribute in self.api_map:
|
|
|
|
|
|
|
|
result[api_attribute] = getattr(
|
|
|
|
|
|
|
|
self, self.api_map[api_attribute]
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
result[api_attribute] = getattr(self, api_attribute)
|
|
|
|
|
|
|
|
result = self._filter_params(result)
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _verify_quorum_type(self, quorum):
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
if quorum is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
return int(quorum)
|
|
|
|
|
|
|
|
except ValueError:
|
|
|
|
|
|
|
|
raise F5ModuleError(
|
|
|
|
|
|
|
|
"The specified 'quorum' must be an integer."
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ApiParameters(Parameters):
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def quorum(self):
|
|
|
|
def quorum(self):
|
|
|
|
if self.kind == 'tm:ltm:pool:poolstate':
|
|
|
|
|
|
|
|
if self._values['monitors'] is None:
|
|
|
|
if self._values['monitors'] is None:
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
pattern = r'min\s+(?P<quorum>\d+)\s+of'
|
|
|
|
pattern = r'min\s+(?P<quorum>\d+)\s+of'
|
|
|
@ -439,20 +433,11 @@ class Parameters(AnsibleF5Parameters):
|
|
|
|
quorum = matches.group('quorum')
|
|
|
|
quorum = matches.group('quorum')
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
quorum = None
|
|
|
|
quorum = None
|
|
|
|
else:
|
|
|
|
result = self._verify_quorum_type(quorum)
|
|
|
|
quorum = self._values['quorum']
|
|
|
|
return result
|
|
|
|
try:
|
|
|
|
|
|
|
|
if quorum is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
return int(quorum)
|
|
|
|
|
|
|
|
except ValueError:
|
|
|
|
|
|
|
|
raise F5ModuleError(
|
|
|
|
|
|
|
|
"The specified 'quorum' must be an integer."
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def monitor_type(self):
|
|
|
|
def monitor_type(self):
|
|
|
|
if self.kind == 'tm:ltm:pool:poolstate':
|
|
|
|
|
|
|
|
if self._values['monitors'] is None:
|
|
|
|
if self._values['monitors'] is None:
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
pattern = r'min\s+\d+\s+of'
|
|
|
|
pattern = r'min\s+\d+\s+of'
|
|
|
@ -461,72 +446,110 @@ class Parameters(AnsibleF5Parameters):
|
|
|
|
return 'm_of_n'
|
|
|
|
return 'm_of_n'
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return 'and_list'
|
|
|
|
return 'and_list'
|
|
|
|
else:
|
|
|
|
|
|
|
|
if self._values['monitor_type'] is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
return self._values['monitor_type']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def host(self):
|
|
|
|
def monitors_list(self):
|
|
|
|
value = self._values['host']
|
|
|
|
if self._values['monitors'] is None:
|
|
|
|
if value is None:
|
|
|
|
return []
|
|
|
|
return None
|
|
|
|
|
|
|
|
msg = "'%s' is not a valid IP address" % value
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
IPAddress(value)
|
|
|
|
result = re.findall(r'/\w+/[^\s}]+', self._values['monitors'])
|
|
|
|
except AddrFormatError:
|
|
|
|
return result
|
|
|
|
raise F5ModuleError(msg)
|
|
|
|
except Exception:
|
|
|
|
return value
|
|
|
|
return self._values['monitors']
|
|
|
|
|
|
|
|
|
|
|
|
@host.setter
|
|
|
|
@property
|
|
|
|
def host(self, value):
|
|
|
|
def metadata(self):
|
|
|
|
self._values['host'] = value
|
|
|
|
if self._values['metadata'] is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
result = []
|
|
|
|
|
|
|
|
for md in self._values['metadata']:
|
|
|
|
|
|
|
|
tmp = dict(name=str(md['name']))
|
|
|
|
|
|
|
|
if 'value' in md:
|
|
|
|
|
|
|
|
tmp['value'] = str(md['value'])
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
tmp['value'] = ''
|
|
|
|
|
|
|
|
result.append(tmp)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ModuleParameters(Parameters):
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def port(self):
|
|
|
|
def monitors_list(self):
|
|
|
|
value = self._values['port']
|
|
|
|
if self._values['monitors'] is None:
|
|
|
|
if value is None:
|
|
|
|
return []
|
|
|
|
|
|
|
|
return self._values['monitors']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
|
|
|
def quorum(self):
|
|
|
|
|
|
|
|
if self._values['quorum'] is None:
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
msg = "The provided port '%s' must be between 0 and 65535" % value
|
|
|
|
result = self._verify_quorum_type(self._values['quorum'])
|
|
|
|
if value < 0 or value > 65535:
|
|
|
|
return result
|
|
|
|
raise F5ModuleError(msg)
|
|
|
|
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@port.setter
|
|
|
|
@property
|
|
|
|
def port(self, value):
|
|
|
|
def monitor_type(self):
|
|
|
|
self._values['port'] = value
|
|
|
|
if self._values['monitor_type'] is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
return self._values['monitor_type']
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def member_name(self):
|
|
|
|
def metadata(self):
|
|
|
|
if self.host is None or self.port is None:
|
|
|
|
if self._values['metadata'] is None:
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
mname = str(self.host) + ':' + str(self.port)
|
|
|
|
if self._values['metadata'] == '':
|
|
|
|
return mname
|
|
|
|
return []
|
|
|
|
|
|
|
|
result = []
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
for k, v in iteritems(self._values['metadata']):
|
|
|
|
|
|
|
|
tmp = dict(name=str(k))
|
|
|
|
|
|
|
|
if v:
|
|
|
|
|
|
|
|
tmp['value'] = str(v)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
tmp['value'] = ''
|
|
|
|
|
|
|
|
result.append(tmp)
|
|
|
|
|
|
|
|
except AttributeError:
|
|
|
|
|
|
|
|
raise F5ModuleError(
|
|
|
|
|
|
|
|
"The 'metadata' parameter must be a dictionary of key/value pairs."
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Changes(Parameters):
|
|
|
|
def to_return(self):
|
|
|
|
def to_return(self):
|
|
|
|
result = {}
|
|
|
|
result = {}
|
|
|
|
for returnable in self.returnables:
|
|
|
|
for returnable in self.returnables:
|
|
|
|
|
|
|
|
try:
|
|
|
|
result[returnable] = getattr(self, returnable)
|
|
|
|
result[returnable] = getattr(self, returnable)
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
|
|
pass
|
|
|
|
result = self._filter_params(result)
|
|
|
|
result = self._filter_params(result)
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def api_params(self):
|
|
|
|
@property
|
|
|
|
result = {}
|
|
|
|
def monitors(self):
|
|
|
|
for api_attribute in self.api_attributes:
|
|
|
|
if self._values['monitors'] is None:
|
|
|
|
if self.api_map is not None and api_attribute in self.api_map:
|
|
|
|
return None
|
|
|
|
result[api_attribute] = getattr(
|
|
|
|
return self._values['monitors']
|
|
|
|
self, self.api_map[api_attribute]
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
result[api_attribute] = getattr(self, api_attribute)
|
|
|
|
|
|
|
|
result = self._filter_params(result)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Changes(Parameters):
|
|
|
|
class UsableChanges(Changes):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ReportableChanges(Changes):
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
|
|
|
def monitors(self):
|
|
|
|
|
|
|
|
result = sorted(re.findall(r'/\w+/[^\s}]+', self._values['monitors']))
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
|
|
|
def metadata(self):
|
|
|
|
|
|
|
|
result = dict()
|
|
|
|
|
|
|
|
for x in self._values['metadata']:
|
|
|
|
|
|
|
|
result[x['name']] = x['value']
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Difference(object):
|
|
|
|
class Difference(object):
|
|
|
|
def __init__(self, want, have=None):
|
|
|
|
def __init__(self, want, have=None):
|
|
|
|
self.want = want
|
|
|
|
self.want = want
|
|
|
@ -548,6 +571,25 @@ class Difference(object):
|
|
|
|
except AttributeError:
|
|
|
|
except AttributeError:
|
|
|
|
return attr1
|
|
|
|
return attr1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def to_tuple(self, items):
|
|
|
|
|
|
|
|
result = []
|
|
|
|
|
|
|
|
for x in items:
|
|
|
|
|
|
|
|
tmp = [(str(k), str(v)) for k, v in iteritems(x)]
|
|
|
|
|
|
|
|
result += tmp
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _diff_complex_items(self, want, have):
|
|
|
|
|
|
|
|
if want == [] and have is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
if want is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
w = self.to_tuple(want)
|
|
|
|
|
|
|
|
h = self.to_tuple(have)
|
|
|
|
|
|
|
|
if set(w).issubset(set(h)):
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return want
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def monitor_type(self):
|
|
|
|
def monitor_type(self):
|
|
|
|
if self.want.monitor_type is None:
|
|
|
|
if self.want.monitor_type is None:
|
|
|
@ -593,13 +635,26 @@ class Difference(object):
|
|
|
|
if self.want.monitors != self.have.monitors:
|
|
|
|
if self.want.monitors != self.have.monitors:
|
|
|
|
return self.want.monitors
|
|
|
|
return self.want.monitors
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
|
|
|
def metadata(self):
|
|
|
|
|
|
|
|
if self.want.metadata is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
elif len(self.want.metadata) == 0 and self.have.metadata is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
elif len(self.want.metadata) == 0:
|
|
|
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
elif self.have.metadata is None:
|
|
|
|
|
|
|
|
return self.want.metadata
|
|
|
|
|
|
|
|
result = self._diff_complex_items(self.want.metadata, self.have.metadata)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ModuleManager(object):
|
|
|
|
class ModuleManager(object):
|
|
|
|
def __init__(self, client):
|
|
|
|
def __init__(self, client):
|
|
|
|
self.client = client
|
|
|
|
self.client = client
|
|
|
|
self.have = None
|
|
|
|
self.want = ModuleParameters(params=self.client.module.params)
|
|
|
|
self.want = Parameters(self.client.module.params)
|
|
|
|
self.have = ApiParameters()
|
|
|
|
self.changes = Changes()
|
|
|
|
self.changes = UsableChanges()
|
|
|
|
|
|
|
|
|
|
|
|
def exec_module(self):
|
|
|
|
def exec_module(self):
|
|
|
|
changed = False
|
|
|
|
changed = False
|
|
|
@ -614,18 +669,15 @@ class ModuleManager(object):
|
|
|
|
except iControlUnexpectedHTTPError as e:
|
|
|
|
except iControlUnexpectedHTTPError as e:
|
|
|
|
raise F5ModuleError(str(e))
|
|
|
|
raise F5ModuleError(str(e))
|
|
|
|
|
|
|
|
|
|
|
|
changes = self.changes.to_return()
|
|
|
|
reportable = ReportableChanges(self.changes.to_return())
|
|
|
|
|
|
|
|
changes = reportable.to_return()
|
|
|
|
result.update(**changes)
|
|
|
|
result.update(**changes)
|
|
|
|
result.update(dict(changed=changed))
|
|
|
|
result.update(dict(changed=changed))
|
|
|
|
self._announce_deprecations()
|
|
|
|
self._announce_deprecations(result)
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def _announce_deprecations(self):
|
|
|
|
def _announce_deprecations(self, result):
|
|
|
|
warnings = []
|
|
|
|
warnings = result.pop('__warnings', [])
|
|
|
|
if self.want:
|
|
|
|
|
|
|
|
warnings += self.want._values.get('__warnings', [])
|
|
|
|
|
|
|
|
if self.have:
|
|
|
|
|
|
|
|
warnings += self.have._values.get('__warnings', [])
|
|
|
|
|
|
|
|
for warning in warnings:
|
|
|
|
for warning in warnings:
|
|
|
|
self.client.module.deprecate(
|
|
|
|
self.client.module.deprecate(
|
|
|
|
msg=warning['msg'],
|
|
|
|
msg=warning['msg'],
|
|
|
@ -638,7 +690,7 @@ class ModuleManager(object):
|
|
|
|
if getattr(self.want, key) is not None:
|
|
|
|
if getattr(self.want, key) is not None:
|
|
|
|
changed[key] = getattr(self.want, key)
|
|
|
|
changed[key] = getattr(self.want, key)
|
|
|
|
if changed:
|
|
|
|
if changed:
|
|
|
|
self.changes = Parameters(changed)
|
|
|
|
self.changes = UsableChanges(changed)
|
|
|
|
|
|
|
|
|
|
|
|
def _update_changed_options(self):
|
|
|
|
def _update_changed_options(self):
|
|
|
|
diff = Difference(self.want, self.have)
|
|
|
|
diff = Difference(self.want, self.have)
|
|
|
@ -648,26 +700,16 @@ class ModuleManager(object):
|
|
|
|
change = diff.compare(k)
|
|
|
|
change = diff.compare(k)
|
|
|
|
if change is None:
|
|
|
|
if change is None:
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
if isinstance(change, dict):
|
|
|
|
|
|
|
|
changed.update(change)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
changed[k] = change
|
|
|
|
changed[k] = change
|
|
|
|
if changed:
|
|
|
|
if changed:
|
|
|
|
self.changes = Parameters(changed)
|
|
|
|
self.changes = UsableChanges(changed)
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def _member_does_not_exist(self, members):
|
|
|
|
|
|
|
|
name = self.want.member_name
|
|
|
|
|
|
|
|
# Return False if name is None, so that we don't attempt to create it
|
|
|
|
|
|
|
|
if name is None:
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
for member in members:
|
|
|
|
|
|
|
|
if member.name == name:
|
|
|
|
|
|
|
|
host, port = name.split(':')
|
|
|
|
|
|
|
|
self.have.host = host
|
|
|
|
|
|
|
|
self.have.port = int(port)
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def present(self):
|
|
|
|
def present(self):
|
|
|
|
if self.exists():
|
|
|
|
if self.exists():
|
|
|
|
return self.update()
|
|
|
|
return self.update()
|
|
|
@ -686,10 +728,7 @@ class ModuleManager(object):
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
def update(self):
|
|
|
|
self.have, members, poolres = self.read_current_from_device()
|
|
|
|
self.have = self.read_current_from_device()
|
|
|
|
if not self.client.check_mode:
|
|
|
|
|
|
|
|
if self._member_does_not_exist(members):
|
|
|
|
|
|
|
|
self.create_member_on_device(poolres)
|
|
|
|
|
|
|
|
if not self.should_update():
|
|
|
|
if not self.should_update():
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
if self.client.check_mode:
|
|
|
|
if self.client.check_mode:
|
|
|
@ -728,10 +767,6 @@ class ModuleManager(object):
|
|
|
|
if self.client.check_mode:
|
|
|
|
if self.client.check_mode:
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
self.create_on_device()
|
|
|
|
self.create_on_device()
|
|
|
|
if self.want.member_name:
|
|
|
|
|
|
|
|
self.have, members, poolres = self.read_current_from_device()
|
|
|
|
|
|
|
|
if self._member_does_not_exist(members):
|
|
|
|
|
|
|
|
self.create_member_on_device(poolres)
|
|
|
|
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def create_on_device(self):
|
|
|
|
def create_on_device(self):
|
|
|
@ -740,12 +775,6 @@ class ModuleManager(object):
|
|
|
|
partition=self.want.partition, **params
|
|
|
|
partition=self.want.partition, **params
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def create_member_on_device(self, poolres):
|
|
|
|
|
|
|
|
poolres.members_s.members.create(
|
|
|
|
|
|
|
|
name=self.want.member_name,
|
|
|
|
|
|
|
|
partition=self.want.partition
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_on_device(self):
|
|
|
|
def update_on_device(self):
|
|
|
|
params = self.want.api_params()
|
|
|
|
params = self.want.api_params()
|
|
|
|
result = self.client.api.tm.ltm.pools.pool.load(
|
|
|
|
result = self.client.api.tm.ltm.pools.pool.load(
|
|
|
@ -765,69 +794,21 @@ class ModuleManager(object):
|
|
|
|
name=self.want.name,
|
|
|
|
name=self.want.name,
|
|
|
|
partition=self.want.partition
|
|
|
|
partition=self.want.partition
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if self.want.member_name and self.want.port and self.want.pool:
|
|
|
|
|
|
|
|
member = result.members_s.members.load(
|
|
|
|
|
|
|
|
name=self.want.member_name,
|
|
|
|
|
|
|
|
partition=self.want.partition
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
if member:
|
|
|
|
|
|
|
|
member.delete()
|
|
|
|
|
|
|
|
self.delete_node_on_device()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
result.delete()
|
|
|
|
result.delete()
|
|
|
|
|
|
|
|
|
|
|
|
def read_current_from_device(self):
|
|
|
|
def read_current_from_device(self):
|
|
|
|
tmp_res = self.client.api.tm.ltm.pools.pool.load(
|
|
|
|
resource = self.client.api.tm.ltm.pools.pool.load(
|
|
|
|
name=self.want.name,
|
|
|
|
name=self.want.name,
|
|
|
|
partition=self.want.partition
|
|
|
|
partition=self.want.partition,
|
|
|
|
|
|
|
|
requests_params=dict(
|
|
|
|
|
|
|
|
params='expandSubcollections=true'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
members = tmp_res.members_s.get_collection()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result = tmp_res.attrs
|
|
|
|
|
|
|
|
return Parameters(result), members, tmp_res
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def delete_node_on_device(self):
|
|
|
|
|
|
|
|
resource = self.client.api.tm.ltm.nodes.node.load(
|
|
|
|
|
|
|
|
name=self.want.host,
|
|
|
|
|
|
|
|
partition=self.want.partition
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
return ApiParameters(resource.attrs)
|
|
|
|
resource.delete()
|
|
|
|
|
|
|
|
except iControlUnexpectedHTTPError as e:
|
|
|
|
|
|
|
|
# If we cannot remove it, it is in use, it is up to user to delete
|
|
|
|
|
|
|
|
# it later.
|
|
|
|
|
|
|
|
if "is referenced by a member of pool" in str(e):
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ArgumentSpec(object):
|
|
|
|
class ArgumentSpec(object):
|
|
|
|
def __init__(self):
|
|
|
|
def __init__(self):
|
|
|
|
self.lb_choice_deprecated = [
|
|
|
|
|
|
|
|
'round_robin',
|
|
|
|
|
|
|
|
'ratio_member',
|
|
|
|
|
|
|
|
'least_connection_member',
|
|
|
|
|
|
|
|
'observed_member',
|
|
|
|
|
|
|
|
'predictive_member',
|
|
|
|
|
|
|
|
'ratio_node_address',
|
|
|
|
|
|
|
|
'least_connection_node_address',
|
|
|
|
|
|
|
|
'fastest_node_address',
|
|
|
|
|
|
|
|
'observed_node_address',
|
|
|
|
|
|
|
|
'predictive_node_address',
|
|
|
|
|
|
|
|
'dynamic_ratio',
|
|
|
|
|
|
|
|
'fastest_app_response',
|
|
|
|
|
|
|
|
'least_sessions',
|
|
|
|
|
|
|
|
'dynamic_ratio_member',
|
|
|
|
|
|
|
|
'ratio_session',
|
|
|
|
|
|
|
|
'weighted_least_connection_member',
|
|
|
|
|
|
|
|
'ratio_least_connection_member',
|
|
|
|
|
|
|
|
'weighted_least_connection_node_address',
|
|
|
|
|
|
|
|
'ratio_least_connection_node_address'
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
self.lb_choice_removed = [
|
|
|
|
|
|
|
|
'l3_addr'
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
self.lb_choice = [
|
|
|
|
self.lb_choice = [
|
|
|
|
'dynamic-ratio-member',
|
|
|
|
'dynamic-ratio-member',
|
|
|
|
'dynamic-ratio-node',
|
|
|
|
'dynamic-ratio-node',
|
|
|
@ -849,7 +830,6 @@ class ArgumentSpec(object):
|
|
|
|
'weighted-least-connections-member',
|
|
|
|
'weighted-least-connections-member',
|
|
|
|
'weighted-least-connections-node'
|
|
|
|
'weighted-least-connections-node'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
lb_choices = self.lb_choice_removed + self.lb_choice + self.lb_choice_deprecated
|
|
|
|
|
|
|
|
self.supports_check_mode = True
|
|
|
|
self.supports_check_mode = True
|
|
|
|
self.argument_spec = dict(
|
|
|
|
self.argument_spec = dict(
|
|
|
|
name=dict(
|
|
|
|
name=dict(
|
|
|
@ -857,7 +837,7 @@ class ArgumentSpec(object):
|
|
|
|
aliases=['pool']
|
|
|
|
aliases=['pool']
|
|
|
|
),
|
|
|
|
),
|
|
|
|
lb_method=dict(
|
|
|
|
lb_method=dict(
|
|
|
|
choices=lb_choices
|
|
|
|
choices=self.lb_choice
|
|
|
|
),
|
|
|
|
),
|
|
|
|
monitor_type=dict(
|
|
|
|
monitor_type=dict(
|
|
|
|
choices=[
|
|
|
|
choices=[
|
|
|
@ -883,14 +863,7 @@ class ArgumentSpec(object):
|
|
|
|
]
|
|
|
|
]
|
|
|
|
),
|
|
|
|
),
|
|
|
|
description=dict(),
|
|
|
|
description=dict(),
|
|
|
|
host=dict(
|
|
|
|
metadata=dict(type='raw')
|
|
|
|
aliases=['address'],
|
|
|
|
|
|
|
|
removed_in_version='2.4'
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
port=dict(
|
|
|
|
|
|
|
|
type='int',
|
|
|
|
|
|
|
|
removed_in_version='2.4'
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.f5_product_name = 'bigip'
|
|
|
|
self.f5_product_name = 'bigip'
|
|
|
|
|
|
|
|
|
|
|
|