Merge "Use is_valid_cidr and is_valid_ipv6_cidr from oslo_utils"
This commit is contained in:
commit
fa987fe309
@ -59,7 +59,7 @@ class CIDR(types.TypeDecorator):
|
|||||||
def process_bind_param(self, value, dialect):
|
def process_bind_param(self, value, dialect):
|
||||||
"""Process/Formats the value before insert it into the db."""
|
"""Process/Formats the value before insert it into the db."""
|
||||||
# NOTE(sdague): normalize all the inserts
|
# NOTE(sdague): normalize all the inserts
|
||||||
if utils.is_valid_ipv6_cidr(value):
|
if netutils.is_valid_ipv6_cidr(value):
|
||||||
return utils.get_shortened_ipv6_cidr(value)
|
return utils.get_shortened_ipv6_cidr(value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -539,14 +539,6 @@ def parse_server_string(server_str):
|
|||||||
return ('', '')
|
return ('', '')
|
||||||
|
|
||||||
|
|
||||||
def is_valid_ipv6_cidr(address):
|
|
||||||
try:
|
|
||||||
netaddr.IPNetwork(address, version=6).cidr
|
|
||||||
return True
|
|
||||||
except (TypeError, netaddr.AddrFormatError):
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def get_shortened_ipv6(address):
|
def get_shortened_ipv6(address):
|
||||||
addr = netaddr.IPAddress(address, version=6)
|
addr = netaddr.IPAddress(address, version=6)
|
||||||
return str(addr.ipv6())
|
return str(addr.ipv6())
|
||||||
@ -557,29 +549,6 @@ def get_shortened_ipv6_cidr(address):
|
|||||||
return str(net.cidr)
|
return str(net.cidr)
|
||||||
|
|
||||||
|
|
||||||
def is_valid_cidr(address):
|
|
||||||
"""Check if address is valid
|
|
||||||
|
|
||||||
The provided address can be a IPv6 or a IPv4
|
|
||||||
CIDR address.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
# Validate the correct CIDR Address
|
|
||||||
netaddr.IPNetwork(address)
|
|
||||||
except netaddr.AddrFormatError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Prior validation partially verify /xx part
|
|
||||||
# Verify it here
|
|
||||||
ip_segment = address.split('/')
|
|
||||||
|
|
||||||
if (len(ip_segment) <= 1 or
|
|
||||||
ip_segment[1] == ''):
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def get_ip_version(network):
|
def get_ip_version(network):
|
||||||
"""Returns the IP version of a network (IPv4 or IPv6).
|
"""Returns the IP version of a network (IPv4 or IPv6).
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user