def attach_iso(self, name, iso):
        (dom, host) = self.get_active_domain(name)
        if not dom:
            dom = self.get_inactive_domain(name)
            host = dom["host"]

        for x in self.hosts:
            if host == x["name"]:
                conn = x["conn"]

        dom = conn.lookupByName(name)

        cdrom = None
        desc = fromstring(dom.XMLDesc(libvirt.VIR_DOMAIN_XML_SECURE))
        for disk in desc.findall(".//disk"):
            if disk.get("device") == "cdrom":
                cdrom = disk
                if cdrom.find(".//source"):
                    cdrom.find(".//source").set("file", iso)
                else:
                    desc.find(".//devices").remove(cdrom)
                    cdrom = None

        if not cdrom:
            xml = """
<disk type="file" device="cdrom">
  <driver name="qemu"/>
  <source file="%s" />
  <target dev="hdc" bus="ide"/>
  <readonly/>
</disk>
   """
        xml = xml % (iso)
        desc.find(".//devices").insert(-1, fromstring(xml))
        conn.defineXML(tostring(desc))
        return True
dataset/ETHPy150Open mizzy/maglica/maglica/virt.py/Virt.attach_iso/original