mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-25 18:55:27 -06:00
XMLProperty: Add convenience param is_int
This commit is contained in:
parent
5f58d05051
commit
7d75a43e33
@ -283,8 +283,8 @@ class XMLParseTest(unittest.TestCase):
|
||||
check("iotune_rbs", 2, 0)
|
||||
check("iotune_wis", 3, 0)
|
||||
check("iotune_wbs", 4, 0)
|
||||
check("iotune_tis", 0, 5)
|
||||
check("iotune_tbs", 0, 6)
|
||||
check("iotune_tis", None, 5)
|
||||
check("iotune_tbs", None, 6)
|
||||
|
||||
|
||||
self._alter_compare(guest.get_xml_config(), outfile)
|
||||
|
@ -365,8 +365,7 @@ class Guest(XMLBuilder):
|
||||
val = self.__validate_cpus(val)
|
||||
self._maxvcpus = val
|
||||
maxvcpus = XMLProperty(_get_maxvcpus, _set_maxvcpus,
|
||||
xpath="./vcpu",
|
||||
get_converter=lambda s, x: int(x))
|
||||
xpath="./vcpu", is_int=True)
|
||||
|
||||
# set phy-cpus for the guest
|
||||
def get_cpuset(self):
|
||||
|
@ -496,24 +496,12 @@ class VirtualDisk(VirtualDevice):
|
||||
error_policy = XMLProperty(xpath="./driver/@error_policy")
|
||||
serial = XMLProperty(xpath="./serial")
|
||||
|
||||
iotune_rbs = XMLProperty(xpath="./iotune/read_bytes_sec",
|
||||
get_converter=lambda s, x: int(x or 0),
|
||||
set_converter=lambda s, x: int(x))
|
||||
iotune_ris = XMLProperty(xpath="./iotune/read_iops_sec",
|
||||
get_converter=lambda s, x: int(x or 0),
|
||||
set_converter=lambda s, x: int(x))
|
||||
iotune_tbs = XMLProperty(xpath="./iotune/total_bytes_sec",
|
||||
get_converter=lambda s, x: int(x or 0),
|
||||
set_converter=lambda s, x: int(x))
|
||||
iotune_tis = XMLProperty(xpath="./iotune/total_iops_sec",
|
||||
get_converter=lambda s, x: int(x or 0),
|
||||
set_converter=lambda s, x: int(x))
|
||||
iotune_wbs = XMLProperty(xpath="./iotune/write_bytes_sec",
|
||||
get_converter=lambda s, x: int(x or 0),
|
||||
set_converter=lambda s, x: int(x))
|
||||
iotune_wis = XMLProperty(xpath="./iotune/write_iops_sec",
|
||||
get_converter=lambda s, x: int(x or 0),
|
||||
set_converter=lambda s, x: int(x))
|
||||
iotune_rbs = XMLProperty(xpath="./iotune/read_bytes_sec", is_int=True)
|
||||
iotune_ris = XMLProperty(xpath="./iotune/read_iops_sec", is_int=True)
|
||||
iotune_tbs = XMLProperty(xpath="./iotune/total_bytes_sec", is_int=True)
|
||||
iotune_tis = XMLProperty(xpath="./iotune/total_iops_sec", is_int=True)
|
||||
iotune_wbs = XMLProperty(xpath="./iotune/write_bytes_sec", is_int=True)
|
||||
iotune_wis = XMLProperty(xpath="./iotune/write_iops_sec", is_int=True)
|
||||
|
||||
|
||||
#############################
|
||||
|
@ -206,9 +206,7 @@ class VirtualGraphics(VirtualDevice):
|
||||
raise ValueError(_("VNC port must be a number between "
|
||||
"5900 and 65535, or -1 for auto allocation"))
|
||||
self._port = val
|
||||
port = XMLProperty(get_port, set_port,
|
||||
get_converter=lambda s, x: int(x or -1),
|
||||
xpath="./@port")
|
||||
port = XMLProperty(get_port, set_port, is_int=True, xpath="./@port")
|
||||
|
||||
def get_listen(self):
|
||||
return self._listen
|
||||
@ -312,13 +310,19 @@ class VirtualGraphics(VirtualDevice):
|
||||
return self._build_xml(display=disp, xauth=xauth)
|
||||
|
||||
def _spice_config(self):
|
||||
return self._build_xml(port=self.port, keymap=self.keymap,
|
||||
port = self.port
|
||||
if port is None:
|
||||
port = -1
|
||||
return self._build_xml(port=port, keymap=self.keymap,
|
||||
passwd=self.passwd, listen=self.listen,
|
||||
tlsPort=self.tlsPort, canautoport=True,
|
||||
passwdValidTo=self.passwdValidTo)
|
||||
|
||||
def _vnc_config(self):
|
||||
return self._build_xml(port=self.port, keymap=self.keymap,
|
||||
port = self.port
|
||||
if port is None:
|
||||
port = -1
|
||||
return self._build_xml(port=port, keymap=self.keymap,
|
||||
passwd=self.passwd, listen=self.listen,
|
||||
# VNC supports autoport, but use legacy
|
||||
# syntax to not break XML tests
|
||||
|
@ -225,7 +225,7 @@ class XMLProperty(property):
|
||||
def __init__(self, fget=None, fset=None, doc=None,
|
||||
xpath=None, get_converter=None, set_converter=None,
|
||||
xml_get_xpath=None, xml_set_xpath=None,
|
||||
is_bool=False, is_tri=False, is_multi=False,
|
||||
is_bool=False, is_tri=False, is_int=False, is_multi=False,
|
||||
default_converter=None, clear_first=None):
|
||||
"""
|
||||
Set a XMLBuilder class property that represents a value in the
|
||||
@ -257,6 +257,7 @@ class XMLProperty(property):
|
||||
@param is_tri: Boolean XML property, but return None if there's
|
||||
no value set.
|
||||
@param is_multi: Whether data is coming multiple or a single node
|
||||
@param is_int: Whethere this is an integer property in the XML
|
||||
@param default_converter: If the virtinst value is "default", use
|
||||
this function to get the actual XML value
|
||||
@param clear_first: List of xpaths to unset before any 'set' operation.
|
||||
@ -268,6 +269,7 @@ class XMLProperty(property):
|
||||
|
||||
self._is_tri = is_tri
|
||||
self._is_bool = is_bool or is_tri
|
||||
self._is_int = is_int
|
||||
self._is_multi = is_multi
|
||||
|
||||
self._xpath_for_getter_cb = xml_get_xpath
|
||||
@ -439,6 +441,8 @@ class XMLProperty(property):
|
||||
val = self._convert_value_for_getter_cb(xmlbuilder, val)
|
||||
elif self._is_bool:
|
||||
val = True
|
||||
elif self._is_int:
|
||||
val = int(val)
|
||||
|
||||
if not self._is_multi:
|
||||
return val
|
||||
@ -530,6 +534,8 @@ class XMLBuilder(object):
|
||||
|
||||
|
||||
def copy(self):
|
||||
# pylint: disable=W0212
|
||||
# Access to protected member, needed to unittest stuff
|
||||
ret = copy.copy(self)
|
||||
ret._propstore = ret._propstore.copy()
|
||||
ret._proporder = ret._proporder[:]
|
||||
|
Loading…
Reference in New Issue
Block a user