How it works...

In this recipe, we used a few new methods from the libvirt.virDomain class. Let's see what they do in more detail and then add them to the simple kvm.py Python script we started in the Defining KVM instances with Python recipe.

In steps 1 and 2, we get the name of the KVM instance and ensure it's in a running state.

In step 3, we collect the following instance information, returned as a Python list:

  • state: The state of the instance, as defined in the virDomainState enumerated type at https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainState
  • maxMemory: The maximum memory used by the guest
  • memory: The current amount of memory used by the instance
  • nbVirtCPU: The number of allocated virtual CPUs
  • cpuTime: The time used ...

Get KVM Virtualization Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.