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:
- 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.
- The members can be either IP addresses, or names of the SNAT translation objects.
type: list
aliases:
- member
@ -52,6 +53,10 @@ options:
type: str
default: Common
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
author:
- Tim Rupp (@caphrim007)
@ -117,6 +122,7 @@ members:
sample: "['10.10.10.10']"
'''
import re
import os
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 transform_name
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
except ImportError:
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 transform_name
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
@ -171,13 +179,25 @@ class ModuleParameters(Parameters):
return result
def _format_member_address(self, member):
if is_valid_ip(member):
address = '/{0}/{1}'.format(self.partition, member)
return address
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:
raise F5ModuleError(
'The provided member address is not a valid IP address'
)
if is_valid_ip(member):
address = '/{0}/{1}'.format(self.partition, member)
return address
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(
'The provided member address: {0} is not a valid IP address or snat translation name'.format(member)
)
@property
def members(self):
@ -310,8 +330,25 @@ class ModuleManager(object):
reportable = ReportableChanges(params=self.changes.to_return())
changes = reportable.to_return()
result.update(**changes)
if self.module._diff and self.have:
result['diff'] = self.make_diff()
result.update(dict(changed=changed))
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
def present(self):