domain: Move get boot order methods to guest
Move get boot order methods to guest XML builder. For this we must replace self.get_bootable_devices() with self.get_bootable_devices(exclude_redirdev=True) in the _get_device_boot_order and set_device_boot_order to have no functionality change. Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com> Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
This commit is contained in:
parent
d0c2750da5
commit
853237aebc
|
@ -1197,64 +1197,11 @@ class vmmDomain(vmmLibvirtObject):
|
|||
def get_cpu_config(self):
|
||||
return self.get_xmlobj().cpu
|
||||
|
||||
def _convert_old_boot_order(self):
|
||||
"""Converts the old boot order (e.g. <boot dev='hd'/>) into the
|
||||
per-device boot order format.
|
||||
|
||||
"""
|
||||
boot_order = self._get_old_boot_order()
|
||||
ret = []
|
||||
disk = None
|
||||
cdrom = None
|
||||
floppy = None
|
||||
net = None
|
||||
|
||||
for d in self.xmlobj.devices.disk:
|
||||
if not cdrom and d.device == "cdrom":
|
||||
cdrom = d
|
||||
if not floppy and d.device == "floppy":
|
||||
floppy = d
|
||||
if not disk and d.device not in ["cdrom", "floppy"]:
|
||||
disk = d
|
||||
if cdrom and disk and floppy:
|
||||
break
|
||||
|
||||
for n in self.xmlobj.devices.interface:
|
||||
net = n
|
||||
break
|
||||
|
||||
for b in boot_order:
|
||||
if b == "network" and net:
|
||||
ret.append(net.get_xml_id())
|
||||
elif b == "hd" and disk:
|
||||
ret.append(disk.get_xml_id())
|
||||
elif b == "cdrom" and cdrom:
|
||||
ret.append(cdrom.get_xml_id())
|
||||
elif b == "fd" and floppy:
|
||||
ret.append(floppy.get_xml_id())
|
||||
return ret
|
||||
|
||||
def _get_device_boot_order(self):
|
||||
order = []
|
||||
for dev in self.get_bootable_devices():
|
||||
if not dev.boot.order:
|
||||
continue
|
||||
order.append((dev.get_xml_id(), dev.boot.order))
|
||||
|
||||
if not order:
|
||||
# No devices individually marked bootable, convert traditional
|
||||
# boot XML to fine grained, for the UI.
|
||||
return self._convert_old_boot_order()
|
||||
|
||||
order.sort(key=lambda p: p[1])
|
||||
return [p[0] for p in order]
|
||||
|
||||
def _get_old_boot_order(self):
|
||||
return self.get_xmlobj().os.bootorder
|
||||
def get_boot_order(self):
|
||||
if self.can_use_device_boot_order():
|
||||
return self._get_device_boot_order()
|
||||
return self._get_old_boot_order()
|
||||
return self.xmlobj.get_device_boot_order()
|
||||
return self.xmlobj.get_old_boot_order()
|
||||
|
||||
def get_boot_menu(self):
|
||||
guest = self.get_xmlobj()
|
||||
return bool(guest.os.enable_bootmenu)
|
||||
|
|
|
@ -312,6 +312,61 @@ class Guest(XMLBuilder):
|
|||
return self.__osinfo
|
||||
osinfo = property(_get_osinfo)
|
||||
|
||||
def get_old_boot_order(self):
|
||||
return self.os.bootorder
|
||||
|
||||
def _convert_old_boot_order(self):
|
||||
"""Converts the old boot order (e.g. <boot dev='hd'/>) into the
|
||||
per-device boot order format.
|
||||
|
||||
"""
|
||||
boot_order = self.get_old_boot_order()
|
||||
ret = []
|
||||
disk = None
|
||||
cdrom = None
|
||||
floppy = None
|
||||
net = None
|
||||
|
||||
for d in self.devices.disk:
|
||||
if not cdrom and d.device == "cdrom":
|
||||
cdrom = d
|
||||
if not floppy and d.device == "floppy":
|
||||
floppy = d
|
||||
if not disk and d.device not in ["cdrom", "floppy"]:
|
||||
disk = d
|
||||
if cdrom and disk and floppy:
|
||||
break
|
||||
|
||||
for n in self.devices.interface:
|
||||
net = n
|
||||
break
|
||||
|
||||
for b in boot_order:
|
||||
if b == "network" and net:
|
||||
ret.append(net.get_xml_id())
|
||||
elif b == "hd" and disk:
|
||||
ret.append(disk.get_xml_id())
|
||||
elif b == "cdrom" and cdrom:
|
||||
ret.append(cdrom.get_xml_id())
|
||||
elif b == "fd" and floppy:
|
||||
ret.append(floppy.get_xml_id())
|
||||
return ret
|
||||
|
||||
def get_device_boot_order(self):
|
||||
order = []
|
||||
for dev in self.get_bootable_devices(exclude_redirdev=True):
|
||||
if not dev.boot.order:
|
||||
continue
|
||||
order.append((dev.get_xml_id(), dev.boot.order))
|
||||
|
||||
if not order:
|
||||
# No devices individually marked bootable, convert traditional
|
||||
# boot XML to fine grained
|
||||
return self._convert_old_boot_order()
|
||||
|
||||
order.sort(key=lambda p: p[1])
|
||||
return [p[0] for p in order]
|
||||
|
||||
def set_device_boot_order(self, boot_order):
|
||||
"""Sets the new device boot order for the domain"""
|
||||
# Unset the traditional boot order
|
||||
|
|
Loading…
Reference in New Issue