コード例 #1
0
ファイル: user.py プロジェクト: lvdongbing/bilean
    def load(cls, context, user_id=None, user=None, realtime=False,
             show_deleted=False, tenant_safe=True):
        '''Retrieve a user from database.'''
        if user is None:
            user = db_api.user_get(context, user_id,
                                   show_deleted=show_deleted,
                                   tenant_safe=tenant_safe)
            if user is None:
                raise exception.UserNotFound(user=user_id)

        u = cls._from_db_record(user)
        if not realtime:
            return u
        if u.rate > 0 and u.status != u.FREEZE:
            seconds = (timeutils.utcnow() - u.last_bill).total_seconds()
            u.balance -= u.rate * seconds
        return u
コード例 #2
0
ファイル: user.py プロジェクト: openstack/bilean
    def load(cls, context, user_id=None, user=None, realtime=False,
             show_deleted=False, project_safe=True):
        '''Retrieve a user from database.'''
        if context.is_admin:
            project_safe = False
        if user is None:
            user = db_api.user_get(context, user_id,
                                   show_deleted=show_deleted,
                                   project_safe=project_safe)
            if user is None:
                raise exception.UserNotFound(user=user_id)

        u = cls._from_db_record(user)
        if not realtime:
            return u
        if u.rate > 0 and u.status != u.FREEZE:
            seconds = utils.make_decimal(wallclock()) - u.last_bill
            u.balance -= u.rate * seconds
        return u