[virt-tools-list] [virt-manager PATCH]RFC: addhardware: Add controller options to addhw wizard

Chen Hanxiao chenhanxiao at cn.fujitsu.com
Fri Apr 4 10:04:02 UTC 2014


Add controller options to addhw wizard.

https://bugzilla.redhat.com/show_bug.cgi?id=1076607

Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
---
 ui/addhardware.ui          | 81 +++++++++++++++++++++++++++++++++++++++
 virtManager/addhardware.py | 95 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 176 insertions(+)

diff --git a/ui/addhardware.ui b/ui/addhardware.ui
index 4fc82fe..c67f4b7 100644
--- a/ui/addhardware.ui
+++ b/ui/addhardware.ui
@@ -1050,6 +1050,8 @@
                               <packing>
                                 <property name="left_attach">0</property>
                                 <property name="top_attach">5</property>
+                                <property name="width">1</property>
+                                <property name="height">1</property>
                               </packing>
                             </child>
                             <child>
@@ -1060,6 +1062,8 @@
                               <packing>
                                 <property name="left_attach">1</property>
                                 <property name="top_attach">5</property>
+                                <property name="width">1</property>
+                                <property name="height">1</property>
                               </packing>
                             </child>
                           </object>
@@ -1823,6 +1827,83 @@
                             <property name="tab_fill">False</property>
                           </packing>
                         </child>
+                        <child>
+                          <object class="GtkGrid" id="grid4">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="row_spacing">6</property>
+                            <property name="column_spacing">6</property>
+                            <child>
+                              <object class="GtkLabel" id="label18">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="xalign">0</property>
+                                <property name="label" translatable="yes">_Type:</property>
+                                <property name="use_underline">True</property>
+                              </object>
+                              <packing>
+                                <property name="left_attach">0</property>
+                                <property name="top_attach">0</property>
+                                <property name="width">1</property>
+                                <property name="height">1</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkLabel" id="label22">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <property name="xalign">0</property>
+                                <property name="label" translatable="yes">_Model:</property>
+                                <property name="use_underline">True</property>
+                              </object>
+                              <packing>
+                                <property name="left_attach">0</property>
+                                <property name="top_attach">1</property>
+                                <property name="width">1</property>
+                                <property name="height">1</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkComboBox" id="controller-type">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                                <signal name="changed" handler="on_controller_type_changed" swapped="no"/>
+                              </object>
+                              <packing>
+                                <property name="left_attach">1</property>
+                                <property name="top_attach">0</property>
+                                <property name="width">1</property>
+                                <property name="height">1</property>
+                              </packing>
+                            </child>
+                            <child>
+                              <object class="GtkComboBox" id="controller-model">
+                                <property name="visible">True</property>
+                                <property name="can_focus">False</property>
+                              </object>
+                              <packing>
+                                <property name="left_attach">1</property>
+                                <property name="top_attach">1</property>
+                                <property name="width">1</property>
+                                <property name="height">1</property>
+                              </packing>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="position">16</property>
+                          </packing>
+                        </child>
+                        <child type="tab">
+                          <object class="GtkLabel" id="label2">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="label" translatable="yes">Controller</property>
+                          </object>
+                          <packing>
+                            <property name="position">16</property>
+                            <property name="tab_fill">False</property>
+                          </packing>
+                        </child>
                       </object>
                     </child>
                   </object>
diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index bd999cc..03cff85 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -58,6 +58,7 @@ PAGE_USBREDIR = 12
 PAGE_TPM = 13
 PAGE_RNG = 14
 PAGE_PANIC = 15
+PAGE_CONTROLLER = 16
 
 
 class vmmAddHardware(vmmGObjectUI):
@@ -111,6 +112,8 @@ class vmmAddHardware(vmmGObjectUI):
             "on_rng_type_changed": self.change_rng,
             "on_rng_backend_mode_changed": self.change_rng,
             "on_rng_backend_type_changed": self.change_rng,
+
+            "on_controller_type_changed": self.populate_controller_model,
         })
         self.bind_escape_key_close()
 
@@ -312,6 +315,16 @@ class vmmAddHardware(vmmGObjectUI):
         combo = self.widget("panic-type")
         self.build_panic_address_type(combo)
 
+        # Controller widgets
+        combo = self.widget("controller-type")
+        target_model = Gtk.ListStore(str, str)
+        combo.set_model(target_model)
+        uiutil.set_combo_text_column(combo, 1)
+        combo = self.widget("controller-model")
+        target_model = Gtk.ListStore(str, str)
+        combo.set_model(target_model)
+        uiutil.set_combo_text_column(combo, 1)
+
         # Available HW options
         is_local = not self.conn.is_remote()
         is_storage_capable = self.conn.is_storage_capable()
@@ -382,6 +395,7 @@ class vmmAddHardware(vmmGObjectUI):
         add_hw_option("Panic Notifier", "system-run", PAGE_PANIC,
             self.conn.check_support(self.conn.SUPPORT_CONN_PANIC_DEVICE),
             _("Not supported for this hypervisor/libvirt combination."))
+        add_hw_option("Controller", "device_pci", PAGE_CONTROLLER, True, None)
 
     def reset_state(self):
         # Storage init
@@ -454,6 +468,9 @@ class vmmAddHardware(vmmGObjectUI):
         # Panic device params
         self.widget("panic-iobase").set_text("0x505")
 
+        # Controller device params
+        self.populate_controller_type()
+
         self.set_hw_selection(0)
 
 
@@ -812,6 +829,48 @@ class vmmAddHardware(vmmGObjectUI):
         if not create:
             format_list.get_child().set_text("")
 
+    def populate_controller_type(self):
+        widget = self.widget("controller-type")
+        model = widget.get_model()
+        model.clear()
+
+        for t in VirtualController.TYPES:
+            model.append([t, VirtualController.pretty_type(t)])
+
+        if len(model) > 0:
+            widget.set_active(0)
+
+    def populate_controller_model(self, src):
+        ignore = src
+
+        controller_type = self.get_config_controller_type()
+        modellist = self.widget("controller-model")
+        model = modellist.get_model()
+        model.clear()
+
+        scsi_models = ["auto", "buslogic", "lsilogic", "lsisas1068",
+                "vmpvscsi", "ibmvscsi", "virtio-scsi", "lsisas1078",
+                "none"]
+        pci_models = ["pci-root", "pcie-root", "pci-bridge",
+                "dmi-to-pci-bridge"]
+        usb_models = ["piix3-uhci", "piix4-uhci", "ehci", "ich9-ehci1",
+                "ich9-uhci1", "ich9-uhci2", "ich9-uhci3", "vt82c686b-uhci",
+                "pci-ohci", "nec-xhci", "none"]
+
+        if controller_type == "scsi":
+            for t in scsi_models:
+                model.append([t, t])
+        elif controller_type == "pci":
+            for t in pci_models:
+                model.append([t, t])
+        elif controller_type == "usb":
+            for t in usb_models:
+                model.append([t, t])
+        else:
+            model.append([None, "None"])
+
+        if len(model) > 0:
+            modellist.set_active(0)
 
     ########################
     # get_config_* methods #
@@ -879,6 +938,13 @@ class vmmAddHardware(vmmGObjectUI):
         self.build_combo_with_values(combo, types,
                 virtinst.VirtualPanicDevice.ADDRESS_TYPE_ISA)
 
+    def build_controller_type(self, combo):
+        types = []
+        for t in VirtualController.TYPES:
+            types.append([t, VirtualController.pretty_type(t)])
+        self.build_combo_with_values(combo, types)
+
+
     def get_config_hardware_type(self):
         row = self.get_hw_selection()
         if not row:
@@ -1007,6 +1073,13 @@ class vmmAddHardware(vmmGObjectUI):
     def get_config_rng_backend_mode(self):
         return uiutil.get_list_selection(self.widget("rng-backend-mode"), 0)
 
+    # CONTROLLER getters
+    def get_config_controller_type(self):
+        return uiutil.get_list_selection(self.widget("controller-type"), 0)
+
+    def get_config_controller_model(self):
+        return uiutil.get_list_selection(self.widget("controller-model"), 0)
+
     ################
     # UI listeners #
     ################
@@ -1136,6 +1209,8 @@ class vmmAddHardware(vmmGObjectUI):
             return _("Random Number Generator")
         if page == PAGE_PANIC:
             return _("Panic Notifier")
+        if page == PAGE_CONTROLLER:
+            return _("Controller")
 
         if page == PAGE_CHAR:
             char_class = self.get_char_type()
@@ -1397,6 +1472,8 @@ class vmmAddHardware(vmmGObjectUI):
             return self.validate_page_rng()
         elif page_num == PAGE_PANIC:
             return self.validate_page_panic()
+        elif page_num == PAGE_CONTROLLER:
+            return self.validate_page_controller()
 
     def validate(self, page_num):
         ret = self._validate(page_num)
@@ -1724,6 +1801,24 @@ class vmmAddHardware(vmmGObjectUI):
         except Exception, e:
             return self.err.val_err(_("Panic device parameter error"), e)
 
+    def validate_page_controller(self):
+        conn = self.conn.get_backend()
+        self._dev = VirtualController(conn)
+
+        controller_type = self.get_config_controller_type()
+        model = self.get_config_controller_model()
+
+        controllers = self.vm.get_controller_devices()
+        controller_num = [x for x in controllers if
+                (x.type == controller_type)]
+        if len(controller_num) > 0:
+            index_new = max([x.index for x in controller_num]) + 1
+            setattr(self._dev, "index", index_new)
+
+        setattr(self._dev, "type", controller_type)
+        if model != "none":
+            setattr(self._dev, "model", model)
+
     def validate_page_rng(self):
         conn = virtinst.VirtualRNGDevice.BACKEND_MODE_CONNECT in \
                self.get_config_rng_backend_mode()
-- 
1.8.5.3




More information about the virt-tools-list mailing list