[virt-tools-list] [PATCH 2/4] addhardware: fix adding and removing a channel device

Marc-André Lureau marcandre.lureau at redhat.com
Mon Apr 4 23:35:32 UTC 2011


---
 src/virtManager/addhardware.py |   37 ++++++++++++++++++++++++-------------
 src/virtManager/details.py     |    2 +-
 src/virtManager/domain.py      |    4 +++-
 3 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/src/virtManager/addhardware.py b/src/virtManager/addhardware.py
index 91ece33..b856318 100644
--- a/src/virtManager/addhardware.py
+++ b/src/virtManager/addhardware.py
@@ -286,19 +286,6 @@ class vmmAddHardware(vmmGObjectUI):
         video_dev = self.window.get_widget("video-model")
         uihelpers.build_video_combo(self.vm, video_dev)
 
-        # Char device type
-        char_devtype = self.window.get_widget("char-device-type")
-        # Type name, desc
-        char_devtype_model = gtk.ListStore(str, str)
-        char_devtype.set_model(char_devtype_model)
-        text = gtk.CellRendererText()
-        char_devtype.pack_start(text, True)
-        char_devtype.add_attribute(text, 'text', 1)
-        for t in VirtualCharDevice.char_types:
-            desc = VirtualCharDevice.get_char_type_desc(t)
-            row = [t, desc + " (%s)" % t]
-            char_devtype_model.append(row)
-
         # Character dev mode
         char_mode = self.window.get_widget("char-mode")
         # Mode name, desc
@@ -358,6 +345,10 @@ class vmmAddHardware(vmmGObjectUI):
                       self.vm.is_hvm(),
                       _("Not supported for this guest type."),
                       "parallel")
+        add_hw_option("Channel", gtk.STOCK_CONNECT, PAGE_CHAR,
+                      self.vm.is_hvm(),
+                      _("Not supported for this guest type."),
+                      "channel")
         add_hw_option("USB Host Device", "system-run", PAGE_HOSTDEV,
                       self.vm.get_connection().is_nodedev_capable(),
                       _("Connection does not support host device enumeration"),
@@ -688,6 +679,23 @@ class vmmAddHardware(vmmGObjectUI):
     def get_hw_selection(self):
         return get_list_selection(self.window.get_widget("hardware-list"))
 
+    def update_char_device_type_model(self):
+        # Char device type
+        char_devtype = self.window.get_widget("char-device-type")
+        dev_type = self.get_char_type()
+        # Type name, desc
+        char_devtype_model = gtk.ListStore(str, str)
+        char_devtype.clear()
+        char_devtype.set_model(char_devtype_model)
+        text = gtk.CellRendererText()
+        char_devtype.pack_start(text, True)
+        char_devtype.add_attribute(text, 'text', 1)
+        for t in VirtualCharDevice.char_types_for_dev_type[dev_type]:
+            desc = VirtualCharDevice.get_char_type_desc(t)
+            row = [t, desc + " (%s)" % t]
+            char_devtype_model.append(row)
+        char_devtype.set_active(0)
+
     def hw_selected(self, src=None):
         ignore = src
         self._dev = None
@@ -707,6 +715,7 @@ class vmmAddHardware(vmmGObjectUI):
             self.window.get_widget("hardware-info").set_text(msg)
 
         if page == PAGE_CHAR:
+            self.update_char_device_type_model()
             devtype = self.window.get_widget("char-device-type")
             self.change_char_device_type(devtype)
 
@@ -814,6 +823,8 @@ class vmmAddHardware(vmmGObjectUI):
 
         if label == "parallel":
             return VirtualDevice.VIRTUAL_DEV_PARALLEL
+        elif label == "channel":
+            return VirtualDevice.VIRTUAL_DEV_CHANNEL
         return VirtualDevice.VIRTUAL_DEV_SERIAL
 
     def dev_to_title(self, page):
diff --git a/src/virtManager/details.py b/src/virtManager/details.py
index 69e2b1a..ca21c2d 100644
--- a/src/virtManager/details.py
+++ b/src/virtManager/details.py
@@ -2752,7 +2752,7 @@ class vmmDetails(vmmGObjectUI):
             port = chardev.target_port
 
             label = devtype.capitalize()
-            if devtype != "console":
+            if devtype not in ["console", "channel"]:
                 # Don't show port for console
                 label += " %s" % (int(port) + 1)
 
diff --git a/src/virtManager/domain.py b/src/virtManager/domain.py
index 9730233..7fc66ed 100644
--- a/src/virtManager/domain.py
+++ b/src/virtManager/domain.py
@@ -46,6 +46,7 @@ def compare_device(origdev, newdev, idx):
         "console"   : ["char_type", "target_type", "target_port"],
         "graphics"  : ["type", "vmmindex"],
         "controller" : ["type", "index"],
+        "channel"   : ["char_type", "target_name"],
     }
 
     if id(origdev) == id(newdev):
@@ -713,8 +714,9 @@ class vmmDomainBase(vmmLibvirtObject):
         serials     = self._build_device_list("serial")
         parallels   = self._build_device_list("parallel")
         consoles    = self._build_device_list("console")
+        channels    = self._build_device_list("channel")
 
-        for devicelist in [serials, parallels, consoles]:
+        for devicelist in [serials, parallels, consoles, channels]:
             devs.extend(devicelist)
 
         # Don't display <console> if it's just a duplicate of <serial>
-- 
1.7.4




More information about the virt-tools-list mailing list