mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-01-11 05:17:59 +03:00
VirtualDisk: Make get_xml_config not have side effects
Move all the defaults setting to a set_defaults function, wire it up to Guest.get_xml_config.
This commit is contained in:
parent
e7b518cbff
commit
02f35628fb
@ -531,7 +531,7 @@ class Guest(XMLBuilder):
|
|||||||
|
|
||||||
newlist = []
|
newlist = []
|
||||||
for i in devlist:
|
for i in devlist:
|
||||||
if i.virtual_device_type == devtype:
|
if devtype == "all" or i.virtual_device_type == devtype:
|
||||||
newlist.append(i)
|
newlist.append(i)
|
||||||
return newlist
|
return newlist
|
||||||
|
|
||||||
@ -1328,6 +1328,9 @@ class Guest(XMLBuilder):
|
|||||||
self.add_device(ctrl)
|
self.add_device(ctrl)
|
||||||
|
|
||||||
def _set_defaults(self, devlist_func, remove_func, features):
|
def _set_defaults(self, devlist_func, remove_func, features):
|
||||||
|
for dev in devlist_func("all"):
|
||||||
|
dev.set_defaults()
|
||||||
|
|
||||||
if self.installer.is_hvm():
|
if self.installer.is_hvm():
|
||||||
self._set_hvm_defaults(devlist_func, features)
|
self._set_hvm_defaults(devlist_func, features)
|
||||||
if self.installer.is_xenpv():
|
if self.installer.is_xenpv():
|
||||||
|
@ -773,29 +773,7 @@ class VirtualDisk(VirtualDevice):
|
|||||||
if volobj:
|
if volobj:
|
||||||
self._change_storage(vol_object=volobj)
|
self._change_storage(vol_object=volobj)
|
||||||
|
|
||||||
|
def set_defaults(self):
|
||||||
def _get_xml_config(self, disknode=None):
|
|
||||||
"""
|
|
||||||
@param disknode: device name in host (xvda, hdb, etc.). self.target
|
|
||||||
takes precedence.
|
|
||||||
@type disknode: C{str}
|
|
||||||
"""
|
|
||||||
# pylint: disable=W0221
|
|
||||||
# Argument number differs from overridden method
|
|
||||||
|
|
||||||
typeattr = self.type
|
|
||||||
if self.type == VirtualDisk.TYPE_BLOCK:
|
|
||||||
typeattr = 'dev'
|
|
||||||
|
|
||||||
if self.target:
|
|
||||||
disknode = self.target
|
|
||||||
|
|
||||||
path = self.path
|
|
||||||
if path:
|
|
||||||
path = util.xml_escape(path)
|
|
||||||
|
|
||||||
ret = " <disk type='%s' device='%s'>\n" % (self.type, self.device)
|
|
||||||
|
|
||||||
cache = self.driver_cache
|
cache = self.driver_cache
|
||||||
iomode = self.driver_io
|
iomode = self.driver_io
|
||||||
|
|
||||||
@ -813,22 +791,38 @@ class VirtualDisk(VirtualDevice):
|
|||||||
self.type == self.TYPE_BLOCK):
|
self.type == self.TYPE_BLOCK):
|
||||||
iomode = self.IO_MODE_NATIVE
|
iomode = self.IO_MODE_NATIVE
|
||||||
|
|
||||||
|
self.driver_cache = cache
|
||||||
|
self.driver_io = iomode
|
||||||
|
|
||||||
|
if ((self.driver_cache or self.driver_io or self.driver_type) and
|
||||||
|
self.driver_name is None and
|
||||||
|
self.conn.is_qemu()):
|
||||||
|
self.driver_name = self.DRIVER_QEMU
|
||||||
|
|
||||||
|
if self.device == self.DEVICE_CDROM:
|
||||||
|
self.read_only = True
|
||||||
|
|
||||||
|
def _get_xml_config(self):
|
||||||
|
typeattr = self.type
|
||||||
|
if self.type == VirtualDisk.TYPE_BLOCK:
|
||||||
|
typeattr = 'dev'
|
||||||
|
path = self.path
|
||||||
|
if path:
|
||||||
|
path = util.xml_escape(path)
|
||||||
|
|
||||||
|
ret = " <disk type='%s' device='%s'>\n" % (self.type, self.device)
|
||||||
|
|
||||||
|
|
||||||
if path:
|
if path:
|
||||||
drvxml = ""
|
drvxml = ""
|
||||||
if not self.driver_type is None:
|
if self.driver_type is not None:
|
||||||
drvxml += " type='%s'" % self.driver_type
|
drvxml += " type='%s'" % self.driver_type
|
||||||
if not cache is None:
|
if self.driver_cache is not None:
|
||||||
drvxml += " cache='%s'" % cache
|
drvxml += " cache='%s'" % self.driver_cache
|
||||||
if not iomode is None:
|
if self.driver_io is not None:
|
||||||
drvxml += " io='%s'" % iomode
|
drvxml += " io='%s'" % self.driver_io
|
||||||
|
if self.driver_name is not None:
|
||||||
if drvxml and self.driver_name is None:
|
|
||||||
if self.conn.is_qemu():
|
|
||||||
self.driver_name = "qemu"
|
|
||||||
|
|
||||||
if not self.driver_name is None:
|
|
||||||
drvxml = (" name='%s'" % self.driver_name) + drvxml
|
drvxml = (" name='%s'" % self.driver_name) + drvxml
|
||||||
|
|
||||||
if drvxml:
|
if drvxml:
|
||||||
ret += " <driver%s/>\n" % drvxml
|
ret += " <driver%s/>\n" % drvxml
|
||||||
|
|
||||||
@ -838,15 +832,11 @@ class VirtualDisk(VirtualDevice):
|
|||||||
bus_xml = ""
|
bus_xml = ""
|
||||||
if self.bus is not None:
|
if self.bus is not None:
|
||||||
bus_xml = " bus='%s'" % self.bus
|
bus_xml = " bus='%s'" % self.bus
|
||||||
ret += " <target dev='%s'%s/>\n" % (disknode, bus_xml)
|
ret += " <target dev='%s'%s/>\n" % (self.target, bus_xml)
|
||||||
|
|
||||||
ro = self.read_only
|
|
||||||
|
|
||||||
if self.device == self.DEVICE_CDROM:
|
|
||||||
ro = True
|
|
||||||
if self.shareable:
|
if self.shareable:
|
||||||
ret += " <shareable/>\n"
|
ret += " <shareable/>\n"
|
||||||
if ro:
|
if self.read_only:
|
||||||
ret += " <readonly/>\n"
|
ret += " <readonly/>\n"
|
||||||
|
|
||||||
addr = self.indent(self.address.get_xml_config(), 6)
|
addr = self.indent(self.address.get_xml_config(), 6)
|
||||||
|
@ -591,6 +591,9 @@ class XMLBuilder(object):
|
|||||||
self._xml_ctx.xpathFreeContext()
|
self._xml_ctx.xpathFreeContext()
|
||||||
self._xml_ctx = None
|
self._xml_ctx = None
|
||||||
|
|
||||||
|
def set_defaults(self):
|
||||||
|
pass
|
||||||
|
|
||||||
def _get_xml_config(self):
|
def _get_xml_config(self):
|
||||||
"""
|
"""
|
||||||
Internal XML building function. Must be overwritten by subclass
|
Internal XML building function. Must be overwritten by subclass
|
||||||
|
Loading…
Reference in New Issue
Block a user