Change in vdsm[master]: Simplify ip address validation leveraging socket.
asegurap at redhat.com
asegurap at redhat.com
Wed Jan 23 15:53:57 UTC 2013
Antoni Segura Puimedon has uploaded a new change for review.
Change subject: Simplify ip address validation leveraging socket.
......................................................................
Simplify ip address validation leveraging socket.
Currently we have a ad-hoc validation of the validity of ip
addresses. Since the standard socket module has a built-in
validator inside inet_pton, we could leverage it.
Change-Id: I6f43556f092d60160860e813b22fcc8660d82a80
Signed-off-by: Antoni S. Puimedon <asegurap at redhat.com>
---
M vdsm/configNetwork.py
1 file changed, 3 insertions(+), 7 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/34/11334/1
diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py
index bfdd505..5380f31 100755
--- a/vdsm/configNetwork.py
+++ b/vdsm/configNetwork.py
@@ -28,6 +28,7 @@
import threading
from xml.sax.saxutils import escape
import glob
+import socket
import shutil
import libvirt
@@ -701,13 +702,8 @@
def _validateIpAddress(address):
try:
- parts = address.split(".")
- if len(parts) != 4:
- return False
- for item in parts:
- if not 0 <= int(item) <= 255:
- return False
- except ValueError:
+ socket.inet_pton(socket.AF_INET, address)
+ except socket.error:
return False
return True
--
To view, visit http://gerrit.ovirt.org/11334
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6f43556f092d60160860e813b22fcc8660d82a80
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Antoni Segura Puimedon <asegurap at redhat.com>
More information about the vdsm-patches
mailing list