VirtualBox Python API 恢复快照
我正在尝试通过 SDK 提供的 vboxapi 管理一些虚拟机。 到目前为止,我成功启动了虚拟机并关闭了它的电源,但我无法恢复快照。 看起来断电过程会锁定虚拟机,直到脚本终止,事实上,这是我得到的错误:
progress = self.session.console.restoreSnapshot(self.mach.currentSnapshot) File "", line 3, in restoreSnapshot xpcom.Exception: 0x80070005 (The object is not ready)
以下是我顺序调用的用于停止虚拟机和恢复快照的特定函数。
def stop(self): if self.mach: # Poweroff the virtual machine. progress = self.session.console.powerDown() # Wait for task to complete with a 60 seconds timeout. progress.waitForCompletion(VIRTUALBOX_TIMEOUT) # Check if poweroff was successful. if progress.resultCode != 0: log("[Virtual Machine] [PowerOff] [ERROR] Unable to poweroff virtual machine \"%s\"." % self.mach.name) return False else: log("[Virtual Machine] [PowerOff] Virtual machine \"%s\" powered off successfully." % self.mach.name) else: log("[Virtual Machine] [PowerOff] [ERROR] No virtual machine handle.") return False return True def restore_snapshot(self): if self.mach: # Restore virtual machine snapshot. progress = self.session.console.restoreSnapshot(self.mach.currentSnapshot) # Wait for task to complete with a 60 seconds timeout. progress.waitForCompletion(VIRTUALBOX_TIMEOUT) # Check if snapshot restoring was successful. if progress.resultCode != 0: log("[Virtual Machine] [Restore Snapshot] [ERROR] Unable to restore virtual machine \"%s\" snapshot." % self.mach.name) return False else: log("[Virtual Machine] [Restore Snapshot] Virtual machine \"%s\" successfully restored to current snashot." % self.mach.name) else: log("[Virtual Machine] [Restore Snapshot] [ERROR] No virtual machine handle.") return False return True
我想我可能错过了一些东西,有什么线索吗? 谢谢, C.
I'm trying to manage some Virtual Machines through the vboxapi provided with the SDK.
So far I managed to launch the VM and poweroff it, but I'm not able to restore the snapshot.
Looks like the power off procedure locks the virtual machine until the scripts terminates, as a matter of fact this is the error that I get:
progress = self.session.console.restoreSnapshot(self.mach.currentSnapshot) File "", line 3, in restoreSnapshot xpcom.Exception: 0x80070005 (The object is not ready)
And following is the specific functions I sequentially call to stop vm and restore snapshot.
def stop(self): if self.mach: # Poweroff the virtual machine. progress = self.session.console.powerDown() # Wait for task to complete with a 60 seconds timeout. progress.waitForCompletion(VIRTUALBOX_TIMEOUT) # Check if poweroff was successful. if progress.resultCode != 0: log("[Virtual Machine] [PowerOff] [ERROR] Unable to poweroff virtual machine \"%s\"." % self.mach.name) return False else: log("[Virtual Machine] [PowerOff] Virtual machine \"%s\" powered off successfully." % self.mach.name) else: log("[Virtual Machine] [PowerOff] [ERROR] No virtual machine handle.") return False return True def restore_snapshot(self): if self.mach: # Restore virtual machine snapshot. progress = self.session.console.restoreSnapshot(self.mach.currentSnapshot) # Wait for task to complete with a 60 seconds timeout. progress.waitForCompletion(VIRTUALBOX_TIMEOUT) # Check if snapshot restoring was successful. if progress.resultCode != 0: log("[Virtual Machine] [Restore Snapshot] [ERROR] Unable to restore virtual machine \"%s\" snapshot." % self.mach.name) return False else: log("[Virtual Machine] [Restore Snapshot] Virtual machine \"%s\" successfully restored to current snashot." % self.mach.name) else: log("[Virtual Machine] [Restore Snapshot] [ERROR] No virtual machine handle.") return False return True
I think I'm probably missing something, any clue of what that is?
Thanks,
C.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果关闭计算机,则必须创建一个新的 IConsole 对象来恢复快照。在您的代码中,您可以在恢复快照之前添加此行。
在SDK中:
当机器被锁定特定会话(客户端
进程)使用 IMachine::lockMachine() 或 IMachine::launchVMProcess()。
推特@dsanchezlavado
If you powerDown the machine you have to create a new IConsole object to restore the snapshot. In your code you can add this lines before restore the snapshot.
In the SDK:
A console object gets created when a machine has been locked for a particular session (client
process) using IMachine::lockMachine() or IMachine::launchVMProcess().
twitter @dsanchezlavado
您需要首先锁定机器,以便为您创建控制台对象。
You need to lock the machine first so that the console object get created for you.