summaryrefslogtreecommitdiff
path: root/virtManager/addhardware.py
diff options
context:
space:
mode:
authorShalini Chellathurai Saroja <shalini@linux.ibm.com>2022-02-01 14:43:41 +0100
committerCole Robinson <crobinso@redhat.com>2022-02-03 15:29:26 -0500
commit216dc6e4e12a628ceebfd692075b3a36b7be97d8 (patch)
tree5d2ede6365fa0ee7efbb31641f7a3b5d3d1a5174 /virtManager/addhardware.py
parentd09e722a6f5a25bb56ab22a633955a07bd4d6667 (diff)
downloadvirt-manager-216dc6e4e12a628ceebfd692075b3a36b7be97d8.tar.gz
virt-manager: prevent attach of inactive nodedevs
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@linux.ibm.com> Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>
Diffstat (limited to 'virtManager/addhardware.py')
-rw-r--r--virtManager/addhardware.py42
1 files 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):