Esempio n. 1
0
def mac_from_vm(vm: libvirt.virDomain = None) -> str:
    """
    Parses the vm's XML to return just the mac address as a string
    """
    doc = minidom.parseString(vm.XMLDesc())
    interfaces = doc.getElementsByTagName('mac')
    return interfaces[0].getAttribute('address')
Esempio n. 2
0
def backup_vm_def(dom: libvirt.virDomain, tar:tarfileProg.TarFile):
    printNoNL("Writing backup of vm definition. ")
    _, xmlFile_path = tempfile.mkstemp(suffix=".xml", prefix="backup_vm_def_")
    xmlFile = open(xmlFile_path, 'w')
    xmlFile.write(dom.XMLDesc())
    xmlFile.close()
    tar.add(xmlFile_path, arcname=os.path.join(backup_name,"vm-def.xml"))
    os.remove(xmlFile_path)
    print("Done.")
Esempio n. 3
0
def domain_vnc_server(domain: libvirt.virDomain) -> str:
    etree = ElementTree.fromstring(domain.XMLDesc())

    vnc = etree.find('.//graphics[@type="vnc"]')
    if vnc is None:
        raise RuntimeError("No VNC connection found for the given domain")

    if 'socket' in vnc.keys():
        return vnc.get('socket')
    elif {'listen', 'port'} <= set(vnc.keys()):
        return '::'.join((vnc.get('listen'), vnc.get('port')))
    else:
        raise RuntimeError("No valid VNC connection found for the given domain")