[PATCH virt-manager v3] virt-manager: prevent attach of inactive nodedevs

Shalini Chellathurai Saroja shalini at linux.ibm.com
Tue Feb 1 13:43:41 UTC 2022


With virt-manager application, it is possible to add inactive node
devices(eg: mediated device) in host system to guest system. But it is
impossible to start a guest system with inactive node devices.  Also,
it is not yet possible to start a node device with virt-manager
application. So, the user cannot use the inactive node devices.

This patch disables the "finish" button and provides a tip, when
inactive node devices are selected. So, it is not possible to add
inactive node devices to the guest system.

Signed-off-by: Shalini Chellathurai Saroja <shalini at linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy at linux.ibm.com>
---
 virtManager/addhardware.py | 42 +++++++++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index 132ba4e0..60b58741 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -754,7 +754,7 @@ class vmmAddHardware(vmmGObjectUI):
     def _build_hostdev_treeview(self):
         host_dev = self.widget("host-device")
         # [ xmlobj, label]
-        host_dev_model = Gtk.ListStore(object, str)
+        host_dev_model = Gtk.ListStore(object, str, bool)
         host_dev.set_model(host_dev_model)
         host_col = Gtk.TreeViewColumn()
         text = Gtk.CellRendererText()
@@ -763,6 +763,28 @@ class vmmAddHardware(vmmGObjectUI):
         host_dev_model.set_sort_column_id(1, Gtk.SortType.ASCENDING)
         host_dev.append_column(host_col)
 
+
+    def disable_finish_if_inactive(self, selection):
+        model, row = selection.get_selected()
+
+        if row is None:
+            return
+
+        hostdev = model[row]
+        if hostdev[1] is None:
+            self.widget("create-finish").set_sensitive(False)
+            self.widget("create-finish").set_tooltip_text()
+        elif hostdev[2]:
+            self.widget("create-finish").set_sensitive(True)
+            self.widget("create-finish").set_tooltip_text()
+        else:
+            tooltip = (_("%s is not active in the host system.\n"
+            "Please start the mdev in the host system before adding it to the guest.")
+            % hostdev[1])
+            self.widget("create-finish").set_sensitive(False)
+            self.widget("create-finish").set_tooltip_text(tooltip)
+
+
     def _populate_hostdev_model(self, devtype):
         devlist = self.widget("host-device")
         model = devlist.get_model()
@@ -790,12 +812,26 @@ class vmmAddHardware(vmmGObjectUI):
                         prettyname = "%s %s" % (
                                 parentdev.pretty_name(), prettyname)
 
-            model.append([dev.xmlobj, prettyname])
+            model.append([dev.xmlobj, prettyname, dev.is_active()])
 
         if len(model) == 0:
-            model.append([None, _("No Devices Available")])
+            model.append([None, _("No Devices Available"), False])
+
         uiutil.set_list_selection_by_number(devlist, 0)
 
+        # enable/disable finish button for default selection
+        if model[0][2]:
+            self.widget("create-finish").set_sensitive(True)
+            self.widget("create-finish").set_tooltip_text()
+        else:
+            tooltip = (_("%s is not active in the host system.\n"
+            "Please start the mdev in the host system before adding it to the guest.")
+            % model[0][1])
+            self.widget("create-finish").set_sensitive(False)
+            self.widget("create-finish").set_tooltip_text(tooltip)
+
+        devlist.get_selection().connect("changed", self.disable_finish_if_inactive)
+
 
     @staticmethod
     def build_video_combo(vm, combo):
-- 
2.34.1




More information about the virt-tools-list mailing list