Standarize ip validation along the code

Details:
 - Use the nova/utils.py validations along the code
 - refactor ipv4 validator to looks like ipv6 validator
 - interprets ip validations exceptions as Invalid IP values

Change-Id: Ia506c00510a066e167d3dcd9dd371a371129a9dd
This commit is contained in:
Mauro S. M. Rodrigues
2013-02-15 08:19:00 -05:00
parent f4b7435bf2
commit 473036d34f

View File

@@ -945,14 +945,16 @@ def is_valid_boolstr(val):
def is_valid_ipv4(address):
"""Verify that address represents a valid IPv4 address."""
try:
addr = netaddr.IPAddress(address)
return addr.version == 4
return netaddr.valid_ipv4(address)
except Exception:
return False
def is_valid_ipv6(address):
return netaddr.valid_ipv6(address)
try:
return netaddr.valid_ipv6(address)
except Exception:
return False
def is_valid_ipv6_cidr(address):