from subprocess import Popen, PIPE
def running_vms():
"""
Return list of running vms
"""
f = Popen(r'vboxmanage nologo list runningvms', stdout=PIPE).stdout
data = [ eachLine.strip() for eachLine in f ]
return data
def restore_vm(name='', snapshot=''):
"""
Restore VM to specific snapshot uuid
name = VM Name
snapshot = uuid of snapshot (uuid can be found in the xml file of your machines folder)
"""
command = r'vboxmanage nologo snapshot %s restore %s' % (name,snapshot)
f = Popen(command, stdout=PIPE).stdout
data = [ eachLine.strip() for eachLine in f ]
return data
def launch_vm(name=''):
"""
Launch VM
name = VM Name
"""
command = r'vboxmanage nologo startvm %s ' % name
f = Popen(command, stdout=PIPE).stdout
data = [ eachLine.strip() for eachLine in f ]
return data
我发现我可以使用以下函数来查找VM是否正在运行,将VM还原到特定的快照,并按名称启动VM。在
引用的代码似乎没有指定要运行哪个VM。您不应该先执行一个^{} 调用,然后在
startVM
调用中使用得到的VM实例吗?E、 g.:…将启动使用给定GUID标识的VM(所有VirtualBox VM在创建时都会分配一个GUID)。您可以从VM的XML文件中获取GUID。如果您需要在运行时发现vm,可以使用方便的^{} 调用:
^{pr2}$相关问题 更多 >
编程相关推荐