'Acquire a lock on the stack.
:param retry: When True, retry if lock was released while stealing.
:type retry: boolean'

def acquire(self, retry=True):

    lock_engine_id = stack_lock_object.StackLock.create(self.context, self.stack_id, self.engine_id)
    if (lock_engine_id is None):
        LOG.debug(('Engine    %(engine)s    acquired    lock    on    stack    %(stack)s' % {'engine': self.engine_id, 'stack': self.stack_id}))
        return
    stack = stack_object.Stack.get_by_id(self.context, self.stack_id, show_deleted=True, eager_load=False)
    if ((lock_engine_id == self.engine_id) or service_utils.engine_alive(self.context, lock_engine_id)):
        LOG.debug(('Lock    on    stack    %(stack)s    is    owned    by    engine    %(engine)s' % {'stack': self.stack_id, 'engine': lock_engine_id}))
        raise exception.ActionInProgress(stack_name=stack.name, action=stack.action)
    else:
        LOG.info('Stale    lock    detected    on    stack    %(stack)s.        Engine    %(engine)s    will    attempt    to    steal    the    lock', {'stack': self.stack_id, 'engine': self.engine_id})
        result = stack_lock_object.StackLock.steal(self.context, self.stack_id, lock_engine_id, self.engine_id)
        if (result is None):
            LOG.info('Engine    %(engine)s    successfully    stole    the    lock    on    stack    %(stack)s', {'engine': self.engine_id, 'stack': self.stack_id})
            return
        elif (result is True):
            if retry:
                LOG.info('The    lock    on    stack    %(stack)s    was    released    while    engine    %(engine)s    was    stealing    it.    Trying    again', {'stack': self.stack_id, 'engine': self.engine_id})
                return self.acquire(retry=False)
        else:
            new_lock_engine_id = result
            LOG.info('Failed    to    steal    lock    on    stack    %(stack)s.    Engine    %(engine)s    stole    the    lock    first', {'stack': self.stack_id, 'engine': new_lock_engine_id})
        raise exception.ActionInProgress(stack_name=stack.name, action=stack.action)
