VirTips wind between the clouds

Tag Archives: Libvirt

Reseting, restarting or rebooting virtual machine

Libvirt gives you a several ways to reboot virtual machine:

  • reboot – by default it sends ACPI request to VM. It can be ignored(acpid daemon required in vm)
  • reset – emulates the power reset button on a machine
  • send ctrl-alt-del keys

Some examples in python:
Reboot

Reset:

Send ctrl-alt-del:

 

Get network stats for virtual machine

It retunrs values in bytes.

Read more about interfaceStats in libvirt C API docs.

Getting disk space usage from running VM.

There is amazing tool which may help in many administrative tasks. It is called libguestfs. To get information about disk space usage you can use program virt-df.
To get disks stats from all running vms just run(libvirt required):

To get disks stats from specific vm:

If you do not have libvirt, you can manually specify disk

Libguestfs is mainly written in C, but it provides bindings for other languages : C++, Erlang, Java, OCaml, Perl, Python, Ruby.
For example to get  disk stats in python you can use this code:

 

Attaching disk via libvirt using python

In VM load modules acpiphp, pci_hotplug. Read more on KVM site

Changing qemu VNC password via libvirt using python

 

Follow

Get every new post delivered to your Inbox

Join other followers