3957d80
# HG changeset patch
3957d80
# User Cole Robinson <crobinso@redhat.com>
3957d80
# Date 1251727555 14400
3957d80
# Node ID c0de24094ca26b8da900d29746adba056f4114f7
3957d80
# Parent  37a986ce54ceac389573d763c78f633a10ec1ab7
3957d80
Don't mangle QEMU driver name on cdrom connect (bz 516116)
3957d80
3957d80
diff -r 37a986ce54ce -r c0de24094ca2 src/virtManager/domain.py
3957d80
--- a/src/virtManager/domain.py	Thu Aug 27 11:07:35 2009 -0400
3957d80
+++ b/src/virtManager/domain.py	Mon Aug 31 10:05:55 2009 -0400
3957d80
@@ -1291,19 +1291,28 @@
3957d80
         xml = self.get_device_xml("disk", dev_id_info)
3957d80
 
3957d80
         def cdrom_xml_connect(doc, ctx):
3957d80
-            disk_fragment = ctx.xpathEval("/disk")
3957d80
+            disk_fragment = ctx.xpathEval("/disk")[0]
3957d80
             driver_fragment = ctx.xpathEval("/disk/driver")
3957d80
-            disk_fragment[0].setProp("type", _type)
3957d80
-            elem = disk_fragment[0].newChild(None, "source", None)
3957d80
+            disk_fragment.setProp("type", _type)
3957d80
+            elem = disk_fragment.newChild(None, "source", None)
3957d80
+
3957d80
             if _type == "file":
3957d80
                 elem.setProp("file", source)
3957d80
-                if driver_fragment:
3957d80
-                    driver_fragment[0].setProp("name", _type)
3957d80
+                driver_name = _type
3957d80
             else:
3957d80
                 elem.setProp("dev", source)
3957d80
-                if driver_fragment:
3957d80
-                    driver_fragment[0].setProp("name", "phy")
3957d80
-            return disk_fragment[0].serialize()
3957d80
+                driver_name = "phy"
3957d80
+
3957d80
+            if driver_fragment:
3957d80
+                driver_fragment = driver_fragment[0]
3957d80
+                orig_name = driver_fragment.prop("name")
3957d80
+
3957d80
+                # For Xen, the driver name is dependent on the storage type
3957d80
+                # (file or phys).
3957d80
+                if orig_name and orig_name in [ "file", "phy" ]:
3957d80
+                    driver_fragment.setProp("name", driver_name)
3957d80
+
3957d80
+            return disk_fragment.serialize()
3957d80
 
3957d80
         result = util.xml_parse_wrapper(xml, cdrom_xml_connect)
3957d80
         logging.debug("connect_cdrom produced: %s" % result)
3957d80
@@ -1313,17 +1322,19 @@
3957d80
         xml = self.get_device_xml("disk", dev_id_info)
3957d80
 
3957d80
         def cdrom_xml_disconnect(doc, ctx):
3957d80
-            disk_fragment = ctx.xpathEval("/disk")
3957d80
+            disk_fragment = ctx.xpathEval("/disk")[0]
3957d80
             sourcenode = None
3957d80
-            for child in disk_fragment[0].children:
3957d80
+
3957d80
+            for child in disk_fragment.children:
3957d80
                 if child.name == "source":
3957d80
                     sourcenode = child
3957d80
                     break
3957d80
                 else:
3957d80
                     continue
3957d80
+
3957d80
             sourcenode.unlinkNode()
3957d80
             sourcenode.freeNode()
3957d80
-            return disk_fragment[0].serialize()
3957d80
+            return disk_fragment.serialize()
3957d80
 
3957d80
         result = util.xml_parse_wrapper(xml, cdrom_xml_disconnect)
3957d80
         logging.debug("eject_cdrom produced: %s" % result)