Esempio n. 1
0
    def lock(self, type=Constants.LockType_Shared):
        """Contextmanager yielding a session to a locked machine.

        Machine must be registered."""
        session = Session.create()
        with VirtualBoxException.ExceptionHandler():
            self.getIMachine().lockMachine(session.getISession(), type)
        try:
            session._setMachine(VirtualMachine(session.getIMachine()))
            yield session
        finally:
            session.unlockMachine(wait=True)
Esempio n. 2
0
    def powerOn(self, type="gui", env=""):
        """Spawns a new process that executes a virtual machine.

        This is spawning a "remote session" in VirtualBox terms."""
        # TODO: Add a wait argument
        if not self.isRegistered():
            raise VirtualBoxException.VirtualBoxInvalidVMStateException(
                "VM is not registered")
        with VirtualBoxException.ExceptionHandler():
            iMachine = self.getIMachine()
            session = Session.create()
            iprogress = iMachine.launchVMProcess(session.getISession(),
                                                 type, env)
            progress = Progress(iprogress)
            progress.waitForCompletion()
            session.unlockMachine()