Add `reorder_boot_order` method to Guest class. It sets the boot order of the passed `dev` to `boot_index` and adapts all other boot indices of the guest accordingly. Signed-off-by: Marc Hartmayer <mhartmay@xxxxxxxxxxxxx> Reviewed-by: Boris Fiuczynski <fiuczy@xxxxxxxxxxxxx> --- virtinst/guest.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/virtinst/guest.py b/virtinst/guest.py index 13b88cf2a987..708664348a79 100644 --- a/virtinst/guest.py +++ b/virtinst/guest.py @@ -338,6 +338,40 @@ class Guest(XMLBuilder): else: self._set_device_boot_order(boot_order) + def reorder_boot_order(self, dev, boot_index): + """Sets boot order of `dev` to `boot_index` + + Sets the boot order for device `dev` to value `boot_index` and + adjusts all other boot indices accordingly. Additionally the + boot order defined in the 'os' node of a domain definition is + disabled since they are mutually exclusive in libvirt. + + """ + # unset legacy boot order + self.os.bootorder = [] + + # Sort the bootable devices by boot order + devs_sorted = sorted([device for device in self.get_bootable_devices() + if device.boot.order is not None], + key=lambda device: device.boot.order) + + # set new boot order + dev.boot.order = boot_index + + next_boot_index = None + for device in devs_sorted: + if device is dev: + continue + + if device.boot.order in [next_boot_index, boot_index]: + next_boot_index = device.boot.order + 1 + device.boot.order = next_boot_index + continue + + if next_boot_index is not None: + # we found a hole so we can stop here + break + def set_os_name(self, name): obj = OSDB.lookup_os(name) if obj is None: -- 2.17.0 _______________________________________________ virt-tools-list mailing list virt-tools-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/virt-tools-list