[virt-tools-list] [PATCH] virt-manager: allow switching between USB1/piix3 and USB2/ich9 controller

Marc-André Lureau marcandre.lureau at gmail.com
Fri Sep 23 15:14:15 UTC 2011


---
 src/virtManager/details.py |   47 ++++++++++++++++++++++++++++++++++++++++++-
 src/virtManager/domain.py  |   20 ++++++++++++++++++
 src/vmm-details.glade      |   26 ++++++++++++++++++++++-
 3 files changed, 89 insertions(+), 4 deletions(-)

diff --git a/src/virtManager/details.py b/src/virtManager/details.py
index 9b53901..a7d5941 100644
--- a/src/virtManager/details.py
+++ b/src/virtManager/details.py
@@ -38,7 +38,7 @@ from virtManager import util as util
 import virtinst
 
 # Parameters that can be editted in the details window
-EDIT_TOTAL = 34
+EDIT_TOTAL = 35
 (EDIT_NAME,
 EDIT_ACPI,
 EDIT_APIC,
@@ -83,6 +83,8 @@ EDIT_VIDEO_MODEL,
 
 EDIT_WATCHDOG_MODEL,
 EDIT_WATCHDOG_ACTION,
+
+EDIT_CONTROLLER_MODEL
 ) = range(EDIT_TOTAL)
 
 
@@ -474,6 +476,8 @@ class vmmDetails(vmmGObjectUI):
             "on_console_pages_switch_page": self.console.page_changed,
             "on_console_auth_password_activate": self.console.auth_login,
             "on_console_auth_login_clicked": self.console.auth_login,
+            "on_controller_model_combo_changed": (self.enable_apply,
+                                                  EDIT_CONTROLLER_MODEL),
         })
 
         # Deliberately keep all this after signal connection
@@ -937,6 +941,16 @@ class vmmDetails(vmmGObjectUI):
         combo = self.widget("redir-type-combo")
         uihelpers.build_redir_type_combo(self.vm, combo)
 
+        # Controller model
+        combo = self.widget("controller-model-combo")
+        model = gtk.ListStore(str, str)
+        combo.set_model(model)
+        text = gtk.CellRendererText()
+        combo.pack_start(text, True)
+        combo.add_attribute(text, 'text', 1)
+        combo.set_active(-1)
+
+
     # Helper function to handle the combo/label pattern used for
     # video model, sound model, network model, etc.
     def set_combo_label(self, prefix, value, model_idx=0, label="",
@@ -1871,6 +1885,8 @@ class vmmDetails(vmmGObjectUI):
                 ret = self.config_watchdog_apply(key)
             elif pagetype is HW_LIST_TYPE_SMARTCARD:
                 ret = self.config_smartcard_apply(key)
+            elif pagetype is HW_LIST_TYPE_CONTROLLER:
+                ret = self.config_controller_apply(key)
             else:
                 ret = False
         except Exception, e:
@@ -2258,6 +2274,18 @@ class vmmDetails(vmmGObjectUI):
 
         return self._change_config_helper(df, da, hf, ha)
 
+    # Controller options
+    def config_controller_apply(self, dev_id_info):
+        df, da, add_define, hf, ha, add_hotplug = self.make_apply_data()
+        ignore = add_hotplug
+
+        if self.editted(EDIT_CONTROLLER_MODEL):
+            model = self.get_combo_label_value("controller-model")
+            if model:
+                add_define(self.vm.define_controller_model, dev_id_info, model)
+
+        return self._change_config_helper(df, da, hf, ha)
+
     # Watchdog options
     def config_watchdog_apply(self, dev_id_info):
         df, da, add_define, hf, ha, add_hotplug = self.make_apply_data()
@@ -3079,7 +3107,18 @@ class vmmDetails(vmmGObjectUI):
             model_label =  _("Default")
 
         self.widget("controller-type").set_text(type_label)
-        self.widget("controller-model").set_text(model_label)
+
+        combo = self.widget("controller-model-combo")
+        model = combo.get_model()
+        model.clear()
+        if dev.type == virtinst.VirtualController.CONTROLLER_TYPE_USB:
+            model.append(["Default", "Default"])
+            model.append(["ich9-ehci1", "USB 2"])
+            self.widget("config-remove").set_sensitive(False)
+        else:
+            self.widget("config-remove").set_sensitive(True)
+
+        self.set_combo_label("controller-model", model_label)
 
     def refresh_filesystem_page(self):
         dev = self.get_hw_selection(HW_LIST_COL_DEVICE)
@@ -3324,6 +3363,10 @@ class vmmDetails(vmmGObjectUI):
 
         # Populate controller devices
         for cont in self.vm.get_controller_devices():
+            # skip USB2 ICH9 companion controllers
+            if cont.model in [ "ich9-uhci1", "ich9-uhci2", "ich9-uhci3" ]:
+                continue
+
             pretty_type = virtinst.VirtualController.pretty_type(cont.type)
             update_hwlist(HW_LIST_TYPE_CONTROLLER, cont,
                           _("Controller %s") % pretty_type,
diff --git a/src/virtManager/domain.py b/src/virtManager/domain.py
index 6921dac..8483468 100644
--- a/src/virtManager/domain.py
+++ b/src/virtManager/domain.py
@@ -683,6 +683,26 @@ class vmmDomain(vmmLibvirtObject):
             editdev.mode = newmodel
         return self._redefine_device(change, devobj)
 
+    # Controller define methods
+
+    def define_controller_model(self, devobj, newmodel):
+        def change(editdev):
+            guest = self._get_guest_to_define()
+            ctrls = guest.get_devices("controller")
+            ctrls = filter(lambda x:
+                               (x.type ==
+                                virtinst.VirtualController.CONTROLLER_TYPE_USB),
+                           ctrls)
+            for dev in ctrls:
+                guest.remove_device(dev)
+
+            if newmodel == "ich9-ehci1":
+                print guest
+                guest.add_usb_ich9_controllers()
+
+        return self._redefine_device(change, devobj)
+
+
 
     ####################
     # Hotplug routines #
diff --git a/src/vmm-details.glade b/src/vmm-details.glade
index de46cc3..852db1f 100644
--- a/src/vmm-details.glade
+++ b/src/vmm-details.glade
@@ -5570,6 +5570,7 @@ I/O:</property>
                                           <widget class="GtkLabel" id="controller-type">
                                             <property name="visible">True</property>
                                             <property name="label">foo</property>
+                                            <property name="xalign">0</property>
                                           </widget>
                                           <packing>
                                             <property name="left_attach">1</property>
@@ -5593,9 +5594,30 @@ I/O:</property>
                                           </packing>
                                         </child>
                                         <child>
-                                          <widget class="GtkLabel" id="controller-model">
+
+                                          <widget class="GtkHBox" id="controller-model-box">
                                             <property name="visible">True</property>
-                                            <property name="label">foo</property>
+                                            <child>
+                                              <widget class="GtkComboBox" id="controller-model-combo">
+                                                <property name="visible">True</property>
+                                                <signal name="changed" handler="on_controller_model_combo_changed"/>
+                                              </widget>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="position">0</property>
+                                              </packing>
+                                            </child>
+                                            <child>
+                                              <widget class="GtkLabel" id="controller-model-label">
+                                                <property name="visible">True</property>
+                                                <property name="xalign">0</property>
+                                                <property name="label">label</property>
+                                              </widget>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="position">1</property>
+                                              </packing>
+                                            </child>
                                           </widget>
                                           <packing>
                                             <property name="left_attach">1</property>
-- 
1.7.6.2




More information about the virt-tools-list mailing list