Subject: interface: check ip address format From: Chen Hanxiao chenhanxiao@cn.fujitsu.com Mon Mar 31 22:25:36 2014 +0800 Date: Mon Mar 31 22:25:36 2014 +0800: Git: 89c45af26deca41cba5dffcc4cae5e653fedc89a Signed-off-by: Chen Hanxiao Index: virt-manager-1.0.1/tests/xmlparse-xml/interface-test-bridge-ip-out.xml =================================================================== --- virt-manager-1.0.1.orig/tests/xmlparse-xml/interface-test-bridge-ip-out.xml +++ virt-manager-1.0.1/tests/xmlparse-xml/interface-test-bridge-ip-out.xml @@ -15,7 +15,7 @@ - + Index: virt-manager-1.0.1/tests/xmlparse.py =================================================================== --- virt-manager-1.0.1.orig/tests/xmlparse.py +++ virt-manager-1.0.1/tests/xmlparse.py @@ -958,7 +958,7 @@ class XMLParseTest(unittest.TestCase): check("autoconf", True, False) check = self._make_checker(iface.protocols[1].ips[1]) - check("address", "fe80::215:58ff:fe6e:5", "foobar") + check("address", "fe80::215:58ff:fe6e:5", "2002::") check("prefix", 64, 38) # Remove a child interface, verify it's data remains intact Index: virt-manager-1.0.1/virtinst/interface.py =================================================================== --- virt-manager-1.0.1.orig/virtinst/interface.py +++ virt-manager-1.0.1/virtinst/interface.py @@ -23,6 +23,7 @@ Classes for building and installing libv import logging import libvirt +import ipaddr from virtinst import util from virtinst.xmlbuilder import XMLBuilder, XMLChildProperty, XMLProperty @@ -32,7 +33,15 @@ class _IPAddress(XMLBuilder): _XML_PROP_ORDER = ["address", "prefix"] _XML_ROOT_NAME = "ip" - address = XMLProperty("./@address") + ###################### + # Validation helpers # + ###################### + + def _validate_ipaddr(self, addr): + ipaddr.IPAddress(addr) + return addr + + address = XMLProperty("./@address", validate_cb=_validate_ipaddr) prefix = XMLProperty("./@prefix", is_int=True)