Corrects downstream bugs in static-route module (#44775)
parent
893d59fabe
commit
f383826d76
|
@ -162,7 +162,11 @@ try:
|
||||||
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 exit_json
|
from library.module_utils.network.f5.common import exit_json
|
||||||
from library.module_utils.network.f5.common import fail_json
|
from library.module_utils.network.f5.common import fail_json
|
||||||
|
from library.module_utils.network.f5.ipaddress import is_valid_ip
|
||||||
|
from library.module_utils.network.f5.ipaddress import ipv6_netmask_to_cidr
|
||||||
|
from library.module_utils.compat.ipaddress import ip_address
|
||||||
from library.module_utils.compat.ipaddress import ip_network
|
from library.module_utils.compat.ipaddress import ip_network
|
||||||
|
from library.module_utils.compat.ipaddress import ip_interface
|
||||||
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
|
||||||
|
@ -173,7 +177,11 @@ except ImportError:
|
||||||
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 exit_json
|
from ansible.module_utils.network.f5.common import exit_json
|
||||||
from ansible.module_utils.network.f5.common import fail_json
|
from ansible.module_utils.network.f5.common import fail_json
|
||||||
|
from ansible.module_utils.network.f5.ipaddress import is_valid_ip
|
||||||
|
from ansible.module_utils.network.f5.ipaddress import ipv6_netmask_to_cidr
|
||||||
|
from ansible.module_utils.compat.ipaddress import ip_address
|
||||||
from ansible.module_utils.compat.ipaddress import ip_network
|
from ansible.module_utils.compat.ipaddress import ip_network
|
||||||
|
from ansible.module_utils.compat.ipaddress import ip_interface
|
||||||
|
|
||||||
|
|
||||||
class Parameters(AnsibleF5Parameters):
|
class Parameters(AnsibleF5Parameters):
|
||||||
|
@ -264,7 +272,7 @@ class ModuleParameters(Parameters):
|
||||||
if self._values['destination'].startswith('default'):
|
if self._values['destination'].startswith('default'):
|
||||||
self._values['destination'] = '0.0.0.0/0'
|
self._values['destination'] = '0.0.0.0/0'
|
||||||
if self._values['destination'].startswith('default-inet6'):
|
if self._values['destination'].startswith('default-inet6'):
|
||||||
self._values['destination'] = '::/::'
|
self._values['destination'] = '::/0'
|
||||||
try:
|
try:
|
||||||
ip = ip_network(u'%s' % str(self.destination_ip))
|
ip = ip_network(u'%s' % str(self.destination_ip))
|
||||||
if self.route_domain:
|
if self.route_domain:
|
||||||
|
@ -286,22 +294,36 @@ class ModuleParameters(Parameters):
|
||||||
def netmask(self):
|
def netmask(self):
|
||||||
if self._values['netmask'] is None:
|
if self._values['netmask'] is None:
|
||||||
return None
|
return None
|
||||||
# Check if numeric
|
|
||||||
try:
|
try:
|
||||||
result = int(self._values['netmask'])
|
result = int(self._values['netmask'])
|
||||||
if 0 <= result < 256:
|
|
||||||
|
# CIDRs between 0 and 128 are allowed
|
||||||
|
if 0 <= result <= 128:
|
||||||
return result
|
return result
|
||||||
|
else:
|
||||||
|
raise F5ModuleError(
|
||||||
|
"The provided netmask must be between 0 and 32 for IPv4, or "
|
||||||
|
"0 and 128 for IPv6."
|
||||||
|
)
|
||||||
|
except ValueError:
|
||||||
|
# not a number, but that's ok. Further processing necessary
|
||||||
|
pass
|
||||||
|
|
||||||
|
if not is_valid_ip(self._values['netmask']):
|
||||||
raise F5ModuleError(
|
raise F5ModuleError(
|
||||||
'The provided netmask {0} is neither in IP or CIDR format'.format(result)
|
'The provided netmask {0} is neither in IP or CIDR format'.format(result)
|
||||||
)
|
)
|
||||||
except ValueError:
|
|
||||||
try:
|
# Create a temporary address to check if the netmask IP is v4 or v6
|
||||||
ip = ip_network(u'%s' % str(self._values['netmask']))
|
addr = ip_address(u'{0}'.format(str(self._values['netmask'])))
|
||||||
except ValueError:
|
if addr.version == 4:
|
||||||
raise F5ModuleError(
|
# Create a more real v4 address using a wildcard, so that we can determine
|
||||||
'The provided netmask {0} is neither in IP or CIDR format'.format(self._values['netmask'])
|
# the CIDR value from it.
|
||||||
)
|
ip = ip_network(u'0.0.0.0/%s' % str(self._values['netmask']))
|
||||||
result = int(ip.prefixlen)
|
result = ip.prefixlen
|
||||||
|
else:
|
||||||
|
result = ipv6_netmask_to_cidr(self._values['netmask'])
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
@ -343,9 +365,9 @@ class ApiParameters(Parameters):
|
||||||
if destination.startswith('default%'):
|
if destination.startswith('default%'):
|
||||||
destination = '0.0.0.0%{0}/0'.format(destination.split('%')[1])
|
destination = '0.0.0.0%{0}/0'.format(destination.split('%')[1])
|
||||||
elif destination.startswith('default-inet6%'):
|
elif destination.startswith('default-inet6%'):
|
||||||
destination = '::%{0}/::'.format(destination.split('%')[1])
|
destination = '::%{0}/0'.format(destination.split('%')[1])
|
||||||
elif destination.startswith('default-inet6'):
|
elif destination.startswith('default-inet6'):
|
||||||
destination = '::/::'
|
destination = '::/0'
|
||||||
elif destination.startswith('default'):
|
elif destination.startswith('default'):
|
||||||
destination = '0.0.0.0/0'
|
destination = '0.0.0.0/0'
|
||||||
return destination
|
return destination
|
||||||
|
|
Loading…
Reference in New Issue