mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
interface: check ip address format
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
This commit is contained in:
parent
7f802e287c
commit
89c45af26d
@ -15,7 +15,7 @@
|
|||||||
</protocol>
|
</protocol>
|
||||||
<protocol family="ipv6">
|
<protocol family="ipv6">
|
||||||
<ip address="fe99::215:58ff:fe6e:5" prefix="32"/>
|
<ip address="fe99::215:58ff:fe6e:5" prefix="32"/>
|
||||||
<ip address="foobar" prefix="38"/>
|
<ip address="2002::" prefix="38"/>
|
||||||
<route gateway="1.2.3.4"/>
|
<route gateway="1.2.3.4"/>
|
||||||
</protocol>
|
</protocol>
|
||||||
</interface>
|
</interface>
|
||||||
|
@ -965,7 +965,7 @@ class XMLParseTest(unittest.TestCase):
|
|||||||
check("autoconf", True, False)
|
check("autoconf", True, False)
|
||||||
|
|
||||||
check = self._make_checker(iface.protocols[1].ips[1])
|
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)
|
check("prefix", 64, 38)
|
||||||
|
|
||||||
# Remove a child interface, verify it's data remains intact
|
# Remove a child interface, verify it's data remains intact
|
||||||
|
@ -23,6 +23,7 @@ Classes for building and installing libvirt interface xml
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import libvirt
|
import libvirt
|
||||||
|
import ipaddr
|
||||||
|
|
||||||
from virtinst import util
|
from virtinst import util
|
||||||
from virtinst.xmlbuilder import XMLBuilder, XMLChildProperty, XMLProperty
|
from virtinst.xmlbuilder import XMLBuilder, XMLChildProperty, XMLProperty
|
||||||
@ -32,7 +33,15 @@ class _IPAddress(XMLBuilder):
|
|||||||
_XML_PROP_ORDER = ["address", "prefix"]
|
_XML_PROP_ORDER = ["address", "prefix"]
|
||||||
_XML_ROOT_NAME = "ip"
|
_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)
|
prefix = XMLProperty("./@prefix", is_int=True)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user