[virt-tools-list] [virt-manager PATCH 2/4] addhardware: add controller UI

Chen Hanxiao chenhanxiao at cn.fujitsu.com
Wed Apr 16 09:51:50 UTC 2014


This patch will enable adding controller
without model.

Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
---
 ui/addhardware.ui          | 137 ++++++++++++++++++++++++++++++++++++---------
 virtManager/addhardware.py |  76 ++++++++++++++++++++++++-
 2 files changed, 184 insertions(+), 29 deletions(-)

diff --git a/ui/addhardware.ui b/ui/addhardware.ui
index 4fc82fe..97d03c0 100644
--- a/ui/addhardware.ui
+++ b/ui/addhardware.ui
@@ -327,6 +327,83 @@
                           </packing>
                         </child>
                         <child>
+                          <object class="GtkGrid" id="grid5">
+                            <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="label29">
+                                <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="controller-model-label">
+                                <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">2</property>
+                          </packing>
+                        </child>
+                        <child type="tab">
+                          <object class="GtkLabel" id="label24">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="label" translatable="yes">Controller</property>
+                          </object>
+                          <packing>
+                            <property name="position">2</property>
+                            <property name="tab_fill">False</property>
+                          </packing>
+                        </child>
+                        <child>
                           <object class="GtkBox" id="box2">
                             <property name="visible">True</property>
                             <property name="can_focus">False</property>
@@ -491,7 +568,7 @@
                             </child>
                           </object>
                           <packing>
-                            <property name="position">2</property>
+                            <property name="position">3</property>
                           </packing>
                         </child>
                         <child type="tab">
@@ -501,7 +578,7 @@
                             <property name="label">net</property>
                           </object>
                           <packing>
-                            <property name="position">2</property>
+                            <property name="position">3</property>
                             <property name="tab_fill">False</property>
                           </packing>
                         </child>
@@ -539,7 +616,7 @@
                             </child>
                           </object>
                           <packing>
-                            <property name="position">3</property>
+                            <property name="position">4</property>
                           </packing>
                         </child>
                         <child type="tab">
@@ -549,7 +626,7 @@
                             <property name="label">input</property>
                           </object>
                           <packing>
-                            <property name="position">3</property>
+                            <property name="position">4</property>
                             <property name="tab_fill">False</property>
                           </packing>
                         </child>
@@ -562,7 +639,7 @@
                             </child>
                           </object>
                           <packing>
-                            <property name="position">4</property>
+                            <property name="position">5</property>
                           </packing>
                         </child>
                         <child type="tab">
@@ -572,7 +649,7 @@
                             <property name="label">gfx</property>
                           </object>
                           <packing>
-                            <property name="position">4</property>
+                            <property name="position">5</property>
                             <property name="tab_fill">False</property>
                           </packing>
                         </child>
@@ -611,7 +688,7 @@
                             </child>
                           </object>
                           <packing>
-                            <property name="position">5</property>
+                            <property name="position">6</property>
                           </packing>
                         </child>
                         <child type="tab">
@@ -621,7 +698,7 @@
                             <property name="label">sound</property>
                           </object>
                           <packing>
-                            <property name="position">5</property>
+                            <property name="position">6</property>
                             <property name="tab_fill">False</property>
                           </packing>
                         </child>
@@ -671,7 +748,7 @@
                             </child>
                           </object>
                           <packing>
-                            <property name="position">6</property>
+                            <property name="position">7</property>
                           </packing>
                         </child>
                         <child type="tab">
@@ -681,7 +758,7 @@
                             <property name="label">host</property>
                           </object>
                           <packing>
-                            <property name="position">6</property>
+                            <property name="position">7</property>
                             <property name="tab_fill">False</property>
                           </packing>
                         </child>
@@ -1050,6 +1127,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,11 +1139,13 @@
                               <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>
                           <packing>
-                            <property name="position">7</property>
+                            <property name="position">8</property>
                           </packing>
                         </child>
                         <child type="tab">
@@ -1074,7 +1155,7 @@
                             <property name="label">char</property>
                           </object>
                           <packing>
-                            <property name="position">7</property>
+                            <property name="position">8</property>
                             <property name="tab_fill">False</property>
                           </packing>
                         </child>
@@ -1113,7 +1194,7 @@
                             </child>
                           </object>
                           <packing>
-                            <property name="position">8</property>
+                            <property name="position">9</property>
                           </packing>
                         </child>
                         <child type="tab">
@@ -1123,7 +1204,7 @@
                             <property name="label">vid</property>
                           </object>
                           <packing>
-                            <property name="position">8</property>
+                            <property name="position">9</property>
                             <property name="tab_fill">False</property>
                           </packing>
                         </child>
@@ -1192,7 +1273,7 @@
                             </child>
                           </object>
                           <packing>
-                            <property name="position">9</property>
+                            <property name="position">10</property>
                           </packing>
                         </child>
                         <child type="tab">
@@ -1202,7 +1283,7 @@
                             <property name="label">wdog</property>
                           </object>
                           <packing>
-                            <property name="position">9</property>
+                            <property name="position">10</property>
                             <property name="tab_fill">False</property>
                           </packing>
                         </child>
@@ -1216,7 +1297,7 @@
                             </child>
                           </object>
                           <packing>
-                            <property name="position">10</property>
+                            <property name="position">11</property>
                           </packing>
                         </child>
                         <child type="tab">
@@ -1226,7 +1307,7 @@
                             <property name="label">fs</property>
                           </object>
                           <packing>
-                            <property name="position">10</property>
+                            <property name="position">11</property>
                             <property name="tab_fill">False</property>
                           </packing>
                         </child>
@@ -1265,7 +1346,7 @@
                             </child>
                           </object>
                           <packing>
-                            <property name="position">11</property>
+                            <property name="position">12</property>
                           </packing>
                         </child>
                         <child type="tab">
@@ -1275,7 +1356,7 @@
                             <property name="label">sc</property>
                           </object>
                           <packing>
-                            <property name="position">11</property>
+                            <property name="position">12</property>
                             <property name="tab_fill">False</property>
                           </packing>
                         </child>
@@ -1385,7 +1466,7 @@
                             </child>
                           </object>
                           <packing>
-                            <property name="position">12</property>
+                            <property name="position">13</property>
                           </packing>
                         </child>
                         <child type="tab">
@@ -1395,7 +1476,7 @@
                             <property name="label">usbr</property>
                           </object>
                           <packing>
-                            <property name="position">12</property>
+                            <property name="position">13</property>
                             <property name="tab_fill">False</property>
                           </packing>
                         </child>
@@ -1464,7 +1545,7 @@
                             </child>
                           </object>
                           <packing>
-                            <property name="position">13</property>
+                            <property name="position">14</property>
                           </packing>
                         </child>
                         <child type="tab">
@@ -1474,7 +1555,7 @@
                             <property name="label">tpm</property>
                           </object>
                           <packing>
-                            <property name="position">13</property>
+                            <property name="position">14</property>
                             <property name="tab_fill">False</property>
                           </packing>
                         </child>
@@ -1732,7 +1813,7 @@
                             </child>
                           </object>
                           <packing>
-                            <property name="position">14</property>
+                            <property name="position">15</property>
                           </packing>
                         </child>
                         <child type="tab">
@@ -1742,7 +1823,7 @@
                             <property name="label" translatable="yes">rng</property>
                           </object>
                           <packing>
-                            <property name="position">14</property>
+                            <property name="position">15</property>
                             <property name="tab_fill">False</property>
                           </packing>
                         </child>
@@ -1809,7 +1890,7 @@
                             </child>
                           </object>
                           <packing>
-                            <property name="position">15</property>
+                            <property name="position">16</property>
                           </packing>
                         </child>
                         <child type="tab">
@@ -1819,7 +1900,7 @@
                             <property name="label" translatable="yes">panic</property>
                           </object>
                           <packing>
-                            <property name="position">15</property>
+                            <property name="position">16</property>
                             <property name="tab_fill">False</property>
                           </packing>
                         </child>
diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index 39ec63f..b22a339 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -44,6 +44,7 @@ from virtManager.addstorage import vmmAddStorage
 
 (PAGE_ERROR,
 PAGE_DISK,
+PAGE_CONTROLLER,
 PAGE_NETWORK,
 PAGE_INPUT,
 PAGE_GRAPHICS,
@@ -58,7 +59,7 @@ PAGE_USBREDIR,
 PAGE_TPM,
 PAGE_RNG,
 PAGE_PANIC,
-) = range(0, 16)
+) = range(0, 17)
 
 
 class vmmAddHardware(vmmGObjectUI):
@@ -313,6 +314,19 @@ 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)
+        # FIXME: we should deal with controller model
+        combo.set_visible(False)
+        self.widget("controller-model-label").set_visible(False)
+
         # Available HW options
         is_local = not self.conn.is_remote()
         is_storage_capable = self.conn.is_storage_capable()
@@ -332,6 +346,7 @@ class vmmAddHardware(vmmGObjectUI):
 
         add_hw_option("Storage", "drive-harddisk", PAGE_DISK, have_storage,
                       have_storage and storage_tooltip or None)
+        add_hw_option("Controller", "device_pci", PAGE_CONTROLLER, True, None)
         add_hw_option("Network", "network-idle", PAGE_NETWORK, True, None)
         add_hw_option("Input", "input-mouse", PAGE_INPUT, self.vm.is_hvm(),
                       _("Not supported for this guest type."))
@@ -455,6 +470,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)
 
 
@@ -813,6 +831,19 @@ 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:
+            if t == VirtualController.TYPE_PCI:
+                continue
+            model.append([t, VirtualController.pretty_type(t)])
+
+        if len(model) > 0:
+            widget.set_active(0)
+
 
     ########################
     # get_config_* methods #
@@ -880,6 +911,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:
@@ -1008,6 +1046,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 #
     ################
@@ -1113,6 +1158,8 @@ class vmmAddHardware(vmmGObjectUI):
             return _("Error")
         if page == PAGE_DISK:
             return _("Storage")
+        if page == PAGE_CONTROLLER:
+            return _("Controller")
         if page == PAGE_NETWORK:
             return _("Network")
         if page == PAGE_INPUT:
@@ -1370,6 +1417,8 @@ class vmmAddHardware(vmmGObjectUI):
             return True
         elif page_num == PAGE_DISK:
             return self.validate_page_storage()
+        elif page_num == PAGE_CONTROLLER:
+            return self.validate_page_controller()
         elif page_num == PAGE_NETWORK:
             return self.validate_page_network()
         elif page_num == PAGE_INPUT:
@@ -1725,6 +1774,31 @@ 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()
+        controller_type = self.get_config_controller_type()
+        model = self.get_config_controller_model()
+        self._dev = VirtualController(conn)
+        # FIXME
+        model = "none"
+
+        if model == "ich9-ehci1":
+            # FIXME: for USB 2
+            pass
+        else:
+            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":
+                if model == "default":
+                    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.9.0




More information about the virt-tools-list mailing list