コード例 #1
0
ファイル: tenant.py プロジェクト: HugoKuo/keystone-essex3
    def list_for_user_get_page(self, user_id, marker, limit, session=None):
        if not session:
            session = get_session()

        user = api.USER.get(user_id)
        if hasattr(api.USER, 'uid_to_id'):
            backend_user_id = api.USER.uid_to_id(user_id)
        else:
            backend_user_id = user_id

        ura = aliased(models.UserRoleAssociation)
        tenant = aliased(models.Tenant)
        q1 = session.query(tenant).join((ura, ura.tenant_id == tenant.id)).\
            filter(ura.user_id == backend_user_id)
        if 'tenant_id' in user:
            if hasattr(api.TENANT, 'uid_to_id'):
                backend_tenant_id = api.TENANT.uid_to_id(user.tenant_id)
            else:
                backend_tenant_id = user.tenant_id
            q2 = session.query(tenant).filter(tenant.id == backend_tenant_id)
            q3 = q1.union(q2)
        else:
            q3 = q1
        if marker:
            results = q3.filter("tenant.id>:marker").params(
                    marker='%s' % marker).order_by(
                    tenant.id.desc()).limit(int(limit)).all()
        else:
            results = q3.order_by(tenant.id.desc()).limit(int(limit)).all()

        return TenantAPI.to_model_list(results)
コード例 #2
0
ファイル: tenant.py プロジェクト: spil-jasper/keystone
    def list_for_user_get_page(self, user_id, marker, limit, session=None):
        if not session:
            session = get_session()

        user = api.USER.get(user_id)
        if hasattr(api.USER, 'uid_to_id'):
            backend_user_id = api.USER.uid_to_id(user_id)
        else:
            backend_user_id = user_id

        ura = aliased(models.UserRoleAssociation)
        tenant = aliased(models.Tenant)
        q1 = session.query(tenant).join((ura, ura.tenant_id == tenant.id)).\
            filter(ura.user_id == backend_user_id)
        if 'tenant_id' in user:
            if hasattr(api.TENANT, 'uid_to_id'):
                backend_tenant_id = api.TENANT.uid_to_id(user.tenant_id)
            else:
                backend_tenant_id = user.tenant_id
            q2 = session.query(tenant).filter(tenant.id == backend_tenant_id)
            q3 = q1.union(q2)
        else:
            q3 = q1
        if marker:
            results = q3.filter("tenant.id>:marker").params(\
                    marker='%s' % marker).order_by(\
                    tenant.id.desc()).limit(limit).all()
        else:
            results = q3.order_by(tenant.id.desc()).limit(limit).all()

        return TenantAPI.to_model_list(results)
コード例 #3
0
ファイル: tenant.py プロジェクト: OpenStack-Kha/keystone
    def list_for_user_get_page_markers(self,
                                       user_id,
                                       marker,
                                       limit,
                                       session=None):
        if not session:
            session = get_session()

        user = api.USER.get(user_id)
        if hasattr(api.USER, 'uid_to_id'):
            backend_user_id = api.USER.uid_to_id(user_id)
        else:
            backend_user_id = user_id

        ura = aliased(models.UserRoleAssociation)
        tenant = aliased(models.Tenant)
        q1 = session.query(tenant).join((ura, ura.tenant_id == tenant.id)).\
            filter(ura.user_id == backend_user_id)
        if 'tenant_id' in user:
            if hasattr(api.TENANT, 'uid_to_id'):
                backend_tenant_id = api.TENANT.uid_to_id(user.tenant_id)
            else:
                backend_tenant_id = user.tenant_id
            q2 = session.query(tenant).filter(tenant.id == backend_tenant_id)
            q3 = q1.union(q2)
        else:
            q3 = q1

        first = q3.order_by(tenant.id).first()
        last = q3.order_by(tenant.id.desc()).first()
        if first is None:
            return (None, None)
        if marker is None:
            marker = first.id
        next_page = q3.filter(tenant.id > marker).order_by(tenant.id).limit(
            int(limit)).all()
        prev_page = q3.filter(tenant.id > marker).order_by(
            tenant.id.desc()).limit(int(limit)).all()
        if len(next_page) == 0:
            next_page = last
        else:
            for t in next_page:
                next_page = t
        if len(prev_page) == 0:
            prev_page = first
        else:
            for t in prev_page:
                prev_page = t
        if prev_page.id == marker:
            prev_page = None
        else:
            prev_page = prev_page.id
        if next_page.id == last.id:
            next_page = None
        else:
            next_page = next_page.id
        return (prev_page, next_page)
コード例 #4
0
ファイル: user.py プロジェクト: mgius/keystone
 def user_groups_get_all(self, user_id, session=None):
     if not session:
         session = get_session()
     uga = aliased(models.UserGroupAssociation)
     group = aliased(models.Group)
     return session.query(group, uga).\
                             join((uga, uga.group_id == group.id)).\
                             filter(uga.user_id == user_id).order_by(
                             group.id).all()
コード例 #5
0
ファイル: tenant.py プロジェクト: HugoKuo/keystone-essex3
    def list_for_user_get_page_markers(self, user_id, marker, limit,
            session=None):
        if not session:
            session = get_session()

        user = api.USER.get(user_id)
        if hasattr(api.USER, 'uid_to_id'):
            backend_user_id = api.USER.uid_to_id(user_id)
        else:
            backend_user_id = user_id

        ura = aliased(models.UserRoleAssociation)
        tenant = aliased(models.Tenant)
        q1 = session.query(tenant).join((ura, ura.tenant_id == tenant.id)).\
            filter(ura.user_id == backend_user_id)
        if 'tenant_id' in user:
            if hasattr(api.TENANT, 'uid_to_id'):
                backend_tenant_id = api.TENANT.uid_to_id(user.tenant_id)
            else:
                backend_tenant_id = user.tenant_id
            q2 = session.query(tenant).filter(tenant.id == backend_tenant_id)
            q3 = q1.union(q2)
        else:
            q3 = q1

        first = q3.order_by(tenant.id).first()
        last = q3.order_by(tenant.id.desc()).first()
        if first is None:
            return (None, None)
        if marker is None:
            marker = first.id
        next_page = q3.filter(tenant.id > marker).order_by(
                        tenant.id).limit(int(limit)).all()
        prev_page = q3.filter(tenant.id > marker).order_by(
                        tenant.id.desc()).limit(int(limit)).all()
        if len(next_page) == 0:
            next_page = last
        else:
            for t in next_page:
                next_page = t
        if len(prev_page) == 0:
            prev_page = first
        else:
            for t in prev_page:
                prev_page = t
        if prev_page.id == marker:
            prev_page = None
        else:
            prev_page = prev_page.id
        if next_page.id == last.id:
            next_page = None
        else:
            next_page = next_page.id
        return (prev_page, next_page)
コード例 #6
0
ファイル: tenant.py プロジェクト: mgius/keystone
 def get_all_endpoints(self, tenant_id, session=None):
     if not session:
         session = get_session()
     ep = aliased(models.Endpoints)
     endpointTemplates = aliased(models.EndpointTemplates)
     q1 = session.query(endpointTemplates).join((ep,
         ep.endpoint_template_id == endpointTemplates.id)).\
             filter(ep.tenant_id == tenant_id)
     q2 = session.query(endpointTemplates).\
         filter(endpointTemplates.is_global == 1)
     q3 = q1.union(q2)
     return q3.all()
コード例 #7
0
ファイル: group.py プロジェクト: mgius/keystone
 def get_by_user_get_page_markers(self, user_id, marker, limit, session=None):
     if not session:
         session = get_session()
     uga = aliased(models.UserGroupAssociation)
     group = aliased(models.Group)
     first, _firstassoc = session.query(group, uga).\
                         join((uga, uga.group_id == group.id)).\
                         filter(uga.user_id == user_id).\
                         order_by(group.id).first()
     last, _lastassoc = session.query(group, uga).\
                         join((uga, uga.group_id == group.id)).\
                         filter(uga.user_id == user_id).\
                         order_by(group.id.desc()).first()
     if first is None:
         return (None, None)
     if marker is None:
         marker = first.id
     next = session.query(group, uga).join(
                             (uga, uga.group_id == group.id)).\
                             filter(uga.user_id == user_id).\
                             filter("id>=:marker").params(
                             marker='%s' % marker).order_by(
                             group.id).limit(int(limit)).all()
 
     prev = session.query(group, uga).join(
                             (uga, uga.group_id == group.id)).\
                             filter(uga.user_id == user_id).\
                             filter("id < :marker").params(
                             marker='%s' % marker).order_by(
                             group.id).limit(int(limit) + 1).all()
     next_len = len(next)
     prev_len = len(prev)
 
     if next_len == 0:
         next = last
     else:
         for t, _a in next:
             next = t
     if prev_len == 0:
         prev = first
     else:
         for t, _a in prev:
             prev = t
     if first.id == marker:
         prev = None
     else:
         prev = prev.id
     if marker == last.id:
         next = None
     else:
         next = next.id
     return (prev, next)
コード例 #8
0
 def get_all_endpoints(self, tenant_id, session=None):
     if not session:
         session = get_session()
     endpointTemplates = aliased(models.EndpointTemplates)
     q = session.query(endpointTemplates).\
         filter(endpointTemplates.is_global == 1)
     if tenant_id:
         ep = aliased(models.Endpoints)
         q1 = session.query(endpointTemplates).join((ep,
             ep.endpoint_template_id == endpointTemplates.id)).\
             filter(ep.tenant_id == tenant_id)
         q = q.union(q1)
     return q.all()
コード例 #9
0
ファイル: tenant.py プロジェクト: wendy-king/x7_venv
 def get_all_endpoints(self, tenant_id, session=None):
     if not session:
         session = get_session()
     endpointTemplates = aliased(models.EndpointTemplates)
     q = session.query(endpointTemplates).filter(endpointTemplates.is_global == 1)
     if tenant_id:
         ep = aliased(models.Endpoints)
         q1 = (
             session.query(endpointTemplates)
             .join((ep, ep.endpoint_template_id == endpointTemplates.id))
             .filter(ep.tenant_id == tenant_id)
         )
         q = q.union(q1)
     return q.all()
コード例 #10
0
ファイル: tenant.py プロジェクト: mgius/keystone
 def tenants_for_user_get_page(self, user, marker, limit, session=None):
     if not session:
         session = get_session()
     ura = aliased(models.UserRoleAssociation)
     tenant = aliased(models.Tenant)
     q1 = session.query(tenant).join((ura, ura.tenant_id == tenant.id)).\
         filter(ura.user_id == user.id)
     q2 = session.query(tenant).filter(tenant.id == user.tenant_id)
     q3 = q1.union(q2)
     if marker:
         return q3.filter("tenant.id>:marker").params(\
                 marker='%s' % marker).order_by(\
                 tenant.id.desc()).limit(limit).all()
     else:
         return q3.order_by(tenant.id.desc()).limit(limit).all()
コード例 #11
0
 def tenants_for_user_get_page(self, user, marker, limit, session=None):
     if not session:
         session = get_session()
     ura = aliased(models.UserRoleAssociation)
     tenant = aliased(models.Tenant)
     q1 = session.query(tenant).join((ura, ura.tenant_id == tenant.id)).\
         filter(ura.user_id == user.id)
     q2 = session.query(tenant).filter(tenant.id == user.tenant_id)
     q3 = q1.union(q2)
     if marker:
         return q3.filter("tenant.id>:marker").params(\
                 marker='%s' % marker).order_by(\
                 tenant.id.desc()).limit(limit).all()
     else:
         return q3.order_by(tenant.id.desc()).limit(limit).all()
コード例 #12
0
    def users_get_by_tenant_get_page(self, tenant_id, marker, limit,
            session=None):
        # This is broken.  If a user has more than one role per project
        # shit hits the fan because we're limiting the wrong model.
        # Also the user lookup is nasty and potentially injectiable.
        if not session:
            session = get_session()
        user = aliased(models.User)

        if marker:
            users = session.query(user).\
                         filter_by(tenant_id = tenant_id).\
                         filter("id > :marker").params(\
                         marker='%s' % marker).order_by(user.id).\
                         limit(limit).\
                         all()
        else:
            users = session.query(user).\
                         filter_by(tenant_id = tenant_id).\
                         order_by(user.id).\
                         limit(limit).\
                         all()

        for usr in users:
            usr.tenant_roles = set()
            for role in usr.roles:
                if role.tenant_id == tenant_id:
                    usr.tenant_roles.add(role.role_id)
        return users
コード例 #13
0
ファイル: user.py プロジェクト: HugoKuo/keystone-essex3
    def users_get_by_tenant_get_page(self, tenant_id, role_id, marker, limit, session=None):
        # This is broken.  If a user has more than one role per project
        # shit hits the fan because we're limiting the wrong model.
        # Also the user lookup is nasty and potentially injectiable.
        if not session:
            session = get_session()

        if hasattr(api.TENANT, "uid_to_id"):
            tenant_id = api.TENANT.uid_to_id(tenant_id)

        user = aliased(models.UserRoleAssociation)
        query = session.query(user).filter("tenant_id = :tenant_id").params(tenant_id="%s" % tenant_id)

        if role_id:
            query = query.filter(user.role_id == role_id)

        if marker:
            rv = query.filter("id>=:marker").params(marker="%s" % marker).order_by("id").limit(int(limit)).all()
        else:
            rv = query.order_by("id").limit(int(limit)).all()

        user_ids = set([str(assoc.user_id) for assoc in rv])
        users = session.query(models.User).filter("id in ('%s')" % "','".join(user_ids)).all()

        for usr in users:
            usr.tenant_roles = set()
            for role in usr.roles:
                if role.tenant_id == tenant_id:
                    usr.tenant_roles.add(role.role_id)

        return UserAPI.to_model_list(users)
コード例 #14
0
ファイル: user.py プロジェクト: Cerberus98/keystone
 def users_get_by_tenant_get_page(self, tenant_id, marker, limit,
         session=None):
     # This is broken.  If a user has more than one role per project
     # shit hits the fan because we're limiting the wrong model.
     # Also the user lookup is nasty and potentially injectiable.
     if not session:
         session = get_session()
     user = aliased(models.UserRoleAssociation)
     if marker:
         rv = session.query(user).\
                      filter("tenant_id = :tenant_id").\
                      params(tenant_id='%s' % tenant_id).\
                      filter("id>=:marker").\
                      params(marker='%s' % marker).\
                      order_by("id").\
                      limit(limit).\
                      all()
     else:
         rv = session.query(user).\
                      filter("tenant_id = :tenant_id").\
                      params(tenant_id='%s' % tenant_id).\
                      order_by("id").\
                      limit(limit).\
                      all()
     user_ids = set([assoc.user_id for assoc in rv])
     users = session.query(models.User).\
                   filter("id in ('%s')" % "','".join(user_ids)).\
                   all()
     for usr in users:
         usr.tenant_roles = set()
         for role in usr.roles:
             if role.tenant_id == tenant_id:
                 usr.tenant_roles.add(role.role_id)
     return users
コード例 #15
0
 def users_get_by_tenant_get_page(self, tenant_id, marker, limit,
         session=None):
     # This is broken.  If a user has more than one role per project
     # shit hits the fan because we're limiting the wrong model.
     # Also the user lookup is nasty and potentially injectiable.
     if not session:
         session = get_session()
     user = aliased(models.UserRoleAssociation)
     if marker:
         rv = session.query(user).\
                      filter("tenant_id = :tenant_id").\
                      params(tenant_id='%s' % tenant_id).\
                      filter("id>=:marker").\
                      params(marker='%s' % marker).\
                      order_by("id").\
                      limit(limit).\
                      all()
     else:
         rv = session.query(user).\
                      filter("tenant_id = :tenant_id").\
                      params(tenant_id='%s' % tenant_id).\
                      order_by("id").\
                      limit(limit).\
                      all()
     user_ids = set([str(assoc.user_id) for assoc in rv])
     users = session.query(models.User).\
                   filter("id in ('%s')" % "','".join(user_ids)).\
                   all()
     for usr in users:
         usr.tenant_roles = set()
         for role in usr.roles:
             if role.tenant_id == tenant_id:
                 usr.tenant_roles.add(role.role_id)
     return users
コード例 #16
0
ファイル: user.py プロジェクト: mgius/keystone
 def users_tenant_group_get_page(self, group_id, marker, limit, session=None):
     if not session:
         session = get_session()
     uga = aliased(models.UserGroupAssociation)
     user = aliased(models.User)
     if marker:
         return session.query(user, uga).join(\
                             (uga, uga.user_id == user.id)).\
                             filter(uga.group_id == group_id).\
                             filter("id>=:marker").params(\
                             marker='%s' % marker).order_by(\
                             user.id).limit(limit).all()
     else:
         return session.query(user, uga).\
                             join((uga, uga.user_id == user.id)).\
                             filter(uga.group_id == group_id).order_by(\
                             user.id).limit(limit).all()
コード例 #17
0
ファイル: tenant.py プロジェクト: HugoKuo/keystone-essex3
    def get_all_endpoints(self, tenant_id, session=None):
        if not session:
            session = get_session()

        if hasattr(api.TENANT, 'uid_to_id'):
            tenant_id = self.uid_to_id(tenant_id)

        endpoint_templates = aliased(models.EndpointTemplates)
        q = session.query(endpoint_templates).\
            filter(endpoint_templates.is_global == True)
        if tenant_id:
            ep = aliased(models.Endpoints)
            q1 = session.query(endpoint_templates).join((ep,
                ep.endpoint_template_id == endpoint_templates.id)).\
                filter(ep.tenant_id == tenant_id)
            q = q.union(q1)
        return q.all()
コード例 #18
0
ファイル: tenant.py プロジェクト: spil-jasper/keystone
    def get_all_endpoints(self, tenant_id, session=None):
        if not session:
            session = get_session()

        if hasattr(api.TENANT, 'uid_to_id'):
            tenant_id = self.uid_to_id(tenant_id)

        endpoint_templates = aliased(models.EndpointTemplates)
        q = session.query(endpoint_templates).\
            filter(endpoint_templates.is_global == True)
        if tenant_id:
            ep = aliased(models.Endpoints)
            q1 = session.query(endpoint_templates).join((ep,
                ep.endpoint_template_id == endpoint_templates.id)).\
                filter(ep.tenant_id == tenant_id)
            q = q.union(q1)
        return q.all()
コード例 #19
0
ファイル: group.py プロジェクト: mgius/keystone
 def get_by_user_get_page(self, user_id, marker, limit, session=None):
     if not session:
         session = get_session()
     uga = aliased(models.UserGroupAssociation)
     group = aliased(models.Group)
     if marker:
         return session.query(group, uga).join(\
                             (uga, uga.group_id == group.id)).\
                             filter(uga.user_id == user_id).\
                             filter("id>=:marker").params(
                             marker='%s' % marker).order_by(
                             group.id).limit(limit).all()
     else:
         return session.query(group, uga).\
                             join((uga, uga.group_id == group.id)).\
                             filter(uga.user_id == user_id).order_by(
                             group.id).limit(limit).all()
コード例 #20
0
ファイル: tenant.py プロジェクト: mgius/keystone
    def tenants_for_user_get_page_markers(self,
                                          user,
                                          marker,
                                          limit,
                                          session=None):
        if not session:
            session = get_session()
        ura = aliased(models.UserRoleAssociation)
        tenant = aliased(models.Tenant)
        q1 = session.query(tenant).join((ura, ura.tenant_id == tenant.id)).\
            filter(ura.user_id == user.id)
        q2 = session.query(tenant).filter(tenant.id == user.tenant_id)
        q3 = q1.union(q2)

        first = q3.order_by(\
                            tenant.id).first()
        last = q3.order_by(\
                            tenant.id.desc()).first()
        if first is None:
            return (None, None)
        if marker is None:
            marker = first.id
        next = q3.filter(tenant.id > marker).order_by(\
                        tenant.id).limit(limit).all()
        prev = q3.filter(tenant.id > marker).order_by(\
                        tenant.id.desc()).limit(int(limit)).all()
        if len(next) == 0:
            next = last
        else:
            for t in next:
                next = t
        if len(prev) == 0:
            prev = first
        else:
            for t in prev:
                prev = t
        if prev.id == marker:
            prev = None
        else:
            prev = prev.id
        if next.id == last.id:
            next = None
        else:
            next = next.id
        return (prev, next)
コード例 #21
0
    def tenants_for_user_get_page_markers(self,
                                          user,
                                          marker,
                                          limit,
                                          session=None):
        if not session:
            session = get_session()
        ura = aliased(models.UserRoleAssociation)
        tenant = aliased(models.Tenant)
        q1 = session.query(tenant).join((ura, ura.tenant_id == tenant.id)).\
            filter(ura.user_id == user.id)
        q2 = session.query(tenant).filter(tenant.id == user.tenant_id)
        q3 = q1.union(q2)

        first = q3.order_by(\
                            tenant.id).first()
        last = q3.order_by(\
                            tenant.id.desc()).first()
        if first is None:
            return (None, None)
        if marker is None:
            marker = first.id
        next_page = q3.filter(tenant.id > marker).order_by(\
                        tenant.id).limit(limit).all()
        prev_page = q3.filter(tenant.id > marker).order_by(\
                        tenant.id.desc()).limit(int(limit)).all()
        if len(next_page) == 0:
            next_page = last
        else:
            for t in next_page:
                next_page = t
        if len(prev_page) == 0:
            prev_page = first
        else:
            for t in prev_page:
                prev_page = t
        if prev_page.id == marker:
            prev_page = None
        else:
            prev_page = prev_page.id
        if next_page.id == last.id:
            next_page = None
        else:
            next_page = next_page.id
        return (prev_page, next_page)
コード例 #22
0
ファイル: user.py プロジェクト: mgius/keystone
 def users_tenant_group_get_page_markers(self, group_id, marker, limit, session=None):
     if not session:
         session = get_session()
     uga = aliased(models.UserGroupAssociation)
     user = aliased(models.User)
     first = session.query(models.User).order_by(\
                         models.User.id).first()
     last = session.query(models.User).order_by(\
                         models.User.id.desc()).first()
     if first is None:
         return (None, None)
     if marker is None:
         marker = first.id
     next = session.query(user).join(
                             (uga, uga.user_id == user.id)).\
                             filter(uga.group_id == group_id).\
                             filter("id > :marker").params(\
                             marker='%s' % marker).order_by(\
                             user.id).limit(limit).all()
     prev = session.query(user).join(\
                             (uga, uga.user_id == user.id)).\
                             filter(uga.group_id == group_id).\
                             filter("id < :marker").params(\
                             marker='%s' % marker).order_by(\
                             user.id.desc()).limit(int(limit)).all()
     if len(next) == 0:
         next = last
     else:
         for t in next:
             next = t
     if len(prev) == 0:
         prev = first
     else:
         for t in prev:
             prev = t
     if prev.id == marker:
         prev = None
     else:
         prev = prev.id
     if next.id == last.id:
         next = None
     else:
         next = next.id
     return (prev, next)
コード例 #23
0
    def endpoint_get_by_tenant_get_page_markers(self,
                                                tenant_id,
                                                marker,
                                                limit,
                                                session=None):
        if not session:
            session = get_session()

        if hasattr(api.TENANT, 'uid_to_id'):
            tenant_id = api.TENANT.uid_to_id(tenant_id)

        tba = aliased(models.Endpoints)
        first = session.query(tba).\
            filter(tba.tenant_id == tenant_id).\
            order_by(tba.id).first()
        last = session.query(tba).\
            filter(tba.tenant_id == tenant_id).\
            order_by(tba.id.desc()).first()
        if first is None:
            return (None, None)
        if marker is None:
            marker = first.id
        next_page = session.query(tba).\
            filter(tba.tenant_id == tenant_id).\
            filter("id>=:marker").params(
            marker='%s' % marker).order_by(
            tba.id).limit(int(limit)).all()

        prev_page = session.query(tba).\
                        filter(tba.tenant_id == tenant_id).\
                        filter("id < :marker").params(
                        marker='%s' % marker).order_by(
                        tba.id).limit(int(limit) + 1).all()
        next_len = len(next_page)
        prev_len = len(prev_page)

        if next_len == 0:
            next_page = last
        else:
            for t in next_page:
                next_page = t
        if prev_len == 0:
            prev_page = first
        else:
            for t in prev_page:
                prev_page = t
        if first.id == marker:
            prev_page = None
        else:
            prev_page = prev_page.id
        if marker == last.id:
            next_page = None
        else:
            next_page = next_page.id
        return (prev_page, next_page)
コード例 #24
0
ファイル: user.py プロジェクト: Cerberus98/keystone
 def users_get_page(self, marker, limit, session=None):
     if not session:
         session = get_session()
     user = aliased(models.User)
     if marker:
         return session.query(user).\
                             filter("id>=:marker").params(
                             marker='%s' % marker).order_by(
                             "id").limit(limit).all()
     else:
         return session.query(user).\
                             order_by("id").limit(limit).all()
コード例 #25
0
ファイル: user.py プロジェクト: wendy-king/x7_venv
 def users_get_page(self, marker, limit, session=None):
     if not session:
         session = get_session()
     user = aliased(models.User)
     if marker:
         return session.query(user).\
                             filter("id>=:marker").params(
                             marker='%s' % marker).order_by(
                             "id").limit(limit).all()
     else:
         return session.query(user).\
                             order_by("id").limit(limit).all()
コード例 #26
0
ファイル: user.py プロジェクト: OpenStack-Kha/keystone
    def users_get_by_tenant_get_page_markers(self, tenant_id, \
            role_id, marker, limit, session=None):
        if not session:
            session = get_session()

        if hasattr(api.TENANT, 'uid_to_id'):
            tenant_id = api.TENANT.uid_to_id(tenant_id)

        user = aliased(models.UserRoleAssociation)
        query = session.query(user).\
                        filter(user.tenant_id == tenant_id)
        if role_id:
            query = query.filter(
                user.role_id == role_id)
        first = query.\
            order_by(user.id).first()
        last = query.\
            order_by(user.id.desc()).first()
        if first is None:
            return (None, None)
        if marker is None:
            marker = first.id
        next_page = query.\
            filter("id > :marker").params(
            marker='%s' % marker).order_by(user.id).\
            limit(int(limit)).all()
        prev_page = query.\
            filter("id < :marker").params(
            marker='%s' % marker).order_by(
            user.id.desc()).limit(int(limit)).all()
        next_len = len(next_page)
        prev_len = len(prev_page)

        if next_len == 0:
            next_page = last
        else:
            for t in next_page:
                next_page = t
        if prev_len == 0:
            prev_page = first
        else:
            for t in prev_page:
                prev_page = t
        if first.id == marker:
            prev_page = None
        else:
            prev_page = prev_page.id
        if marker == last.id:
            next_page = None
        else:
            next_page = next_page.id
        return (prev_page, next_page)
コード例 #27
0
ファイル: endpoint_template.py プロジェクト: bodepd/keystone
    def endpoint_get_by_tenant_get_page_markers(self, tenant_id, marker, limit,
            session=None):
        if not session:
            session = get_session()

        if hasattr(api.TENANT, 'uid_to_id'):
            tenant_id = api.TENANT.uid_to_id(tenant_id)

        tba = aliased(models.Endpoints)
        first = session.query(tba).\
            filter(tba.tenant_id == tenant_id).\
            order_by(tba.id).first()
        last = session.query(tba).\
            filter(tba.tenant_id == tenant_id).\
            order_by(tba.id.desc()).first()
        if first is None:
            return (None, None)
        if marker is None:
            marker = first.id
        next_page = session.query(tba).\
            filter(tba.tenant_id == tenant_id).\
            filter("id>=:marker").params(
            marker='%s' % marker).order_by(
            tba.id).limit(int(limit)).all()

        prev_page = session.query(tba).\
                        filter(tba.tenant_id == tenant_id).\
                        filter("id < :marker").params(
                        marker='%s' % marker).order_by(
                        tba.id).limit(int(limit) + 1).all()
        next_len = len(next_page)
        prev_len = len(prev_page)

        if next_len == 0:
            next_page = last
        else:
            for t in next_page:
                next_page = t
        if prev_len == 0:
            prev_page = first
        else:
            for t in prev_page:
                prev_page = t
        if first.id == marker:
            prev_page = None
        else:
            prev_page = prev_page.id
        if marker == last.id:
            next_page = None
        else:
            next_page = next_page.id
        return (prev_page, next_page)
コード例 #28
0
ファイル: user.py プロジェクト: spil-jasper/keystone
    def users_get_by_tenant_get_page_markers(self, tenant_id, \
            role_id, marker, limit, session=None):
        if not session:
            session = get_session()

        if hasattr(api.TENANT, 'uid_to_id'):
            tenant_id = api.TENANT.uid_to_id(tenant_id)

        user = aliased(models.UserRoleAssociation)
        query = session.query(user).\
                        filter(user.tenant_id == tenant_id)
        if role_id:
            query = query.filter(user.role_id == role_id)
        first = query.\
            order_by(user.id).first()
        last = query.\
            order_by(user.id.desc()).first()
        if first is None:
            return (None, None)
        if marker is None:
            marker = first.id
        next_page = query.\
            filter("id > :marker").params(\
            marker='%s' % marker).order_by(user.id).\
            limit(int(limit)).all()
        prev_page = query.\
            filter("id < :marker").params(
            marker='%s' % marker).order_by(
            user.id.desc()).limit(int(limit)).all()
        next_len = len(next_page)
        prev_len = len(prev_page)

        if next_len == 0:
            next_page = last
        else:
            for t in next_page:
                next_page = t
        if prev_len == 0:
            prev_page = first
        else:
            for t in prev_page:
                prev_page = t
        if first.id == marker:
            prev_page = None
        else:
            prev_page = prev_page.id
        if marker == last.id:
            next_page = None
        else:
            next_page = next_page.id
        return (prev_page, next_page)
コード例 #29
0
ファイル: endpoint_template.py プロジェクト: hub-cap/keystone
    def endpoint_get_by_tenant_get_page_markers(self, tenant_id, marker, limit, session=None):
        if not session:
            session = get_session()
        tba = aliased(models.Endpoints)
        first = session.query(tba).filter(tba.tenant_id == tenant_id).order_by(tba.id).first()
        last = session.query(tba).filter(tba.tenant_id == tenant_id).order_by(tba.id.desc()).first()
        if first is None:
            return (None, None)
        if marker is None:
            marker = first.id
        next = (
            session.query(tba)
            .filter(tba.tenant_id == tenant_id)
            .filter("id>=:marker")
            .params(marker="%s" % marker)
            .order_by(tba.id)
            .limit(int(limit))
            .all()
        )

        prev = (
            session.query(tba)
            .filter(tba.tenant_id == tenant_id)
            .filter("id < :marker")
            .params(marker="%s" % marker)
            .order_by(tba.id)
            .limit(int(limit) + 1)
            .all()
        )
        next_len = len(next)
        prev_len = len(prev)

        if next_len == 0:
            next = last
        else:
            for t in next:
                next = t
        if prev_len == 0:
            prev = first
        else:
            for t in prev:
                prev = t
        if first.id == marker:
            prev = None
        else:
            prev = prev.id
        if marker == last.id:
            next = None
        else:
            next = next.id
        return (prev, next)
コード例 #30
0
ファイル: user.py プロジェクト: HugoKuo/keystone-essex3
    def users_get_page_markers(self, marker, limit, session=None):
        if not session:
            session = get_session()

        user = aliased(models.User)
        first = session.query(user).order_by(user.id).first()
        last = session.query(user).order_by(user.id.desc()).first()
        if first is None:
            return (None, None)
        if marker is None:
            marker = first.id
        next_page = (
            session.query(user)
            .filter("id > :marker")
            .params(marker="%s" % marker)
            .order_by(user.id)
            .limit(int(limit))
            .all()
        )
        prev_page = (
            session.query(user)
            .filter("id < :marker")
            .params(marker="%s" % marker)
            .order_by(user.id.desc())
            .limit(int(limit))
            .all()
        )
        next_len = len(next_page)
        prev_len = len(prev_page)

        if next_len == 0:
            next_page = last
        else:
            for t in next_page:
                next_page = t
        if prev_len == 0:
            prev_page = first
        else:
            for t in prev_page:
                prev_page = t
        if first.id == marker:
            prev_page = None
        else:
            prev_page = prev_page.id
        if marker == last.id:
            next_page = None
        else:
            next_page = next_page.id
        return (prev_page, next_page)
コード例 #31
0
ファイル: user.py プロジェクト: mgius/keystone
 def users_get_by_tenant_get_page_markers(self, tenant_id, marker, limit, \
         session=None):
     if not session:
         session = get_session()
     user = aliased(models.UserRoleAssociation)
     first = session.query(user).\
                     filter(user.tenant_id == tenant_id).\
                     order_by(user.id).first()
     last = session.query(user).\
                         filter(user.tenant_id == tenant_id).\
                         order_by(user.id.desc()).first()
     if first is None:
         return (None, None)
     if marker is None:
         marker = first.id
     next = session.query(user).\
                     filter(user.tenant_id == tenant_id).\
                     filter("id > :marker").params(\
                     marker='%s' % marker).order_by(user.id).\
                     limit(int(limit)).all()
     prev = session.query(user).\
                     filter(user.tenant_id == tenant_id).\
                     filter("id < :marker").params(
                     marker='%s' % marker).order_by(
                     user.id.desc()).limit(int(limit)).all()
     next_len = len(next)
     prev_len = len(prev)
 
     if next_len == 0:
         next = last
     else:
         for t in next:
             next = t
     if prev_len == 0:
         prev = first
     else:
         for t in prev:
             prev = t
     if first.id == marker:
         prev = None
     else:
         prev = prev.id
     if marker == last.id:
         next = None
     else:
         next = next.id
     return (prev, next)
コード例 #32
0
ファイル: user.py プロジェクト: HugoKuo/keystone-essex3
    def users_get_page(self, marker, limit, session=None):
        if not session:
            session = get_session()

        user = aliased(models.User)
        if marker:
            results = (
                session.query(user)
                .filter("id>=:marker")
                .params(marker="%s" % marker)
                .order_by("id")
                .limit(int(limit))
                .all()
            )
        else:
            results = session.query(user).order_by("id").limit(int(limit)).all()

        return UserAPI.to_model_list(results)
コード例 #33
0
ファイル: user.py プロジェクト: spil-jasper/keystone
    def users_get_page_markers(self, marker, limit, session=None):
        if not session:
            session = get_session()

        user = aliased(models.User)
        first = session.query(user).\
                        order_by(user.id).first()
        last = session.query(user).\
                            order_by(user.id.desc()).first()
        if first is None:
            return (None, None)
        if marker is None:
            marker = first.id
        next_page = session.query(user).\
                        filter("id > :marker").params(\
                        marker='%s' % marker).order_by(user.id).\
                        limit(int(limit)).all()
        prev_page = session.query(user).\
                        filter("id < :marker").params(
                        marker='%s' % marker).order_by(
                        user.id.desc()).limit(int(limit)).all()
        next_len = len(next_page)
        prev_len = len(prev_page)

        if next_len == 0:
            next_page = last
        else:
            for t in next_page:
                next_page = t
        if prev_len == 0:
            prev_page = first
        else:
            for t in prev_page:
                prev_page = t
        if first.id == marker:
            prev_page = None
        else:
            prev_page = prev_page.id
        if marker == last.id:
            next_page = None
        else:
            next_page = next_page.id
        return (prev_page, next_page)