enabled specyfing snat translation objects as pool members (#61076)

added route domain support
added diff functionality
This commit is contained in:
Wojciech Wypior 2019-08-22 04:51:23 +01:00 committed by Tim Rupp
parent 3a689d3b1f
commit e5243ef1d7

View file

@ -24,6 +24,7 @@ options:
description: description:
- List of members to put in the SNAT pool. When a C(state) of present is - List of members to put in the SNAT pool. When a C(state) of present is
provided, this parameter is required. Otherwise, it is optional. provided, this parameter is required. Otherwise, it is optional.
- The members can be either IP addresses, or names of the SNAT translation objects.
type: list type: list
aliases: aliases:
- member - member
@ -52,6 +53,10 @@ options:
type: str type: str
default: Common default: Common
version_added: 2.5 version_added: 2.5
notes:
- When C(bigip_snat_pool) object is removed it also removes any associated C(bigip_snat_translation) objects.
- This is a BIG-IP behavior not module behavior and it only occurs when the C(bigip_snat_translation) objects
are also not referenced by another C(bigip_snat_pool).
extends_documentation_fragment: f5 extends_documentation_fragment: f5
author: author:
- Tim Rupp (@caphrim007) - Tim Rupp (@caphrim007)
@ -117,6 +122,7 @@ members:
sample: "['10.10.10.10']" sample: "['10.10.10.10']"
''' '''
import re
import os import os
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
@ -130,6 +136,7 @@ try:
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 transform_name
from library.module_utils.network.f5.ipaddress import is_valid_ip from library.module_utils.network.f5.ipaddress import is_valid_ip
from library.module_utils.network.f5.ipaddress import compress_address
from library.module_utils.network.f5.compare import cmp_str_with_none from library.module_utils.network.f5.compare import cmp_str_with_none
except ImportError: except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient from ansible.module_utils.network.f5.bigip import F5RestClient
@ -139,6 +146,7 @@ except ImportError:
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 transform_name
from ansible.module_utils.network.f5.ipaddress import is_valid_ip from ansible.module_utils.network.f5.ipaddress import is_valid_ip
from ansible.module_utils.network.f5.ipaddress import compress_address
from ansible.module_utils.network.f5.compare import cmp_str_with_none from ansible.module_utils.network.f5.compare import cmp_str_with_none
@ -171,12 +179,24 @@ class ModuleParameters(Parameters):
return result return result
def _format_member_address(self, member): def _format_member_address(self, member):
if len(member.split('%')) > 1:
address, rd = member.split('%')
if is_valid_ip(address):
result = '/{0}/{1}%{2}'.format(self.partition, compress_address(address), rd)
return result
else:
if is_valid_ip(member): if is_valid_ip(member):
address = '/{0}/{1}'.format(self.partition, member) address = '/{0}/{1}'.format(self.partition, member)
return address return address
else: else:
# names must start with alphabetic character, and can contain hyphens and underscores and numbers
# no special characters are allowed
pattern = re.compile(r'(?!-)[A-Z-].*(?<!-)$', re.IGNORECASE)
if pattern.match(member):
address = '/{0}/{1}'.format(self.partition, member)
return address
raise F5ModuleError( raise F5ModuleError(
'The provided member address is not a valid IP address' 'The provided member address: {0} is not a valid IP address or snat translation name'.format(member)
) )
@property @property
@ -310,8 +330,25 @@ class ModuleManager(object):
reportable = ReportableChanges(params=self.changes.to_return()) reportable = ReportableChanges(params=self.changes.to_return())
changes = reportable.to_return() changes = reportable.to_return()
result.update(**changes) result.update(**changes)
if self.module._diff and self.have:
result['diff'] = self.make_diff()
result.update(dict(changed=changed)) result.update(dict(changed=changed))
self._announce_deprecations(result) self._announce_deprecations(result)
return result
def _grab_attr(self, item):
result = dict()
updatables = Parameters.updatables
for k in updatables:
if getattr(item, k) is not None:
result[k] = getattr(item, k)
return result
def make_diff(self):
result = dict(before=self._grab_attr(self.have), after=self._grab_attr(self.want))
return result return result
def present(self): def present(self):