def list_vms(running=False):
"""
Return the list of VM in for the form name => uuid, when the running bool
is set to true, only return running VMs
:param running: bool
:return: dict[str,str]
"""
try:
LIST_PARSER = re.compile(r'"(?P<name>[^"]+)" \{(?P<uuid>[^\}]+)\}')
vms = {}
list = running and 'runningvms' or 'vms'
for line in VBoxManage('list', list, _iter=True):
res = re.match(LIST_PARSER, line)
if res:
vms[res.group('name')] = res.group('uuid')
return vms
except CommandNotFound:
return {}
评论列表
文章目录