Re: [libvirt-users] Managing VMs across multiple physical hosts

William Kern
Mon, 25 Apr 2016 19:15:25 -0000

the libvirt command to see what is running is simply 'virsh list'

so if you have a config tool system like puppet/chef/ansible (or even
remote ssh commands) you can simply send that command to each node.

We use ansible, so a simple on liner would be:

ansible all -i virt_list.ini -m command -a 'virsh list' --sudo

where the file virt_list.ini is the list of VM hosts.

That would output a listing that looks like this

host-b2 | SUCCESS | rc=0 >>
  Id    Name                           State
----------------------------------------------------
  4     vm34                      running
  5     vm42                      running

host-b3 | SUCCESS | rc=0 >>
  Id    Name                           State
----------------------------------------------------
  3     vm2                          running
  5     vm12                         running
  7     vm33                    running

etc.

so you would quickly see whats running where. With a little
grep/awk/perl goodness, it would be trivial to pipe that output into a
DB table that could searched and constantly updated.

The more hardcore ansible guys could make some sort of playbook that
would do the above, but the above shows you the way.

-bill




On 4/24/2016 4:01 PM, Daniel Corbe wrote:
> Hello List,
>
> We’re currently managing VMs across approximately 26 physical hosts.  We
tend to migrate VMs around a lot to do things like spread load and keep VMs
running when physical hosts are in need of package updates.
>
> Suffice it to say sometimes finding out which physical host a VM is
currently running on can be a pain.