Search code examples
pythonqemukvmlibvirt

Python - libvirt


Is it possible to create a VM from KVM hypervisor using libvirt-python API? I have an iso that I downloaded from a cloud directly. I could not find any example on the internet.

Cheers


Solution

  • sure libvirt-python is designed to do that. You just need to open a connection and call defineXML() with a well formated XML.

    import libvirt
    conn = libvirt.open('qemu+ssh://root@yourhost/system')
    conn.defineXML(imagine_a_well_formated_domain_xml_here)
    

    Now the domain is defined, you can start it:

    dom = conn.lookupByName(the_domain_name)
    dom.create() # start the domain