def lock_machine(self, session, lock_type):
        """Locks the machine for the given session to enable the caller
        to make changes to the machine or start the VM or control
        VM execution.
        
        There are two ways to lock a machine for such uses:
        
        
        If you want to make changes to the machine settings,
        you must obtain an exclusive write lock on the machine
        by setting @a lockType to @c Write.
        
        This will only succeed if no other process has locked
        the machine to prevent conflicting changes. Only after
        an exclusive write lock has been obtained using this method, one
        can change all VM settings or execute the VM in the process
        space of the session object. (Note that the latter is only of
        interest if you actually want to write a new front-end for
        virtual machines; but this API gets called internally by
        the existing front-ends such as VBoxHeadless and the VirtualBox
        GUI to acquire a write lock on the machine that they are running.)
        
        On success, write-locking the machine for a session creates
        a second copy of the IMachine object. It is this second object
        upon which changes can be made; in VirtualBox terminology, the
        second copy is "mutable". It is only this second, mutable machine
        object upon which you can call methods that change the
        machine state. After having called this method, you can
        obtain this second, mutable machine object using the
        :py:func:`ISession.machine`  attribute.
        
        If you only want to check the machine state or control
        machine execution without actually changing machine
        settings (e.g. to get access to VM statistics or take
        a snapshot or save the machine state), then set the
        @a lockType argument to @c Shared.
        
        If no other session has obtained a lock, you will obtain an
        exclusive write lock as described above. However, if another
        session has already obtained such a lock, then a link to that
        existing session will be established which allows you
        to control that existing session.
        
        To find out which type of lock was obtained, you can
        inspect :py:func:`ISession.type_p` , which will have been
        set to either @c WriteLock or @c Shared.
        
        
        
        In either case, you can get access to the :py:class:`IConsole` 
        object which controls VM execution.
        
        Also in all of the above cases, one must always call
        :py:func:`ISession.unlock_machine`  to release the lock on the machine, or
        the machine's state will eventually be set to "Aborted".
        
        To change settings on a machine, the following sequence is typically
        performed:
        
        
        Call this method to obtain an exclusive write lock for the current session.
        
        Obtain a mutable IMachine object from :py:func:`ISession.machine` .
        
        Change the settings of the machine by invoking IMachine methods.
        
        Call :py:func:`IMachine.save_settings` .
        
        Release the write lock by calling :py:func:`ISession.unlock_machine` .

        in session of type :class:`ISession`
            Session object for which the machine will be locked.

        in lock_type of type :class:`LockType`
            If set to @c Write, then attempt to acquire an exclusive write lock or fail.
            If set to @c Shared, then either acquire an exclusive write lock or establish
            a link to an existing session.

        raises :class:`OleErrorUnexpected`
            Virtual machine not registered.
        
        raises :class:`OleErrorAccessdenied`
            Process not started by
        
        raises :class:`VBoxErrorInvalidObjectState`
            Session already open or being opened.
        
        raises :class:`VBoxErrorVmError`
            Failed to assign machine to session.
        
        """
        if not isinstance(session, ISession):
            raise TypeError("session can only be an instance of type ISession")
        if not isinstance(lock_type, LockType):
            raise TypeError("lock_type can only be an instance of type LockType")
        self._call("lockMachine",
                     in_p=[session, lock_type])