KVM api to run a virtual machine

I was wondering if there is a KVM API that allows you to start the KVM virtual machine using a simple command from a python script.

My Python script performs a series of checks to find out if we need to run a specific virtual machine, and I would like to start a virtual machine if I need to.

Now I need to find the API calls, but I cannot find a simple call to launch them on the libvirt website. Does anyone know if this is possible?

+5
source share
4 answers

You can use the create () function from the python libvirt API bindings:

import libvirt

#connect to hypervisor running on localhost
conn = libvirt.open('qemu:///system')

dom0 = conn.lookupByName('my-vm-1')
dom0.create()

basically the python API is the C API called by libvirt.C_API_CALL minus the virConnect part or conn.C_API_CALL minus the virDomain part.

. API libvirt .

+8

, , , - os.system python qemu-kvm. , .

libvirt, , virt-install.

virt-install \
         --connect qemu:///system \
         --virt-type kvm \
         --name MyNewVM \
         --ram 512 \
         --disk path=/var/lib/libvirt/images/MyNewVM.img,size=8 \
         --vnc \
         --cdrom /var/lib/libvirt/images/Fedora-14-x86_64-Live-KDE.iso \
         --network network=default,mac=52:54:00:9c:94:3b \
         --os-variant fedora14

http://wiki.libvirt.org/page/VM_lifecycle

virsh start MyNewVM . , .

+2

, libvirt [qemu-] kvm pythonistas. , kvmtools: http://www.linux-kvm.org/page/Kvmtools (../kvmtools/kvm/build_command.py kvm_boot_action./kvmtools/kvm/action.py, subprocess os.system)

0

virsh, KVM. virsh;

,

virsh, , .

if you use a python script to control you KVM, I would suggest going through the following script. this will give you a good idea. http://russell.ballestrini.net/series/virt-back/

0
source

All Articles