[virt-tools-list] [PATCH 2/3] virt-manager: Add redirected devices details

Marc-André Lureau marcandre.lureau at gmail.com
Fri Sep 2 01:23:27 UTC 2011


---
 src/virtManager/details.py   |   53 ++++++++++-
 src/virtManager/domain.py    |    3 +
 src/virtManager/uihelpers.py |   19 ++++
 src/vmm-details.glade        |  224 +++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 295 insertions(+), 4 deletions(-)

diff --git a/src/virtManager/details.py b/src/virtManager/details.py
index 1858af8..9b53901 100644
--- a/src/virtManager/details.py
+++ b/src/virtManager/details.py
@@ -111,12 +111,14 @@ HW_LIST_TYPE_WATCHDOG = 13
 HW_LIST_TYPE_CONTROLLER = 14
 HW_LIST_TYPE_FILESYSTEM = 15
 HW_LIST_TYPE_SMARTCARD = 16
+HW_LIST_TYPE_REDIRDEV = 17
 
 remove_pages = [HW_LIST_TYPE_NIC, HW_LIST_TYPE_INPUT,
                 HW_LIST_TYPE_GRAPHICS, HW_LIST_TYPE_SOUND, HW_LIST_TYPE_CHAR,
                 HW_LIST_TYPE_HOSTDEV, HW_LIST_TYPE_DISK, HW_LIST_TYPE_VIDEO,
                 HW_LIST_TYPE_WATCHDOG, HW_LIST_TYPE_CONTROLLER,
-                HW_LIST_TYPE_FILESYSTEM, HW_LIST_TYPE_SMARTCARD]
+                HW_LIST_TYPE_FILESYSTEM, HW_LIST_TYPE_SMARTCARD,
+                HW_LIST_TYPE_REDIRDEV]
 
 # Boot device columns
 BOOT_DEV_TYPE = 0
@@ -172,6 +174,24 @@ def prettyify_bytes(val):
     else:
         return "%2.2f MB" % (val / (1024.0 * 1024.0))
 
+def build_redir_label(redirdev):
+    # String shown in the devices details section
+    addrlabel = ""
+    # String shown in the VMs hardware list
+    hwlabel = ""
+
+    if redirdev.type == 'spicevmc':
+        addrlabel = None
+    elif redirdev.type == 'tcp':
+        addrlabel += _("%s:%s") % (redirdev.host, redirdev.service)
+    else:
+        raise RuntimeError("unhandled redirection kind: %s" % redirdev.type)
+
+    hwlabel = _("Redirected %s") % redirdev.bus.upper()
+
+    return addrlabel, hwlabel
+
+
 def build_hostdev_label(hostdev):
     # String shown in the devices details section
     srclabel = ""
@@ -913,6 +933,10 @@ class vmmDetails(vmmGObjectUI):
         sc_mode = self.widget("smartcard-mode-combo")
         uihelpers.build_smartcard_mode_combo(self.vm, sc_mode)
 
+        # Redirection type
+        combo = self.widget("redir-type-combo")
+        uihelpers.build_redir_type_combo(self.vm, combo)
+
     # 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="",
@@ -1218,6 +1242,8 @@ class vmmDetails(vmmGObjectUI):
                 self.refresh_filesystem_page()
             elif pagetype == HW_LIST_TYPE_SMARTCARD:
                 self.refresh_smartcard_page()
+            elif pagetype == HW_LIST_TYPE_REDIRDEV:
+                self.refresh_redir_page()
             else:
                 pagetype = -1
         except Exception, e:
@@ -2906,6 +2932,20 @@ class vmmDetails(vmmGObjectUI):
 
         self.set_combo_label("smartcard-mode", sc.mode)
 
+    def refresh_redir_page(self):
+        rd = self.get_hw_selection(HW_LIST_COL_DEVICE)
+        if not rd:
+            return
+
+        address = build_redir_label(rd)[0] or "-"
+
+        devlabel = "<b>Redirected %s Device</b>" % rd.bus.upper()
+        self.widget("redir-title").set_markup(devlabel)
+        self.widget("redir-address").set_text(address)
+
+        self.widget("redir-type-label").set_text(rd.type)
+        self.widget("redir-type-combo").hide()
+
     def refresh_char_page(self):
         chardev = self.get_hw_selection(HW_LIST_COL_DEVICE)
         if not chardev:
@@ -3262,6 +3302,17 @@ class vmmDetails(vmmGObjectUI):
                 icon = "device_pci"
             update_hwlist(HW_LIST_TYPE_HOSTDEV, hostdev, label, icon)
 
+        # Populate redir devices
+        for redirdev in self.vm.get_redirdev_devices():
+            bus = redirdev.bus
+            label = build_redir_label(redirdev)[1]
+
+            if bus == "usb":
+                icon = "device_usb"
+            else:
+                icon = "device_pci"
+            update_hwlist(HW_LIST_TYPE_REDIRDEV, redirdev, label, icon)
+
         # Populate video devices
         for vid in self.vm.get_video_devices():
             update_hwlist(HW_LIST_TYPE_VIDEO, vid, _("Video"), "video-display")
diff --git a/src/virtManager/domain.py b/src/virtManager/domain.py
index 679dfc4..6921dac 100644
--- a/src/virtManager/domain.py
+++ b/src/virtManager/domain.py
@@ -51,6 +51,7 @@ def compare_device(origdev, newdev, idx):
         "channel"   : ["char_type", "target_name"],
         "filesystem" : ["target" , "vmmindex"],
         "smartcard" : ["mode" , "vmmindex"],
+        "redirdev" : ["bus" , "type", "vmmindex"],
     }
 
     if id(origdev) == id(newdev):
@@ -943,6 +944,8 @@ class vmmDomain(vmmLibvirtObject):
         return self._build_device_list("filesystem")
     def get_smartcard_devices(self):
         return self._build_device_list("smartcard")
+    def get_redirdev_devices(self):
+        return self._build_device_list("redirdev")
 
     def get_disk_devices(self, refresh_if_necc=True, inactive=False):
         devs = self._build_device_list("disk", refresh_if_necc, inactive)
diff --git a/src/virtManager/uihelpers.py b/src/virtManager/uihelpers.py
index 9f9c950..65693e0 100644
--- a/src/virtManager/uihelpers.py
+++ b/src/virtManager/uihelpers.py
@@ -270,6 +270,25 @@ def populate_smartcard_mode_combo(vm, combo):
 # TODO
 #    model.append(["host-certificates", "Host Certificates"])
 
+def build_redir_type_combo(vm, combo):
+    source_mode = gtk.ListStore(str, str, bool)
+    combo.set_model(source_mode)
+    text = gtk.CellRendererText()
+    combo.pack_start(text, True)
+    combo.add_attribute(text, 'text', 1)
+
+    populate_redir_type_combo(vm, combo)
+    combo.set_active(0)
+
+def populate_redir_type_combo(vm, combo):
+    ignore = vm
+    model = combo.get_model()
+    model.clear()
+
+    # [xml value, label, conn details]
+    model.append(["spicevmc", "Spice channel", False])
+    model.append(["tcp", "TCP", True])
+
 def build_netmodel_combo(vm, combo):
     dev_model = gtk.ListStore(str, str)
     combo.set_model(dev_model)
diff --git a/src/vmm-details.glade b/src/vmm-details.glade
index 8ab386b..de46cc3 100644
--- a/src/vmm-details.glade
+++ b/src/vmm-details.glade
@@ -5876,20 +5876,238 @@ I/O:</property>
                                 </child>
                               </widget>
                               <packing>
-                                <property name="position">9</property>
+                                <property name="position">16</property>
                               </packing>
                             </child>
                             <child>
                               <widget class="GtkLabel" id="label76">
                                 <property name="visible">True</property>
-                                <property name="label">snd</property>
+                                <property name="label">sc</property>
                               </widget>
                               <packing>
-                                <property name="position">9</property>
+                                <property name="position">16</property>
+                                <property name="tab_fill">False</property>
+                                <property name="type">tab</property>
+                              </packing>
+                            </child>
+
+                            <child>
+                              <widget class="GtkFrame" id="frame19">
+                                <property name="visible">True</property>
+                                <property name="label_xalign">0</property>
+                                <property name="label_yalign">0.5</property>
+                                <property name="shadow_type">none</property>
+
+                                <child>
+                                  <widget class="GtkAlignment" id="alignment161">
+                                    <property name="visible">True</property>
+                                    <property name="xalign">0.5</property>
+                                    <property name="yalign">0.5</property>
+                                    <property name="xscale">1</property>
+                                    <property name="yscale">1</property>
+                                    <property name="top_padding">3</property>
+                                    <property name="bottom_padding">0</property>
+                                    <property name="left_padding">12</property>
+                                    <property name="right_padding">0</property>
+
+                                    <child>
+                                      <widget class="GtkTable" id="table51">
+                                        <property name="border_width">3</property>
+                                        <property name="visible">True</property>
+                                        <property name="n_rows">2</property>
+                                        <property name="n_columns">2</property>
+                                        <property name="homogeneous">False</property>
+                                        <property name="row_spacing">4</property>
+                                        <property name="column_spacing">8</property>
+
+                                        <child>
+
+                                          <widget class="GtkLabel" id="label516">
+                                            <property name="visible">True</property>
+                                            <property name="label" translatable="yes">T_ype:</property>
+                                            <property name="use_underline">True</property>
+                                            <property name="use_markup">False</property>
+                                            <property name="justify">GTK_JUSTIFY_LEFT</property>
+                                            <property name="wrap">False</property>
+                                            <property name="selectable">False</property>
+                                            <property name="xalign">0</property>
+                                            <property name="yalign">0.5</property>
+                                            <property name="xpad">0</property>
+                                            <property name="ypad">0</property>
+                                            <property name="mnemonic_widget">redir-type-combo</property>
+                                            <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+                                            <property name="width_chars">-1</property>
+                                            <property name="single_line_mode">False</property>
+                                            <property name="angle">0</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="left_attach">0</property>
+                                            <property name="right_attach">1</property>
+                                            <property name="top_attach">0</property>
+                                            <property name="bottom_attach">1</property>
+                                            <property name="x_options"></property>
+                                            <property name="y_options"></property>
+                                          </packing>
+                                        </child>
+
+                                        <child>
+                                          <widget class="GtkHBox" id="hbox1125">
+                                            <property name="visible">True</property>
+                                            <property name="homogeneous">False</property>
+                                            <property name="spacing">0</property>
+
+                                            <child>
+                                              <widget class="GtkComboBox" id="redir-type-combo">
+                                                <property name="visible">True</property>
+                                                <property name="add_tearoffs">False</property>
+                                                <property name="focus_on_click">True</property>
+                                              </widget>
+                                              <packing>
+                                                <property name="padding">0</property>
+                                                <property name="expand">True</property>
+                                                <property name="fill">True</property>
+                                              </packing>
+                                            </child>
+
+                                            <child>
+                                              <widget class="GtkLabel" id="redir-type-label">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">True</property>
+                                                <property name="label">redir type</property>
+                                                <property name="use_underline">False</property>
+                                                <property name="use_markup">False</property>
+                                                <property name="justify">GTK_JUSTIFY_LEFT</property>
+                                                <property name="wrap">False</property>
+                                                <property name="selectable">True</property>
+                                                <property name="xalign">0</property>
+                                                <property name="yalign">0.5</property>
+                                                <property name="xpad">1</property>
+                                                <property name="ypad">0</property>
+                                                <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+                                                <property name="width_chars">-1</property>
+                                                <property name="single_line_mode">False</property>
+                                                <property name="angle">0</property>
+                                              </widget>
+                                              <packing>
+                                                <property name="padding">0</property>
+                                                <property name="expand">True</property>
+                                                <property name="fill">True</property>
+                                              </packing>
+                                            </child>
+                                          </widget>
+                                          <packing>
+                                            <property name="left_attach">1</property>
+                                            <property name="right_attach">2</property>
+                                            <property name="top_attach">0</property>
+                                            <property name="bottom_attach">1</property>
+                                            <property name="y_padding">1</property>
+                                            <property name="x_options"></property>
+                                            <property name="y_options"></property>
+                                          </packing>
+                                        </child>
+
+                                        <child>
+                                          <widget class="GtkLabel" id="label519">
+                                            <property name="visible">True</property>
+                                            <property name="label" translatable="yes">Address:</property>
+                                            <property name="use_underline">False</property>
+                                            <property name="use_markup">False</property>
+                                            <property name="justify">GTK_JUSTIFY_LEFT</property>
+                                            <property name="wrap">False</property>
+                                            <property name="selectable">False</property>
+                                            <property name="xalign">0</property>
+                                            <property name="yalign">0.5</property>
+                                            <property name="xpad">0</property>
+                                            <property name="ypad">0</property>
+                                            <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+                                            <property name="width_chars">-1</property>
+                                            <property name="single_line_mode">False</property>
+                                            <property name="angle">0</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="left_attach">0</property>
+                                            <property name="right_attach">1</property>
+                                            <property name="top_attach">1</property>
+                                            <property name="bottom_attach">2</property>
+                                            <property name="x_options">fill</property>
+                                            <property name="y_options"></property>
+                                          </packing>
+                                        </child>
+
+                                        <child>
+                                          <widget class="GtkLabel" id="redir-address">
+                                            <property name="visible">True</property>
+                                            <property name="label" translatable="yes">foo:12</property>
+                                            <property name="use_underline">False</property>
+                                            <property name="use_markup">False</property>
+                                            <property name="justify">GTK_JUSTIFY_LEFT</property>
+                                            <property name="wrap">False</property>
+                                            <property name="selectable">False</property>
+                                            <property name="xalign">0</property>
+                                            <property name="yalign">0.5</property>
+                                            <property name="xpad">0</property>
+                                            <property name="ypad">0</property>
+                                            <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+                                            <property name="width_chars">-1</property>
+                                            <property name="single_line_mode">False</property>
+                                            <property name="angle">0</property>
+                                          </widget>
+                                          <packing>
+                                            <property name="left_attach">1</property>
+                                            <property name="right_attach">2</property>
+                                            <property name="top_attach">1</property>
+                                            <property name="bottom_attach">2</property>
+                                            <property name="x_options">fill</property>
+                                            <property name="y_options"></property>
+                                          </packing>
+                                        </child>
+                                      </widget>
+                                    </child>
+                                  </widget>
+                                </child>
+
+                                <child>
+                                  <widget class="GtkLabel" id="redir-title">
+                                    <property name="visible">True</property>
+                                    <property name="label" translatable="yes"><b>Redirected device</b></property>
+                                    <property name="use_underline">False</property>
+                                    <property name="use_markup">True</property>
+                                    <property name="justify">GTK_JUSTIFY_LEFT</property>
+                                    <property name="wrap">False</property>
+                                    <property name="selectable">False</property>
+                                    <property name="xalign">0.5</property>
+                                    <property name="yalign">0.5</property>
+                                    <property name="xpad">0</property>
+                                    <property name="ypad">0</property>
+                                    <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+                                    <property name="width_chars">-1</property>
+                                    <property name="single_line_mode">False</property>
+                                    <property name="angle">0</property>
+                                  </widget>
+                                  <packing>
+                                    <property name="type">label_item</property>
+                                  </packing>
+                                </child>
+                              </widget>
+                              <packing>
+                                <property name="position">17</property>
+                                <property name="tab_expand">False</property>
+                                <property name="tab_fill">True</property>
+                              </packing>
+                            </child>
+
+                            <child>
+                              <widget class="GtkLabel" id="label515">
+                                <property name="visible">True</property>
+                                <property name="label">rd</property>
+                              </widget>
+                              <packing>
+                                <property name="position">17</property>
                                 <property name="tab_fill">False</property>
                                 <property name="type">tab</property>
                               </packing>
                             </child>
+
                           </widget>
                         </child>
                       </widget>
-- 
1.7.6




More information about the virt-tools-list mailing list