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...

The following steps describe how to install the bottle module and the simple RESTfull API server written in Python:

  1. Install the bottle module:
(kvm_python) root@kvm:~/kvm_python# pip install bottleCollecting bottle... Downloading bottle-0.12.13.tar.gz (70kB) 100% |████████████████████████████████| 71kB 4.5MB/s...Successfully installed bottle-0.12.13(kvm_python) root@kvm:~/kvm_python#
  1. Create a new file, import the libvirt and bottle modules and write the libvirt connection method:
(kvm_python) root@kvm:~/kvm_python# vim kvm_api.pyimport libvirtfrom bottle import run, request, get, post, HTTPResponsedef libvirtConnect():  try:    conn = libvirt.open('qemu:///system')  except libvirt.libvirtError:    conn = None  return conn

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