Merge "Reuse methods from netutils"

This commit is contained in:
Jenkins 2015-01-05 17:21:32 +00:00 committed by Gerrit Code Review
commit 3384940caf
2 changed files with 2 additions and 20 deletions
nova
db/sqlalchemy
utils.py

View File

@ -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

View File

@ -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