[virt-tools-list] [PATCH virt-manager 04/10] domain: Try to untangle __use_device_boot_order

Marc Hartmayer mhartmay at linux.ibm.com
Wed Feb 6 09:55:37 UTC 2019


Operate only on @boot_order and @guest and not on @self. This allows
us to refactor this functionality in the next patch. Additionally,
simplify the used algorithm without functionality change.

Signed-off-by: Marc Hartmayer <mhartmay at linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy at linux.ibm.com>
---
 virtManager/domain.py | 21 +++++++--------------
 1 file changed, 7 insertions(+), 14 deletions(-)

diff --git a/virtManager/domain.py b/virtManager/domain.py
index f43439c518c5..9c1a8e49cbe3 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -522,13 +522,6 @@ class vmmDomain(vmmLibvirtObject):
         self._redefine_xmlobj(guest)
 
     def __use_device_boot_order(self, boot_order, guest):
-        boot_dev_order = []
-        devmap = dict((dev.get_xml_id(), dev) for dev in
-                      guest.get_bootable_devices(exclude_redirdev=True))
-        for b in boot_order:
-            if b in devmap:
-                boot_dev_order.append(devmap[b])
-
         # Unset the traditional boot order
         guest.os.bootorder = []
 
@@ -536,13 +529,13 @@ class vmmDomain(vmmLibvirtObject):
         for dev in guest.devices.get_all():
             dev.boot.order = None
 
-        count = 1
-        for origdev in boot_dev_order:
-            dev = self._lookup_device_to_define(guest, origdev, False)
-            if not dev:
-                continue
-            dev.boot.order = count
-            count += 1
+        dev_map = dict((dev.get_xml_id(), dev) for dev in
+                       guest.get_bootable_devices(exclude_redirdev=True))
+        for boot_order_idx, dev_xml_id in enumerate(boot_order, 1):
+            try:
+                dev_map[dev_xml_id].boot.order = boot_order_idx
+            except KeyError:
+                pass
 
     def define_boot(self, boot_order=_SENTINEL, boot_menu=_SENTINEL,
                     kernel=_SENTINEL, initrd=_SENTINEL, dtb=_SENTINEL,
-- 
2.17.0




More information about the virt-tools-list mailing list