|
|
@ -1,7 +1,7 @@
|
|
|
|
#!/usr/bin/python
|
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Copyright (c) 2017 F5 Networks Inc.
|
|
|
|
# Copyright: (c) 2017, F5 Networks Inc.
|
|
|
|
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# GNU General Public License v3.0 (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
@ -177,9 +177,38 @@ options:
|
|
|
|
- This parameter is only relevant when a C(type) of C(require) is used.
|
|
|
|
- This parameter is only relevant when a C(type) of C(require) is used.
|
|
|
|
- This parameter will be ignored if a type of either C(all) or C(at_least) is used.
|
|
|
|
- This parameter will be ignored if a type of either C(all) or C(at_least) is used.
|
|
|
|
version_added: 2.6
|
|
|
|
version_added: 2.6
|
|
|
|
|
|
|
|
max_answers_returned:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- Specifies the maximum number of available virtual servers that the system lists in a response.
|
|
|
|
|
|
|
|
- The maximum is 500.
|
|
|
|
|
|
|
|
version_added: 2.8
|
|
|
|
|
|
|
|
ttl:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- Specifies the number of seconds that the IP address, once found, is valid.
|
|
|
|
|
|
|
|
version_added: 2.8
|
|
|
|
extends_documentation_fragment: f5
|
|
|
|
extends_documentation_fragment: f5
|
|
|
|
author:
|
|
|
|
author:
|
|
|
|
- Tim Rupp (@caphrim007)
|
|
|
|
- Tim Rupp (@caphrim007)
|
|
|
|
|
|
|
|
- Wojciech Wypior (@wojtek0806)
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EXAMPLES = r'''
|
|
|
|
|
|
|
|
- name: Create a GTM pool
|
|
|
|
|
|
|
|
bigip_gtm_pool:
|
|
|
|
|
|
|
|
server: lb.mydomain.com
|
|
|
|
|
|
|
|
user: admin
|
|
|
|
|
|
|
|
password: secret
|
|
|
|
|
|
|
|
name: my_pool
|
|
|
|
|
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Disable pool
|
|
|
|
|
|
|
|
bigip_gtm_pool:
|
|
|
|
|
|
|
|
server: lb.mydomain.com
|
|
|
|
|
|
|
|
user: admin
|
|
|
|
|
|
|
|
password: secret
|
|
|
|
|
|
|
|
state: disabled
|
|
|
|
|
|
|
|
name: my_pool
|
|
|
|
|
|
|
|
delegate_to: localhost
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
RETURN = r'''
|
|
|
|
RETURN = r'''
|
|
|
@ -221,25 +250,11 @@ members:
|
|
|
|
description: The name of the virtual server portion of the member.
|
|
|
|
description: The name of the virtual server portion of the member.
|
|
|
|
returned: changed
|
|
|
|
returned: changed
|
|
|
|
type: string
|
|
|
|
type: string
|
|
|
|
'''
|
|
|
|
max_answers_returned:
|
|
|
|
|
|
|
|
description: The new Maximum Answers Returned value.
|
|
|
|
EXAMPLES = r'''
|
|
|
|
returned: changed
|
|
|
|
- name: Create a GTM pool
|
|
|
|
type: int
|
|
|
|
bigip_gtm_pool:
|
|
|
|
sample: 25
|
|
|
|
server: lb.mydomain.com
|
|
|
|
|
|
|
|
user: admin
|
|
|
|
|
|
|
|
password: secret
|
|
|
|
|
|
|
|
name: my_pool
|
|
|
|
|
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Disable pool
|
|
|
|
|
|
|
|
bigip_gtm_pool:
|
|
|
|
|
|
|
|
server: lb.mydomain.com
|
|
|
|
|
|
|
|
user: admin
|
|
|
|
|
|
|
|
password: secret
|
|
|
|
|
|
|
|
state: disabled
|
|
|
|
|
|
|
|
name: my_pool
|
|
|
|
|
|
|
|
delegate_to: localhost
|
|
|
|
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
|
import copy
|
|
|
|
import copy
|
|
|
@ -250,33 +265,31 @@ from ansible.module_utils.basic import env_fallback
|
|
|
|
from distutils.version import LooseVersion
|
|
|
|
from distutils.version import LooseVersion
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
from library.module_utils.network.f5.bigip import HAS_F5SDK
|
|
|
|
from library.module_utils.network.f5.bigip import F5RestClient
|
|
|
|
from library.module_utils.network.f5.bigip import F5Client
|
|
|
|
|
|
|
|
from library.module_utils.network.f5.common import F5ModuleError
|
|
|
|
from library.module_utils.network.f5.common import F5ModuleError
|
|
|
|
from library.module_utils.network.f5.common import AnsibleF5Parameters
|
|
|
|
from library.module_utils.network.f5.common import AnsibleF5Parameters
|
|
|
|
from library.module_utils.network.f5.common import cleanup_tokens
|
|
|
|
from library.module_utils.network.f5.common import cleanup_tokens
|
|
|
|
from library.module_utils.network.f5.common import fq_name
|
|
|
|
from library.module_utils.network.f5.common import fq_name
|
|
|
|
from library.module_utils.network.f5.common import f5_argument_spec
|
|
|
|
from library.module_utils.network.f5.common import f5_argument_spec
|
|
|
|
|
|
|
|
from library.module_utils.network.f5.common import transform_name
|
|
|
|
|
|
|
|
from library.module_utils.network.f5.common import exit_json
|
|
|
|
|
|
|
|
from library.module_utils.network.f5.common import fail_json
|
|
|
|
|
|
|
|
from library.module_utils.network.f5.icontrol import tmos_version
|
|
|
|
|
|
|
|
from library.module_utils.network.f5.icontrol import module_provisioned
|
|
|
|
from library.module_utils.network.f5.ipaddress import is_valid_ip
|
|
|
|
from library.module_utils.network.f5.ipaddress import is_valid_ip
|
|
|
|
try:
|
|
|
|
|
|
|
|
from library.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
|
|
|
|
|
|
|
from f5.sdk_exception import LazyAttributesRequired
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
|
|
HAS_F5SDK = False
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
except ImportError:
|
|
|
|
from ansible.module_utils.network.f5.bigip import HAS_F5SDK
|
|
|
|
from ansible.module_utils.network.f5.bigip import F5RestClient
|
|
|
|
from ansible.module_utils.network.f5.bigip import F5Client
|
|
|
|
|
|
|
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
|
|
|
from ansible.module_utils.network.f5.common import F5ModuleError
|
|
|
|
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
|
|
|
|
from ansible.module_utils.network.f5.common import AnsibleF5Parameters
|
|
|
|
from ansible.module_utils.network.f5.common import cleanup_tokens
|
|
|
|
from ansible.module_utils.network.f5.common import cleanup_tokens
|
|
|
|
from ansible.module_utils.network.f5.common import fq_name
|
|
|
|
from ansible.module_utils.network.f5.common import fq_name
|
|
|
|
from ansible.module_utils.network.f5.common import f5_argument_spec
|
|
|
|
from ansible.module_utils.network.f5.common import f5_argument_spec
|
|
|
|
|
|
|
|
from ansible.module_utils.network.f5.common import transform_name
|
|
|
|
|
|
|
|
from ansible.module_utils.network.f5.common import exit_json
|
|
|
|
|
|
|
|
from ansible.module_utils.network.f5.common import fail_json
|
|
|
|
|
|
|
|
from ansible.module_utils.network.f5.icontrol import tmos_version
|
|
|
|
|
|
|
|
from ansible.module_utils.network.f5.icontrol import module_provisioned
|
|
|
|
from ansible.module_utils.network.f5.ipaddress import is_valid_ip
|
|
|
|
from ansible.module_utils.network.f5.ipaddress import is_valid_ip
|
|
|
|
try:
|
|
|
|
|
|
|
|
from ansible.module_utils.network.f5.common import iControlUnexpectedHTTPError
|
|
|
|
|
|
|
|
from f5.sdk_exception import LazyAttributesRequired
|
|
|
|
|
|
|
|
except ImportError:
|
|
|
|
|
|
|
|
HAS_F5SDK = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Parameters(AnsibleF5Parameters):
|
|
|
|
class Parameters(AnsibleF5Parameters):
|
|
|
@ -289,7 +302,8 @@ class Parameters(AnsibleF5Parameters):
|
|
|
|
'fallbackIpv6': 'fallback_ip',
|
|
|
|
'fallbackIpv6': 'fallback_ip',
|
|
|
|
'fallbackIp': 'fallback_ip',
|
|
|
|
'fallbackIp': 'fallback_ip',
|
|
|
|
'membersReference': 'members',
|
|
|
|
'membersReference': 'members',
|
|
|
|
'monitor': 'monitors'
|
|
|
|
'monitor': 'monitors',
|
|
|
|
|
|
|
|
'maxAnswersReturned': 'max_answers_returned',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
updatables = [
|
|
|
|
updatables = [
|
|
|
@ -300,6 +314,8 @@ class Parameters(AnsibleF5Parameters):
|
|
|
|
'monitors',
|
|
|
|
'monitors',
|
|
|
|
'preferred_lb_method',
|
|
|
|
'preferred_lb_method',
|
|
|
|
'state',
|
|
|
|
'state',
|
|
|
|
|
|
|
|
'max_answers_returned',
|
|
|
|
|
|
|
|
'ttl',
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
returnables = [
|
|
|
|
returnables = [
|
|
|
@ -310,7 +326,10 @@ class Parameters(AnsibleF5Parameters):
|
|
|
|
'monitors',
|
|
|
|
'monitors',
|
|
|
|
'preferred_lb_method',
|
|
|
|
'preferred_lb_method',
|
|
|
|
'enabled',
|
|
|
|
'enabled',
|
|
|
|
'disabled'
|
|
|
|
'disabled',
|
|
|
|
|
|
|
|
'availability_requirements',
|
|
|
|
|
|
|
|
'max_answers_returned',
|
|
|
|
|
|
|
|
'ttl',
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
api_attributes = [
|
|
|
|
api_attributes = [
|
|
|
@ -324,34 +343,11 @@ class Parameters(AnsibleF5Parameters):
|
|
|
|
'loadBalancingMode',
|
|
|
|
'loadBalancingMode',
|
|
|
|
'members',
|
|
|
|
'members',
|
|
|
|
'verifyMemberAvailability',
|
|
|
|
'verifyMemberAvailability',
|
|
|
|
# The monitor attribute is not included here, because it can break the
|
|
|
|
'monitor',
|
|
|
|
# API calls to the device. If this bug is ever fixed, uncomment this code.
|
|
|
|
'maxAnswersReturned',
|
|
|
|
#
|
|
|
|
'ttl',
|
|
|
|
# monitor
|
|
|
|
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def to_return(self):
|
|
|
|
|
|
|
|
result = {}
|
|
|
|
|
|
|
|
for returnable in self.returnables:
|
|
|
|
|
|
|
|
result[returnable] = getattr(self, returnable)
|
|
|
|
|
|
|
|
result = self._filter_params(result)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
|
|
|
def collection(self):
|
|
|
|
|
|
|
|
type_map = dict(
|
|
|
|
|
|
|
|
a='a_s',
|
|
|
|
|
|
|
|
aaaa='aaaas',
|
|
|
|
|
|
|
|
cname='cnames',
|
|
|
|
|
|
|
|
mx='mxs',
|
|
|
|
|
|
|
|
naptr='naptrs',
|
|
|
|
|
|
|
|
srv='srvs'
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
if self._values['type'] is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
wideip_type = self._values['type']
|
|
|
|
|
|
|
|
return type_map[wideip_type]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def type(self):
|
|
|
|
def type(self):
|
|
|
|
if self._values['type'] is None:
|
|
|
|
if self._values['type'] is None:
|
|
|
@ -449,7 +445,6 @@ class ApiParameters(Parameters):
|
|
|
|
result = 'require {0} from {1} {{ {2} }}'.format(self.number_of_probes, self.number_of_probers, monitors)
|
|
|
|
result = 'require {0} from {1} {{ {2} }}'.format(self.number_of_probes, self.number_of_probers, monitors)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
result = ' and '.join(monitors).strip()
|
|
|
|
result = ' and '.join(monitors).strip()
|
|
|
|
|
|
|
|
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
@ -608,15 +603,25 @@ class ModuleParameters(Parameters):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Changes(Parameters):
|
|
|
|
class Changes(Parameters):
|
|
|
|
pass
|
|
|
|
def to_return(self):
|
|
|
|
|
|
|
|
result = {}
|
|
|
|
|
|
|
|
for returnable in self.returnables:
|
|
|
|
|
|
|
|
result[returnable] = getattr(self, returnable)
|
|
|
|
|
|
|
|
result = self._filter_params(result)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UsableChanges(Changes):
|
|
|
|
class UsableChanges(Changes):
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def monitors(self):
|
|
|
|
def monitors(self):
|
|
|
|
if self._values['monitors'] is None:
|
|
|
|
monitor_string = self._values['monitors']
|
|
|
|
|
|
|
|
if monitor_string is None:
|
|
|
|
return None
|
|
|
|
return None
|
|
|
|
return self._values['monitors']
|
|
|
|
if '{' in monitor_string and '}':
|
|
|
|
|
|
|
|
tmp = monitor_string.strip('}').split('{')
|
|
|
|
|
|
|
|
monitor = ''.join(tmp).rstrip()
|
|
|
|
|
|
|
|
return monitor
|
|
|
|
|
|
|
|
return monitor_string
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def members(self):
|
|
|
|
def members(self):
|
|
|
@ -646,6 +651,93 @@ class ReportableChanges(Changes):
|
|
|
|
))
|
|
|
|
))
|
|
|
|
return results
|
|
|
|
return results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
|
|
|
def monitors(self):
|
|
|
|
|
|
|
|
if self._values['monitors'] is None:
|
|
|
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
result = re.findall(r'/\w+/[^\s}]+', self._values['monitors'])
|
|
|
|
|
|
|
|
result.sort()
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
except Exception:
|
|
|
|
|
|
|
|
return self._values['monitors']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
|
|
|
def availability_requirement_type(self):
|
|
|
|
|
|
|
|
if self._values['monitors'] is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
if 'min ' in self._values['monitors']:
|
|
|
|
|
|
|
|
return 'at_least'
|
|
|
|
|
|
|
|
elif 'require ' in self._values['monitors']:
|
|
|
|
|
|
|
|
return 'require'
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return 'all'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
|
|
|
def number_of_probes(self):
|
|
|
|
|
|
|
|
"""Returns the probes value from the monitor string.
|
|
|
|
|
|
|
|
The monitor string for a Require monitor looks like this.
|
|
|
|
|
|
|
|
require 1 from 2 { /Common/tcp }
|
|
|
|
|
|
|
|
This method parses out the first of the numeric values. This values represents
|
|
|
|
|
|
|
|
the "probes" value that can be updated in the module.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
int: The probes value if found. None otherwise.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
if self._values['monitors'] is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
pattern = r'require\s+(?P<probes>\d+)\s+from'
|
|
|
|
|
|
|
|
matches = re.search(pattern, self._values['monitors'])
|
|
|
|
|
|
|
|
if matches is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
return int(matches.group('probes'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
|
|
|
def number_of_probers(self):
|
|
|
|
|
|
|
|
"""Returns the probers value from the monitor string.
|
|
|
|
|
|
|
|
The monitor string for a Require monitor looks like this.
|
|
|
|
|
|
|
|
require 1 from 2 { /Common/tcp }
|
|
|
|
|
|
|
|
This method parses out the first of the numeric values. This values represents
|
|
|
|
|
|
|
|
the "probers" value that can be updated in the module.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
int: The probers value if found. None otherwise.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
if self._values['monitors'] is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
pattern = r'require\s+\d+\s+from\s+(?P<probers>\d+)\s+'
|
|
|
|
|
|
|
|
matches = re.search(pattern, self._values['monitors'])
|
|
|
|
|
|
|
|
if matches is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
return int(matches.group('probers'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
|
|
|
def at_least(self):
|
|
|
|
|
|
|
|
"""Returns the 'at least' value from the monitor string.
|
|
|
|
|
|
|
|
The monitor string for a Require monitor looks like this.
|
|
|
|
|
|
|
|
min 1 of { /Common/gateway_icmp }
|
|
|
|
|
|
|
|
This method parses out the first of the numeric values. This values represents
|
|
|
|
|
|
|
|
the "at_least" value that can be updated in the module.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
int: The at_least value if found. None otherwise.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
if self._values['monitors'] is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
pattern = r'min\s+(?P<least>\d+)\s+of\s+'
|
|
|
|
|
|
|
|
matches = re.search(pattern, self._values['monitors'])
|
|
|
|
|
|
|
|
if matches is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
return int(matches.group('least'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
|
|
|
def availability_requirements(self):
|
|
|
|
|
|
|
|
if self._values['monitors'] is None:
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
result = dict()
|
|
|
|
|
|
|
|
result['type'] = self.availability_requirement_type
|
|
|
|
|
|
|
|
result['at_least'] = self.at_least
|
|
|
|
|
|
|
|
result['number_of_probers'] = self.number_of_probers
|
|
|
|
|
|
|
|
result['number_of_probes'] = self.number_of_probes
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Difference(object):
|
|
|
|
class Difference(object):
|
|
|
|
def __init__(self, want, have=None):
|
|
|
|
def __init__(self, want, have=None):
|
|
|
@ -701,7 +793,7 @@ class ModuleManager(object):
|
|
|
|
self.client = kwargs.get('client', None)
|
|
|
|
self.client = kwargs.get('client', None)
|
|
|
|
|
|
|
|
|
|
|
|
def exec_module(self):
|
|
|
|
def exec_module(self):
|
|
|
|
if not self.gtm_provisioned():
|
|
|
|
if not module_provisioned(self.client, 'gtm'):
|
|
|
|
raise F5ModuleError(
|
|
|
|
raise F5ModuleError(
|
|
|
|
"GTM must be provisioned to use this module."
|
|
|
|
"GTM must be provisioned to use this module."
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -718,20 +810,12 @@ class ModuleManager(object):
|
|
|
|
return UntypedManager(**self.kwargs)
|
|
|
|
return UntypedManager(**self.kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
def version_is_less_than_12(self):
|
|
|
|
def version_is_less_than_12(self):
|
|
|
|
version = self.client.api.tmos_version
|
|
|
|
version = tmos_version(self.client)
|
|
|
|
if LooseVersion(version) < LooseVersion('12.0.0'):
|
|
|
|
if LooseVersion(version) < LooseVersion('12.0.0'):
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def gtm_provisioned(self):
|
|
|
|
|
|
|
|
resource = self.client.api.tm.sys.dbs.db.load(
|
|
|
|
|
|
|
|
name='provisioned.cpu.gtm'
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
if int(resource.value) == 0:
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BaseManager(object):
|
|
|
|
class BaseManager(object):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
@ -772,13 +856,10 @@ class BaseManager(object):
|
|
|
|
result = dict()
|
|
|
|
result = dict()
|
|
|
|
state = self.want.state
|
|
|
|
state = self.want.state
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
if state in ["present", "disabled"]:
|
|
|
|
if state in ["present", "disabled"]:
|
|
|
|
changed = self.present()
|
|
|
|
changed = self.present()
|
|
|
|
elif state == "absent":
|
|
|
|
elif state == "absent":
|
|
|
|
changed = self.absent()
|
|
|
|
changed = self.absent()
|
|
|
|
except iControlUnexpectedHTTPError as e:
|
|
|
|
|
|
|
|
raise F5ModuleError(str(e))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
reportable = ReportableChanges(params=self.changes.to_return())
|
|
|
|
reportable = ReportableChanges(params=self.changes.to_return())
|
|
|
|
changes = reportable.to_return()
|
|
|
|
changes = reportable.to_return()
|
|
|
@ -850,36 +931,6 @@ class BaseManager(object):
|
|
|
|
raise F5ModuleError("Failed to delete the GTM pool")
|
|
|
|
raise F5ModuleError("Failed to delete the GTM pool")
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def update_monitors_on_device(self):
|
|
|
|
|
|
|
|
"""Updates the monitors string on a virtual server
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
There is a long-standing bug in GTM virtual servers where the monitor value
|
|
|
|
|
|
|
|
is a string that includes braces. These braces cause the REST API to panic and
|
|
|
|
|
|
|
|
fail to update or create any resources that have an "at_least" or "require"
|
|
|
|
|
|
|
|
set of availability_requirements.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This method exists to do a tmsh command to cause the update to take place on
|
|
|
|
|
|
|
|
the device.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Preferably, this method can be removed and the bug be fixed. The API should
|
|
|
|
|
|
|
|
be working, obviously, but the more concerning issue is if tmsh commands change
|
|
|
|
|
|
|
|
over time, breaking this method.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
command = 'tmsh modify gtm pool {0} /{1}/{2} monitor {3}'.format(
|
|
|
|
|
|
|
|
self.want.type, self.want.partition, self.want.name, self.want.monitors
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
output = self.client.api.tm.util.bash.exec_cmd(
|
|
|
|
|
|
|
|
'run',
|
|
|
|
|
|
|
|
utilCmdArgs='-c "{0}"'.format(command)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
if hasattr(output, 'commandResult'):
|
|
|
|
|
|
|
|
if len(output.commandResult.strip()) > 0:
|
|
|
|
|
|
|
|
raise F5ModuleError(output.commandResult)
|
|
|
|
|
|
|
|
except (AttributeError, NameError, LazyAttributesRequired):
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TypedManager(BaseManager):
|
|
|
|
class TypedManager(BaseManager):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
@ -906,112 +957,184 @@ class TypedManager(BaseManager):
|
|
|
|
return super(TypedManager, self).present()
|
|
|
|
return super(TypedManager, self).present()
|
|
|
|
|
|
|
|
|
|
|
|
def exists(self):
|
|
|
|
def exists(self):
|
|
|
|
pools = self.client.api.tm.gtm.pools
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/gtm/pool/{2}/{3}".format(
|
|
|
|
collection = getattr(pools, self.want.collection)
|
|
|
|
self.client.provider['server'],
|
|
|
|
resource = getattr(collection, self.want.type)
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
result = resource.exists(
|
|
|
|
self.want.type,
|
|
|
|
name=self.want.name,
|
|
|
|
transform_name(self.want.partition, self.want.name)
|
|
|
|
partition=self.want.partition
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return result
|
|
|
|
resp = self.client.api.get(uri)
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
response = resp.json()
|
|
|
|
|
|
|
|
except ValueError:
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
if resp.status == 404 or 'code' in response and response['code'] == 404:
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def update_on_device(self):
|
|
|
|
def update_on_device(self):
|
|
|
|
params = self.changes.api_params()
|
|
|
|
params = self.changes.api_params()
|
|
|
|
pools = self.client.api.tm.gtm.pools
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/gtm/pool/{2}/{3}".format(
|
|
|
|
collection = getattr(pools, self.want.collection)
|
|
|
|
self.client.provider['server'],
|
|
|
|
resource = getattr(collection, self.want.type)
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
result = resource.load(
|
|
|
|
self.want.type,
|
|
|
|
name=self.want.name,
|
|
|
|
transform_name(self.want.partition, self.want.name)
|
|
|
|
partition=self.want.partition
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if params:
|
|
|
|
resp = self.client.api.patch(uri, json=params)
|
|
|
|
result.modify(**params)
|
|
|
|
try:
|
|
|
|
if self.want.monitors:
|
|
|
|
response = resp.json()
|
|
|
|
self.update_monitors_on_device()
|
|
|
|
except ValueError as ex:
|
|
|
|
|
|
|
|
raise F5ModuleError(str(ex))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if 'code' in response and response['code'] == 400:
|
|
|
|
|
|
|
|
if 'message' in response:
|
|
|
|
|
|
|
|
raise F5ModuleError(response['message'])
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
raise F5ModuleError(resp.content)
|
|
|
|
|
|
|
|
|
|
|
|
def read_current_from_device(self):
|
|
|
|
def read_current_from_device(self):
|
|
|
|
pools = self.client.api.tm.gtm.pools
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/gtm/pool/{2}/{3}".format(
|
|
|
|
collection = getattr(pools, self.want.collection)
|
|
|
|
self.client.provider['server'],
|
|
|
|
resource = getattr(collection, self.want.type)
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
result = resource.load(
|
|
|
|
self.want.type,
|
|
|
|
name=self.want.name,
|
|
|
|
transform_name(self.want.partition, self.want.name)
|
|
|
|
partition=self.want.partition,
|
|
|
|
|
|
|
|
requests_params=dict(
|
|
|
|
|
|
|
|
params=dict(
|
|
|
|
|
|
|
|
expandSubcollections='true'
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
query = '?expandSubcollections=true'
|
|
|
|
result = result.attrs
|
|
|
|
resp = self.client.api.get(uri + query)
|
|
|
|
return ApiParameters(params=result)
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
response = resp.json()
|
|
|
|
|
|
|
|
except ValueError as ex:
|
|
|
|
|
|
|
|
raise F5ModuleError(str(ex))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if 'code' in response and response['code'] == 400:
|
|
|
|
|
|
|
|
if 'message' in response:
|
|
|
|
|
|
|
|
raise F5ModuleError(response['message'])
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
raise F5ModuleError(resp.content)
|
|
|
|
|
|
|
|
return ApiParameters(params=response)
|
|
|
|
|
|
|
|
|
|
|
|
def create_on_device(self):
|
|
|
|
def create_on_device(self):
|
|
|
|
params = self.changes.api_params()
|
|
|
|
params = self.changes.api_params()
|
|
|
|
pools = self.client.api.tm.gtm.pools
|
|
|
|
params['name'] = self.want.name
|
|
|
|
collection = getattr(pools, self.want.collection)
|
|
|
|
params['partition'] = self.want.partition
|
|
|
|
resource = getattr(collection, self.want.type)
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/gtm/pool/{2}".format(
|
|
|
|
resource.create(
|
|
|
|
self.client.provider['server'],
|
|
|
|
name=self.want.name,
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
partition=self.want.partition,
|
|
|
|
self.want.type
|
|
|
|
**params
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if self.want.monitors:
|
|
|
|
resp = self.client.api.post(uri, json=params)
|
|
|
|
self.update_monitors_on_device()
|
|
|
|
try:
|
|
|
|
|
|
|
|
response = resp.json()
|
|
|
|
|
|
|
|
except ValueError as ex:
|
|
|
|
|
|
|
|
raise F5ModuleError(str(ex))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if 'code' in response and response['code'] in [400, 403]:
|
|
|
|
|
|
|
|
if 'message' in response:
|
|
|
|
|
|
|
|
raise F5ModuleError(response['message'])
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
raise F5ModuleError(resp.content)
|
|
|
|
|
|
|
|
return response['selfLink']
|
|
|
|
|
|
|
|
|
|
|
|
def remove_from_device(self):
|
|
|
|
def remove_from_device(self):
|
|
|
|
pools = self.client.api.tm.gtm.pools
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/gtm/pool/{2}/{3}".format(
|
|
|
|
collection = getattr(pools, self.want.collection)
|
|
|
|
self.client.provider['server'],
|
|
|
|
resource = getattr(collection, self.want.type)
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
resource = resource.load(
|
|
|
|
self.want.type,
|
|
|
|
name=self.want.name,
|
|
|
|
transform_name(self.want.partition, self.want.name)
|
|
|
|
partition=self.want.partition
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if resource:
|
|
|
|
response = self.client.api.delete(uri)
|
|
|
|
resource.delete()
|
|
|
|
if response.status == 200:
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
raise F5ModuleError(response.content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UntypedManager(BaseManager):
|
|
|
|
class UntypedManager(BaseManager):
|
|
|
|
def exists(self):
|
|
|
|
def exists(self):
|
|
|
|
result = self.client.api.tm.gtm.pools.pool.exists(
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/gtm/pool/{2}".format(
|
|
|
|
name=self.want.name,
|
|
|
|
self.client.provider['server'],
|
|
|
|
partition=self.want.partition
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
|
|
|
|
transform_name(self.want.partition, self.want.name)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return result
|
|
|
|
resp = self.client.api.get(uri)
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
response = resp.json()
|
|
|
|
|
|
|
|
except ValueError:
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
if resp.status == 404 or 'code' in response and response['code'] == 404:
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_on_device(self):
|
|
|
|
|
|
|
|
params = self.changes.api_params()
|
|
|
|
|
|
|
|
params['name'] = self.want.name
|
|
|
|
|
|
|
|
params['partition'] = self.want.partition
|
|
|
|
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/gtm/pool/".format(
|
|
|
|
|
|
|
|
self.client.provider['server'],
|
|
|
|
|
|
|
|
self.client.provider['server_port']
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
resp = self.client.api.post(uri, json=params)
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
response = resp.json()
|
|
|
|
|
|
|
|
except ValueError as ex:
|
|
|
|
|
|
|
|
raise F5ModuleError(str(ex))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if 'code' in response and response['code'] in [400, 403]:
|
|
|
|
|
|
|
|
if 'message' in response:
|
|
|
|
|
|
|
|
raise F5ModuleError(response['message'])
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
raise F5ModuleError(resp.content)
|
|
|
|
|
|
|
|
return response['selfLink']
|
|
|
|
|
|
|
|
|
|
|
|
def update_on_device(self):
|
|
|
|
def update_on_device(self):
|
|
|
|
params = self.changes.api_params()
|
|
|
|
params = self.changes.api_params()
|
|
|
|
resource = self.client.api.tm.gtm.pools.pool.load(
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/gtm/pool/{2}".format(
|
|
|
|
name=self.want.name,
|
|
|
|
self.client.provider['server'],
|
|
|
|
partition=self.want.partition
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
|
|
|
|
transform_name(self.want.partition, self.want.name)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
resource.modify(**params)
|
|
|
|
resp = self.client.api.patch(uri, json=params)
|
|
|
|
if self.want.monitors:
|
|
|
|
try:
|
|
|
|
self.update_monitors_on_device()
|
|
|
|
response = resp.json()
|
|
|
|
|
|
|
|
except ValueError as ex:
|
|
|
|
|
|
|
|
raise F5ModuleError(str(ex))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if 'code' in response and response['code'] == 400:
|
|
|
|
|
|
|
|
if 'message' in response:
|
|
|
|
|
|
|
|
raise F5ModuleError(response['message'])
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
raise F5ModuleError(resp.content)
|
|
|
|
|
|
|
|
|
|
|
|
def read_current_from_device(self):
|
|
|
|
def read_current_from_device(self):
|
|
|
|
resource = self.client.api.tm.gtm.pools.pool.load(
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/gtm/pool/{2}".format(
|
|
|
|
name=self.want.name,
|
|
|
|
self.client.provider['server'],
|
|
|
|
partition=self.want.partition
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
|
|
|
|
transform_name(self.want.partition, self.want.name)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
result = resource.attrs
|
|
|
|
resp = self.client.api.get(uri)
|
|
|
|
return ApiParameters(params=result)
|
|
|
|
try:
|
|
|
|
|
|
|
|
response = resp.json()
|
|
|
|
|
|
|
|
except ValueError as ex:
|
|
|
|
|
|
|
|
raise F5ModuleError(str(ex))
|
|
|
|
|
|
|
|
|
|
|
|
def create_on_device(self):
|
|
|
|
if 'code' in response and response['code'] == 400:
|
|
|
|
params = self.changes.api_params()
|
|
|
|
if 'message' in response:
|
|
|
|
self.client.api.tm.gtm.pools.pool.create(
|
|
|
|
raise F5ModuleError(response['message'])
|
|
|
|
name=self.want.name,
|
|
|
|
else:
|
|
|
|
partition=self.want.partition,
|
|
|
|
raise F5ModuleError(resp.content)
|
|
|
|
**params
|
|
|
|
return ApiParameters(params=response)
|
|
|
|
)
|
|
|
|
|
|
|
|
if self.want.monitors:
|
|
|
|
|
|
|
|
self.update_monitors_on_device()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def remove_from_device(self):
|
|
|
|
def remove_from_device(self):
|
|
|
|
resource = self.client.api.tm.gtm.pools.pool.load(
|
|
|
|
uri = "https://{0}:{1}/mgmt/tm/gtm/pool/{2}".format(
|
|
|
|
name=self.want.name,
|
|
|
|
self.client.provider['server'],
|
|
|
|
partition=self.want.partition
|
|
|
|
self.client.provider['server_port'],
|
|
|
|
|
|
|
|
transform_name(self.want.partition, self.want.name)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
resource.delete()
|
|
|
|
response = self.client.api.delete(uri)
|
|
|
|
|
|
|
|
if response.status == 200:
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
raise F5ModuleError(response.content)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ArgumentSpec(object):
|
|
|
|
class ArgumentSpec(object):
|
|
|
@ -1088,6 +1211,8 @@ class ArgumentSpec(object):
|
|
|
|
]
|
|
|
|
]
|
|
|
|
),
|
|
|
|
),
|
|
|
|
monitors=dict(type='list'),
|
|
|
|
monitors=dict(type='list'),
|
|
|
|
|
|
|
|
max_answers_returned=dict(type='int'),
|
|
|
|
|
|
|
|
ttl=dict(type='int')
|
|
|
|
)
|
|
|
|
)
|
|
|
|
self.argument_spec = {}
|
|
|
|
self.argument_spec = {}
|
|
|
|
self.argument_spec.update(f5_argument_spec)
|
|
|
|
self.argument_spec.update(f5_argument_spec)
|
|
|
@ -1105,20 +1230,18 @@ def main():
|
|
|
|
module = AnsibleModule(
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec=spec.argument_spec,
|
|
|
|
argument_spec=spec.argument_spec,
|
|
|
|
supports_check_mode=spec.supports_check_mode,
|
|
|
|
supports_check_mode=spec.supports_check_mode,
|
|
|
|
required_if=spec.required_if
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if not HAS_F5SDK:
|
|
|
|
|
|
|
|
module.fail_json(msg="The python f5-sdk module is required")
|
|
|
|
client = F5RestClient(**module.params)
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
client = F5Client(**module.params)
|
|
|
|
|
|
|
|
mm = ModuleManager(module=module, client=client)
|
|
|
|
mm = ModuleManager(module=module, client=client)
|
|
|
|
results = mm.exec_module()
|
|
|
|
results = mm.exec_module()
|
|
|
|
cleanup_tokens(client)
|
|
|
|
cleanup_tokens(client)
|
|
|
|
module.exit_json(**results)
|
|
|
|
exit_json(module, results, client)
|
|
|
|
except F5ModuleError as ex:
|
|
|
|
except F5ModuleError as ex:
|
|
|
|
cleanup_tokens(client)
|
|
|
|
cleanup_tokens(client)
|
|
|
|
module.fail_json(msg=str(ex))
|
|
|
|
fail_json(module, ex, client)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if __name__ == '__main__':
|
|
|
|