adds support for IPV4 addressing for interfaces (#58182)

pull/58197/head
Wojciech Wypior 5 years ago committed by Tim Rupp
parent 66c828d45f
commit 022b5d8b79

@ -138,6 +138,13 @@ options:
- modp4096 - modp4096
- modp6144 - modp6144
- modp8192 - modp8192
ipv4_interface:
description:
- When C(mode) is C(interface) indicate if the IPv4 C(any) address should be used.
By default C(BIG-IP) assumes C(any6) address for tunnel addresses when C(mode) is C(interface).
- This option takes effect only when C(mode) is set to C(interface).
type: bool
version_added: 2.9
partition: partition:
description: description:
- Device partition to manage resources on. - Device partition to manage resources on.
@ -155,6 +162,7 @@ options:
extends_documentation_fragment: f5 extends_documentation_fragment: f5
author: author:
- Tim Rupp (@caphrim007) - Tim Rupp (@caphrim007)
- Wojciech Wypior (@wojtek0806)
''' '''
EXAMPLES = r''' EXAMPLES = r'''
@ -248,6 +256,8 @@ try:
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 transform_name
from library.module_utils.network.f5.common import flatten_boolean
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
from ansible.module_utils.network.f5.common import F5ModuleError from ansible.module_utils.network.f5.common import F5ModuleError
@ -255,6 +265,8 @@ except ImportError:
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 transform_name
from ansible.module_utils.network.f5.common import flatten_boolean
from ansible.module_utils.network.f5.compare import cmp_str_with_none
class Parameters(AnsibleF5Parameters): class Parameters(AnsibleF5Parameters):
@ -312,52 +324,77 @@ class Parameters(AnsibleF5Parameters):
'route_domain', 'route_domain',
] ]
@property
def tunnel_local_address(self):
if self._values['tunnel_local_address'] is None:
return None
result = self._values['tunnel_local_address'].split('%')[0]
return result
class ApiParameters(Parameters):
@property @property
def encrypt_algorithm(self): def tunnel_remote_address(self):
if self._values['encrypt_algorithm'] is None: if self._values['tunnel_remote_address'] is None:
return None return None
elif self._values['encrypt_algorithm'] == 'null': result = self._values['tunnel_remote_address'].split('%')[0]
return 'none' return result
return self._values['encrypt_algorithm']
class ApiParameters(Parameters):
@property @property
def description(self): def description(self):
if self._values['description'] in [None, 'none']: if self._values['description'] in [None, 'none']:
return None return None
return self._values['description'] return self._values['description']
@property
def encrypt_algorithm(self):
if self._values['encrypt_algorithm'] is None:
return None
elif self._values['encrypt_algorithm'] == 'null':
return 'none'
return self._values['encrypt_algorithm']
@property @property
def route_domain(self): def route_domain(self):
if self.tunnel_local_address is None and self.tunnel_remote_address is None: if self._values['tunnel_local_address'] is None and self._values['tunnel_remote_address'] is None:
return None return None
elif self.tunnel_local_address is None and self.tunnel_remote_address is not None: elif self._values['tunnel_local_address'] is None and self._values['tunnel_remote_address'] is not None:
if self.tunnel_remote_address == 'any6': if self._values['tunnel_remote_address'] == 'any6':
result = 'any6' result = 'any6'
elif self._values['tunnel_remote_address'] == 'any':
result = 'any'
else: else:
result = int(self.tunnel_remote_address.split('%')[1]) result = int(self._values['tunnel_remote_address'].split('%')[1])
elif self.tunnel_remote_address is None and self.tunnel_local_address is not None: elif self._values['tunnel_remote_address'] is None and self._values['tunnel_local_address'] is not None:
if self.tunnel_local_address == 'any6': if self._values['tunnel_local_address'] == 'any6':
result = 'any6' result = 'any6'
elif self._values['tunnel_local_address'] == 'any':
result = 'any'
else: else:
result = int(self.tunnel_local_address.split('%')[1]) result = int(self._values['tunnel_local_address'].split('%')[1])
else: else:
try: try:
result = int(self.tunnel_local_address.split('%')[1]) result = int(self._values['tunnel_local_address'].split('%')[1])
except Exception: except Exception:
if self.tunnel_local_address == 'any6': if self._values['tunnel_local_address'] in ['any6', 'any']:
return 0 return 0
return None return None
try: try:
if result == 'any6': if result in ['any6', 'any']:
return 0 return 0
return int(self.tunnel_local_address.split('%')[1]) return int(self._values['tunnel_local_address'].split('%')[1])
except Exception: except Exception:
return None return None
class ModuleParameters(Parameters): class ModuleParameters(Parameters):
@property
def ipv4_interface(self):
result = flatten_boolean(self._values['ipv4_interface'])
if result == 'yes':
return True
return False
@property @property
def description(self): def description(self):
if self._values['description'] is None: if self._values['description'] is None:
@ -388,6 +425,24 @@ class UsableChanges(Changes):
return 'null' return 'null'
return self._values['encrypt_algorithm'] return self._values['encrypt_algorithm']
@property
def tunnel_local_address(self):
if self._values['tunnel_local_address'] is None:
return None
if self._values['route_domain'] and len(self._values['tunnel_local_address'].split('%')) == 1:
result = '{0}%{1}'.format(self._values['tunnel_local_address'], self._values['route_domain'])
return result
return self._values['tunnel_local_address']
@property
def tunnel_remote_address(self):
if self._values['tunnel_remote_address'] is None:
return None
if self._values['route_domain'] and len(self._values['tunnel_remote_address'].split('%')) == 1:
result = '{0}%{1}'.format(self._values['tunnel_remote_address'], self._values['route_domain'])
return result
return self._values['tunnel_remote_address']
class ReportableChanges(Changes): class ReportableChanges(Changes):
@property @property
@ -422,19 +477,20 @@ class Difference(object):
@property @property
def description(self): def description(self):
if self.want.description is None: return cmp_str_with_none(self.want.description, self.have.description)
return None
if self.have.description is None and self.want.description == '':
return None
if self.want.description != self.have.description:
return self.want.description
@property @property
def route_domain(self): def route_domain(self):
if self.want.route_domain is None: if self.want.route_domain is None:
return None return None
if self.have.route_domain != self.want.route_domain: if self.have.route_domain != self.want.route_domain:
if self.want.route_domain == 0: if self.want.route_domain == 0 and self.want.ipv4_interface:
return dict(
tunnel_local_address='any',
tunnel_remote_address='any',
route_domain=self.want.route_domain,
)
elif self.want.route_domain == 0 and not self.want.ipv4_interface:
return dict( return dict(
tunnel_local_address='any6', tunnel_local_address='any6',
tunnel_remote_address='any6', tunnel_remote_address='any6',
@ -552,12 +608,25 @@ class ModuleManager(object):
return True return True
def create(self): def create(self):
if self.want.mode == 'interface':
if self.want.ipv4_interface:
self._set_any_on_interface(ip='ipv4')
else:
self._set_any_on_interface()
self._set_changed_options() self._set_changed_options()
if self.module.check_mode: if self.module.check_mode:
return True return True
self.create_on_device() self.create_on_device()
return True return True
def _set_any_on_interface(self, ip='ipv6'):
if ip == 'ipv4':
self.want.update({'tunnel_local_address': 'any'})
self.want.update({'tunnel_remote_address': 'any'})
else:
self.want.update({'tunnel_local_address': 'any6'})
self.want.update({'tunnel_remote_address': 'any6'})
def create_on_device(self): def create_on_device(self):
params = self.changes.api_params() params = self.changes.api_params()
params['name'] = self.want.name params['name'] = self.want.name
@ -644,6 +713,7 @@ class ArgumentSpec(object):
mode=dict( mode=dict(
choices=['transport', 'interface', 'isession', 'tunnel'] choices=['transport', 'interface', 'isession', 'tunnel']
), ),
ipv4_interface=dict(type='bool'),
tunnel_local_address=dict(), tunnel_local_address=dict(),
tunnel_remote_address=dict(), tunnel_remote_address=dict(),
encrypt_algorithm=dict( encrypt_algorithm=dict(

@ -106,7 +106,6 @@ try:
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 f5_argument_spec from library.module_utils.network.f5.common import f5_argument_spec
from library.module_utils.network.f5.compare import compare_dictionary
from library.module_utils.network.f5.common import is_valid_hostname from library.module_utils.network.f5.common import is_valid_hostname
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.ipaddress import is_valid_ip from library.module_utils.network.f5.ipaddress import is_valid_ip
@ -115,7 +114,6 @@ except ImportError:
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 f5_argument_spec from ansible.module_utils.network.f5.common import f5_argument_spec
from ansible.module_utils.network.f5.compare import compare_dictionary
from ansible.module_utils.network.f5.common import is_valid_hostname from ansible.module_utils.network.f5.common import is_valid_hostname
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.ipaddress import is_valid_ip from ansible.module_utils.network.f5.ipaddress import is_valid_ip

Loading…
Cancel
Save