#!/usr/bin/pythonimport libvirtconn = libvirt.open (' Qemu:///system ') xmldesc = ' < Domain type= ' KVM ' ><name>centos_6.5</name><memory unit= ' KiB ' >524288</memory ><currentmemory unit= ' KiB ' >524288</currentmemory><vcpu placement= ' static ' >1< /vcpu><os><type arch= ' x86_64 ' machine= ' rhel6.5.0 ' >hvm</type><boot dev= ' CDROM '/></os><features><acpi/><apic/><pae/></features><clock Offset= ' UTC '/><on_poweroff>destroy</on_poweroff><on_reboot>restart</on_reboot>< on_crash>restart</on_crash><devices><emulator>/usr/libexec/qemu-kvm</emulator>< Disk type= ' file ' device= ' disk ' ><driver name= ' qemu ' type= ' Qcow2 '/><source File= '/home/centos_6.5.qcow2 '/> <--- qemu-img create -f qcow2 /home/centos_6.5.qcow2 10g<target dev= ' HDA ' bus= ' IDE '/></disk><disk type= ' file ' Device= ' cdrom ' ><source file= '/data0/xcloud/iso/centos_6.5_x86_64-minimal.iso '/><target dev= ' hdc ' bus= ' IDE '/></disk><controller type= ' USB ' index= ' 0 ' ><address Type= ' PCI ' domain= ' 0x0000 ' bus= ' 0x00 ' slot= ' 0x01 ' function= ' 0x2 '/></controller> <controller type= ' IDE ' index= ' 0 ' ><address type= ' PCI ' domain= ' 0x0000 ' bus= ' 0x00 ' slot= ' 0x01 ' function= ' 0x1 '/></controller><interface type= ' Bridge ' ><mac address= ' 52:54:00:a7:40:f7 '/><source bridge= ' br0 '/><address type= ' PCI ' domain = ' 0x0000 ' bus= ' 0x00 ' slot= ' 0x03 ' function= ' 0x0 '/></interface><serial type= ' pty ' ><target port= ' 0 '/></serial><console type= ' pty ' ><target type= ' serial ' port= ' 0 '/></console><input type= ' mouse ' bus= ' ps2 '/><graphics type= ' vnc ' port= ' 5905 ' autoport= ' no ' listen= ' 0.0.0.0 ' ><listen type= ' address ' address= ' 0.0.0.0 '/></ Graphics><video><model type= ' Cirrus ' vram= ' 9216 ' heads= ' 1 '/><address Type= ' PCI ' domain= ' 0x0000 ' bus= ' 0x00 ' slot= ' 0x02 ' function= ' 0x0 '/></video>< Memballoon model= ' virtio ' ><address type= ' PCI ' domain= ' 0x0000 ' bus= ' 0x00 ' slot= ' 0x04 ' function= ' 0x0 '/></memballoon></devices></domain> ' dom = Conn.createlinux (xmldesc,0) print "domain:id %d running %s"% (Dom.ID (), Dom. OSType ())
This article from "Muzinan Technology blog" blog, declined reprint!
KVM Creation (python)