VirtualBox Python API restores snapshot

I am trying to manage some virtual machines through the vboxapi that comes with the SDK. So far I have been able to start the VM and disable it, but I cannot restore the snapshot. It seems that the power-off procedure blocks the virtual machine until the scripts run out, in fact this is the error I get:

    progress = self.session.console.restoreSnapshot (self.mach.currentSnapshot)
  File "", line 3, in restoreSnapshot
xpcom.Exception: 0x80070005 (The object is not ready)

The following are the specific functions that I call sequentially to stop vm and restore the 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

, , , - , - , ? , .

+3
2

, IConsole . .

def restore_snapshot(self):
    if self.mach:
         self.mach.lockMachine(self.session,1)
         console = self.session.console
         progress = console.restoreSnapshot(self.mach.currentSnapshot)

SDK: , ( ) IMachine:: lockMachine() IMachine:: launchVMProcess().

twitter @dsanchezlavado

+2

, .

0

All Articles