summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorRussell Bryant <rbryant@redhat.com>2013-02-01 04:06:09 -0500
committerRussell Bryant <rbryant@redhat.com>2013-02-02 16:15:50 +0100
commited45c0b95d6eea0d4a40437dcbbc5920a72aa939 (patch)
treed66e36d12540f4afb8e2c5fa90b99db2bc4116b7 /nova/utils.py
parent795d1bcfd13aae2d07f52a2a1a51117e78a234c8 (diff)
downloadnova-ed45c0b95d6eea0d4a40437dcbbc5920a72aa939.tar.gz
nova-ed45c0b95d6eea0d4a40437dcbbc5920a72aa939.tar.xz
nova-ed45c0b95d6eea0d4a40437dcbbc5920a72aa939.zip
Reimplement is_valid_ipv4().
This patch reimplements the is_valid_ipv4() function is nova.utils. Instead of open-coding the validity check, just make use of the netaddr module, which is already used elsewhere in nova.utils. Also add a unit test for this code. Part of indigoprint bored-on-an-airplane. Change-Id: Ia89cbbd94a0ac4631d794d658b53c244237e1ca2
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py17
1 files changed, 5 insertions, 12 deletions
diff --git a/nova/utils.py b/nova/utils.py
index be441bfcc..7dc4f6d8f 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -881,19 +881,12 @@ def is_valid_boolstr(val):
def is_valid_ipv4(address):
- """valid the address strictly as per format xxx.xxx.xxx.xxx.
- where xxx is a value between 0 and 255.
- """
- parts = address.split(".")
- if len(parts) != 4:
+ """Verify that address represents a valid IPv4 address."""
+ try:
+ addr = netaddr.IPAddress(address)
+ return addr.version == 4
+ except Exception:
return False
- for item in parts:
- try:
- if not 0 <= int(item) <= 255:
- return False
- except ValueError:
- return False
- return True
def is_valid_cidr(address):