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 start the KVM instance that was defined earlier, to obtain its status and finally to stop it, use the following Python code:

  1. Invoke the create() method on the instance object:
In [1]: instance.create()Out[1]: 0In [2]:
  1. Ensure the instance is in a running state by calling the isActive() method on the instance object:
In [2]: instance.isActive()Out[2]: 1In [3]:
  1. Check the status of the KVM instance from the host OS:
(kvm_python) root@kvm:~/kvm_python# virsh list --all Id   Name        State---------------------------------------------------- 5    kvm_python  running(kvm_python) root@kvm:~/kvm_python#
  1. Stop the instance with the destroy() method:
In [3]: instance.destroy()Out[3]: 0In [4]:
  1. Ensure the instance has been destroyed: ...

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