From e5243ef1d7bb12b255980e3830e81be760a1d62b Mon Sep 17 00:00:00 2001 From: Wojciech Wypior Date: Thu, 22 Aug 2019 04:51:23 +0100 Subject: [PATCH] enabled specyfing snat translation objects as pool members (#61076) added route domain support added diff functionality --- .../modules/network/f5/bigip_snat_pool.py | 49 ++++++++++++++++--- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/network/f5/bigip_snat_pool.py b/lib/ansible/modules/network/f5/bigip_snat_pool.py index e0c8657e77b..690a7ef5000 100644 --- a/lib/ansible/modules/network/f5/bigip_snat_pool.py +++ b/lib/ansible/modules/network/f5/bigip_snat_pool.py @@ -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-].*(?