Fixes ipv6 and defaults errors (#48776)

This commit is contained in:
Tim Rupp 2018-11-15 20:15:11 -08:00 committed by GitHub
parent 01b06dd5f2
commit 2cd4224fb3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 8 deletions

View file

@ -94,12 +94,12 @@ def is_valid_ip_interface(address):
def get_netmask(address):
addr = ip_network(address)
addr = ip_network(u'{0}'.format(address))
netmask = addr.netmask.compressed
return netmask
def compress_address(address):
addr = ip_network(address)
addr = ip_network(u'{0}'.format(address))
result = addr.compressed.split('/')[0]
return result

View file

@ -36,7 +36,9 @@ options:
description:
- Netmask of the provided virtual address. This value cannot be
modified after it is set.
default: 255.255.255.255
- When creating a new virtual address, if this parameter is not specified, the
default value is C(255.255.255.255) for IPv4 addresses and
C(ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff) for IPv6 addresses.
connection_limit:
description:
- Specifies the number of concurrent connections that the system
@ -279,6 +281,7 @@ try:
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.ipaddress import is_valid_ip
from library.module_utils.network.f5.ipaddress import compress_address
from library.module_utils.network.f5.icontrol import tmos_version
except ImportError:
from ansible.module_utils.network.f5.bigip import F5RestClient
@ -291,6 +294,7 @@ except ImportError:
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.ipaddress import is_valid_ip
from ansible.module_utils.network.f5.ipaddress import compress_address
from ansible.module_utils.network.f5.icontrol import tmos_version
@ -487,7 +491,7 @@ class ModuleParameters(Parameters):
if self._values['address'] is None:
return None
if is_valid_ip(self._values['address']):
return self._values['address']
return compress_address(self._values['address'])
else:
raise F5ModuleError(
"The provided 'address' is not a valid IP address"
@ -713,6 +717,7 @@ class ModuleManager(object):
def create(self):
self._set_changed_options()
if self.want.traffic_group is None:
self.want.update({'traffic_group': '/Common/traffic-group-1'})
if self.want.arp is None:
@ -720,6 +725,12 @@ class ModuleManager(object):
if self.want.spanning is None:
self.want.update({'spanning': False})
if self.want.netmask is None:
if is_valid_ip(self.want.address, type='ipv4'):
self.want.update({'netmask': '255.255.255.255'})
else:
self.want.update({'netmask': 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'})
if self.want.arp and self.want.spanning:
raise F5ModuleError(
"'arp' and 'spanning' cannot both be enabled on virtual address."
@ -866,10 +877,7 @@ class ArgumentSpec(object):
),
name=dict(),
address=dict(),
netmask=dict(
type='str',
default='255.255.255.255',
),
netmask=dict(),
connection_limit=dict(
type='int'
),