mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add vm info listsing to the libvirt module
This commit is contained in:
parent
6082e850e1
commit
873e8b4755
1 changed files with 27 additions and 1 deletions
|
@ -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()
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue