

def attach_iso(self, name, iso):
    (dom, host) = self.get_active_domain(name)
    if (not name):
        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 = '\n<disk type="file" device="cdrom">\n  <driver name="qemu"/>\n  <source file="%s" />\n  <target dev="hdc" bus="ide"/>\n  <readonly/>\n</disk>\n   '
    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/VarMisuse@30/34 `dom`->`name`