예제 #1
0
    def create_session(self, lock_type=library.LockType.shared, session=None):
        """Lock this machine

        Arguments:
            lock_type - see IMachine.lock_machine for details
            session - optionally define a session object to lock this machine
                      against.  If not defined, a new ISession object is
                      created to lock against

        return an ISession object
        """
        if session is None:
            session = library.ISession()
        # NOTE: The following hack handles the issue of unknown machine state.
        #       This occurs most frequently when a machine is powered off and
        #       in spite waiting for the completion event to end, the state of
        #       machine still raises the following Error:
        #          virtualbox.library.VBoxErrorVmError: 0x80bb0003 (Failed to \
        #          get a console object from the direct session (Unknown \
        #          Status 0x80BB0002))
        error = None
        for _ in range(10):
            try:
                self.lock_machine(session, lock_type)
            except Exception as exc:
                error = exc
                time.sleep(1)
                continue
            else:
                break
        else:
            if error is not None:
                raise Exception("Failed to create clone - %s" % error)
        return session
예제 #2
0
 def launch_vm_process(self, session=None, type_p='gui', environment=''):
     if session is None:
         local_session = library.ISession()
     else:
         local_session = session
     p = super(IMachine, self).launch_vm_process(local_session, type_p,
                                                 environment)
     if session is None:
         p.wait_for_completion(-1)
         local_session.unlock_machine()
     return p
예제 #3
0
    def launch_vm_process(self, session=None, type_p="gui", environment=None):
        if session is None:
            local_session = library.ISession()
        else:
            local_session = session

        environment_changes = []
        if environment is not None:
            # Split string of environment changes by new line symbol
            if isinstance(environment, basestring):
                environment_changes = environment.splitlines()
            else:
                environment_changes = environment

        p = super(IMachine, self).launch_vm_process(local_session, type_p,
                                                    environment_changes)
        if session is None:
            p.wait_for_completion(-1)
            local_session.unlock_machine()
        return p