Add vm info listsing to the libvirt module

This commit is contained in:
Thomas S Hatch 2011-03-16 13:46:33 -06:00
parent 6082e850e1
commit 873e8b4755

View file

@ -8,6 +8,7 @@ import libvirt
import subprocess
import StringIO
from xml.dom import minidom
# Import libvirt
import libvirt
@ -21,7 +22,7 @@ VIRT_STATE_NAME_MAP = {
6 : "crashed"
}
def _get_conn():
def __get_conn():
'''
Detects what type of dom this node is and attempts to connect to the
correct hypervisor via libvirt.
@ -30,5 +31,30 @@ def _get_conn():
# all vm layers supported by libvirt
return libvirt.open("qemu:///system")
def list_vms():
'''
Return a list of virtual machine names on the minion
'''
conn = __get_con()
vms = []
names = conn.listDefinedDomains()
for name in names:
vm = conn.lookupByName(name)
vms.append(vm)
return vms
def _info():
'''
Return detailed information about the vms on this hyper in a dict:
[{'cpus': <int>,
'MaxMem': <int>,
'Mem': <int>,
'state': '<state>',}, ...]
'''
info = {}
conn = __get_conn()
for vm in list_vms():
raw = vm.info()