Merge "Reuse methods from netutils"
This commit is contained in:
commit
3384940caf
@ -15,6 +15,7 @@
|
||||
|
||||
"""Custom SQLAlchemy types."""
|
||||
|
||||
from oslo.utils import netutils
|
||||
import netaddr
|
||||
from sqlalchemy.dialects import postgresql
|
||||
from sqlalchemy import types
|
||||
@ -39,7 +40,7 @@ class IPAddress(types.TypeDecorator):
|
||||
return value
|
||||
# NOTE(maurosr): The purpose here is to convert ipv6 to the shortened
|
||||
# form, not validate it.
|
||||
elif utils.is_valid_ipv6(value):
|
||||
elif netutils.is_valid_ipv6(value):
|
||||
return utils.get_shortened_ipv6(value)
|
||||
return value
|
||||
|
||||
|
@ -492,25 +492,6 @@ def is_int_like(val):
|
||||
return False
|
||||
|
||||
|
||||
def is_valid_ipv4(address):
|
||||
"""Verify that address represents a valid IPv4 address."""
|
||||
try:
|
||||
return netaddr.valid_ipv4(address)
|
||||
except (ValueError, netaddr.AddrFormatError):
|
||||
return False
|
||||
|
||||
|
||||
def is_valid_ipv6(address):
|
||||
try:
|
||||
return netaddr.valid_ipv6(address)
|
||||
except (ValueError, netaddr.AddrFormatError):
|
||||
return False
|
||||
|
||||
|
||||
def is_valid_ip_address(address):
|
||||
return is_valid_ipv4(address) or is_valid_ipv6(address)
|
||||
|
||||
|
||||
def is_valid_ipv6_cidr(address):
|
||||
try:
|
||||
netaddr.IPNetwork(address, version=6).cidr
|
||||
|
Loading…
Reference in New Issue
Block a user