[PATCH] virt-manager: Add firmware preferences for creating a new VM
Charles Arnold
carnold at suse.com
Mon Oct 25 23:00:41 UTC 2021
From d30b50139e60afc6e5da1e38f130b27859d31a83 Mon Sep 17 00:00:00 2001
From: Charles Arnold <carnold at suse.com>
Date: Mon, 25 Oct 2021 16:16:06 -0600
Subject: virt-manager: Add firmware preferences for creating a new VM
Possible values are BIOS (default) and UEFI.
The firmware used is determined by libvirt unless a specific firmware is
selected from the Customize dialog.
See https://bugzilla.redhat.com/show_bug.cgi?id=1997882
---
.../org.virt-manager.virt-manager.gschema.xml | 6 +++++
ui/preferences.ui | 26 +++++++++++++++++++
virtManager/config.py | 11 ++++++++
virtManager/createvm.py | 4 +++
virtManager/preferences.py | 20 ++++++++++++++
5 files changed, 67 insertions(+)
diff --git a/data/org.virt-manager.virt-manager.gschema.xml
b/data/org.virt-manager.virt-manager.gschema.xml
index dadbb5b7..07908bdf 100644
--- a/data/org.virt-manager.virt-manager.gschema.xml
+++ b/data/org.virt-manager.virt-manager.gschema.xml
@@ -265,6 +265,12 @@
<description>CPU setting to use for new VMs. Limited to VMs
matching the host architecture. Possible values: default (virt-manager
default), hv-default (qemu's default), host-model-only (just the model,
not the additional features), host-model (libvirt's host-model setting),
host-passthrough (libvirt's host-passthrough setting).</description>
</key>
+ <key name="firmware" type="s">
+ <default>'default'</default>
+ <summary>Use selected firmware for new VM booting</summary>
+ <description>Firmware used for new VMs. Possible values are BIOS
(default) and UEFI. The firmware used is determined by libvirt unless a
specific firmware is selected from the Customize dialog.</description>
+ </key>
+
</schema>
<schema id="org.virt-manager.virt-manager.paths"
diff --git a/ui/preferences.ui b/ui/preferences.ui
index bfb25107..da5af1a8 100644
--- a/ui/preferences.ui
+++ b/ui/preferences.ui
@@ -494,6 +494,32 @@ identical CPUs in order to migrate the VM.</property>
<property name="top_attach">2</property>
</packing>
</child>
+ <child>
+ <object class="GtkLabel" id="label127">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="tooltip_text"
translatable="yes">Default Firmware for new VMs. Boot using either BIOS
or UEFI.</property>
+ <property name="halign">start</property>
+ <property name="label"
translatable="yes">_Firmware default:</property>
+ <property
name="use_underline">True</property>
+ <property
name="mnemonic_widget">prefs-firmware-default</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">3</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkComboBox"
id="prefs-firmware-default">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <signal name="changed"
handler="on_prefs_firmware_default_changed" swapped="no"/>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="top_attach">3</property>
+ </packing>
+ </child>
</object>
</child>
</object>
diff --git a/virtManager/config.py b/virtManager/config.py
index 86721e59..7dc6b94a 100644
--- a/virtManager/config.py
+++ b/virtManager/config.py
@@ -221,6 +221,7 @@ class vmmConfig(object):
self.default_storage_format_from_config = "qcow2"
self.default_console_resizeguest = 0
+ self.default_firmware_from_config = "bios"
self._objects = []
self.color_insensitive = None
@@ -532,6 +533,16 @@ class vmmConfig(object):
def set_default_cpu_setting(self, val):
self.conf.set("/new-vm/cpu-default", val.lower())
+ def get_default_firmware_setting(self, raw=False):
+ ret = self.conf.get("/new-vm/firmware")
+ if ret not in ["default", "bios", "uefi"]:
+ ret = "default" # pragma: no cover
+ if ret == "default" and not raw:
+ return self.default_firmware_from_config
+ return ret
+ def set_firmware_setting(self, val):
+ self.conf.set("/new-vm/firmware", val.lower())
+
# URL/Media path history
def _url_add_helper(self, gsettings_path, url):
diff --git a/virtManager/createvm.py b/virtManager/createvm.py
index a184f422..486d1dd7 100644
--- a/virtManager/createvm.py
+++ b/virtManager/createvm.py
@@ -105,6 +105,7 @@ class _GuestData:
self.os_variant = None
self.uefi_path = None
self.name = None
+ self.firmware = None
self.vcpus = None
self.memory = None
@@ -159,6 +160,8 @@ class _GuestData:
guest.currentMemory = self.currentMemory
if self.memory:
guest.memory = self.memory
+ if self.firmware == "uefi":
+ guest.os.firmware = "efi"
return guest
@@ -1425,6 +1428,7 @@ class vmmCreateVM(vmmGObjectUI):
gdata.default_graphics_type = self.config.get_graphics_type()
gdata.x86_cpu_default = self.config.get_default_cpu_setting()
+ gdata.firmware = self.config.get_default_firmware_setting()
return gdata
diff --git a/virtManager/preferences.py b/virtManager/preferences.py
index a2798b7e..5e5cc940 100644
--- a/virtManager/preferences.py
+++ b/virtManager/preferences.py
@@ -46,6 +46,7 @@ class vmmPreferences(vmmGObjectUI):
self.refresh_graphics_type()
self.refresh_storage_format()
self.refresh_cpu_default()
+ self.refresh_firmware_default()
self.refresh_cpu_poll()
self.refresh_disk_poll()
self.refresh_net_poll()
@@ -73,6 +74,7 @@ class vmmPreferences(vmmGObjectUI):
"on_prefs_graphics_type_changed": self.change_graphics_type,
"on_prefs_storage_format_changed": self.change_storage_format,
"on_prefs_cpu_default_changed": self.change_cpu_default,
+ "on_prefs_firmware_default_changed":
self.change_firmware_default,
"on_prefs_stats_enable_cpu_toggled": self.change_cpu_poll,
"on_prefs_stats_enable_disk_toggled": self.change_disk_poll,
"on_prefs_stats_enable_net_toggled": self.change_net_poll,
@@ -175,6 +177,17 @@ class vmmPreferences(vmmGObjectUI):
combo.set_model(model)
uiutil.init_combo_text_column(combo, 1)
+ combo = self.widget("prefs-firmware-default")
+ # [gsettings value, string]
+ model = Gtk.ListStore(str, str)
+ for row in [["default", _("System default (%s)") %
+ self.config.default_firmware_from_config],
+ ["bios", "BIOS"],
+ ["uefi", "UEFI"]]:
+ model.append(row)
+ combo.set_model(model)
+ uiutil.init_combo_text_column(combo, 1)
+
if not vmmInspection.libguestfs_installed(): # pragma: no cover
self.widget("prefs-libguestfs").set_sensitive(False)
self.widget("prefs-libguestfs").set_tooltip_text(
@@ -234,6 +247,10 @@ class vmmPreferences(vmmGObjectUI):
combo = self.widget("prefs-cpu-default")
val = self.config.get_default_cpu_setting()
uiutil.set_list_selection(combo, val)
+ def refresh_firmware_default(self):
+ combo = self.widget("prefs-firmware-default")
+ val = self.config.get_default_firmware_setting(raw=True)
+ uiutil.set_list_selection(combo, val)
def refresh_cpu_poll(self):
self.widget("prefs-stats-enable-cpu").set_active(
@@ -374,6 +391,9 @@ class vmmPreferences(vmmGObjectUI):
def change_cpu_default(self, src):
typ = uiutil.get_list_selection(src) or "default"
self.config.set_default_cpu_setting(typ.lower())
+ def change_firmware_default(self, src):
+ typ = uiutil.get_list_selection(src) or "default"
+ self.config.set_firmware_setting(typ.lower())
def change_cpu_poll(self, src):
self.config.set_stats_enable_cpu_poll(src.get_active())
--
2.26.2
More information about the virt-tools-list
mailing list