O'Reilly logo

KVM Virtualization Cookbook by Konstantin Ivanov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

To define a new KVM instance, using the Python libvirt module follow these instructions:

  1. In the iPython interpreter, import the libvirt module:
In [1]: import libvirtIn [2]:
  1. Create the instance definition string:
In [2]: xmlconfig = """<domain type='kvm' id='1'> <name>kvm_python</name> <memory unit='KiB'>1048576</memory> <currentMemory unit='KiB'>1048576</currentMemory> <vcpu placement='static'>1</vcpu> <resource>   <partition>/machine</partition> </resource> <os>   <type arch='x86_64' machine='pc-i440fx-trusty'>hvm</type>   <boot dev='hd'/> </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/bin/qemu-system-x86_64</emulator> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required