def index(self, req, body=None): body = body or {} order = body.pop('order', None) desc = body.pop('desc', False) page_num = int(body.pop('page_num', 0)) session = endpoint_session(readonly=True) columns = [ Group.group_id, Group.name, Group.platfrom_id, Group.warsvr, Group.desc, Group.areas ] results = resultutils.bulk_results(session, model=Group, columns=columns, counter=Group.group_id, order=order, desc=desc, option=joinedload(Group.areas, innerjoin=False), page_num=page_num) for column in results['data']: areas = column.get('areas', []) column['areas'] = [] for area in areas: column['areas'].append( dict(area_id=area.area_id, areaname=area.areaname, show_id=area.show_id)) return results
def index(self, req, body=None): """列出漫画""" body = body or {} cid = body.get('cid') session = endpoint_session(readonly=True) filters = [] if cid: filters.insert(0, Comic.cid < cid) filters = filters[0] if len(filters) == 1 else and_(*filters) ret_dict = resultutils.bulk_results(session, model=Comic, columns=[ Comic.cid, Comic.name, Comic.author, Comic.type, Comic.region, Comic.point, Comic.last, Comic.ext, Comic.lastup, ], counter=Comic.cid, order=Comic.cid, desc=True, filter=filters, limit=1000) return ret_dict
def index(self, req, body=None): session = endpoint_session() body = body or {} post = int(body.get('post', 0)) limit = int(body.get('limit', 0)) timeline = int(body.get('timeline', 0)) if limit < 0: raise InvalidArgument('NO for limit less then 0') if post and timeline: raise InvalidArgument('Both post and timeline over 0') filter = None if post > 0: filter = LogEntity.id < post elif timeline: filter = LogEntity.atime < timeline ret_dict = resultutils.bulk_results(session, model=LogEntity, columns=[ LogEntity.id, LogEntity.ip, LogEntity.atime, LogEntity.path ], counter=LogEntity.id, order=LogEntity.id, desc=True, filter=filter, limit=abs(limit)) return ret_dict
def index(self, req, body=None): """列出订单""" body = body or {} session = endpoint_session(readonly=True) sandbox = int(body.pop('sandbox', False)) platform = body.pop('platform', None) oid = body.pop('oid', None) filters = [Order.sandbox == sandbox] if platform: filters.insert(0, Order.platform == platform) if oid: filters.insert(0, Order.oid < oid) filters = filters[0] if len(filters) == 1 else and_(*filters) ret_dict = resultutils.bulk_results(session, model=Order, columns=[ Order.oid, Order.platform, Order.uid, Order.coin, Order.gift, Order.money, Order.platform, Order.time, ], counter=Order.oid, order=Order.oid, desc=True, filter=filters, limit=1000) return ret_dict
def index(self, req, database_id, body=None): body = body or {} database_id = int(database_id) order = body.pop('order', None) desc = body.pop('desc', False) page_num = int(body.pop('page_num', 0)) session = endpoint_session(readonly=True) results = resultutils.bulk_results( session, model=GopSchema, columns=[ GopSchema.schema_id, GopSchema.schema, GopSchema.database_id, GopSchema.schema, GopSchema.character_set, GopSchema.collation_type, ], counter=GopSchema.schema_id, order=order, desc=desc, filter=GopSchema.database_id == database_id, page_num=page_num) return results
def index(self, req, body=None): session = endpoint_session() ret_dict = resultutils.bulk_results(session, model=KeyWord, columns=[KeyWord.kid, KeyWord.value, ], counter=KeyWord.kid, order=KeyWord.kid, desc=True, limit=100000) return ret_dict
def index(self, req, body=None): body = body or {} order = body.pop('order', None) desc = body.pop('desc', False) page_num = int(body.pop('page_num', 0)) slaves = body.pop('slaves', False) # schemas = body.pop('schemas', False) # quotes = body.pop('quotes', False) impl = body.get('impl', None) session = endpoint_session(readonly=True) _filter = None if impl: _filter = GopDatabase.impl == impl columns = [ GopDatabase.database_id, GopDatabase.slave, GopDatabase.impl, GopDatabase.dbtype, GopDatabase.dbversion, GopDatabase.reflection_id, GopDatabase.status, GopDatabase.affinity, GopDatabase.desc ] option = None if slaves: columns.append(GopDatabase.slaves) option = joinedload(GopDatabase.slaves, innerjoin=False) results = resultutils.bulk_results(session, model=GopDatabase, columns=columns, counter=GopDatabase.database_id, order=order, desc=desc, option=option, filter=_filter, page_num=page_num) for column in results['data']: slaves = column.get('slaves', []) column['slaves'] = [] for slave in slaves: column['slaves'].append( dict(slave_id=slave.slave_id, master_id=column.get('database_id'), readonly=slave.readonly, ready=slave.ready)) return results
def index(self, req, body=None): """call buy client""" body = body or {} filter_list = [] session = get_session(readonly=True) agent_type = body.pop('agent_type', None) order = body.pop('order', None) desc = body.pop('desc', False) deleted = body.pop('deleted', False) page_num = body.pop('page_num', 0) if agent_type: filter_list.append(Agent.agent_type == agent_type) if not deleted: filter_list.append(Agent.status > manager_common.DELETED) else: filter_list.append(Agent.status <= manager_common.DELETED) agent_filter = and_(*filter_list) ret_dict = resultutils.bulk_results(session, model=Agent, columns=[Agent.agent_id, Agent.host, Agent.agent_type, Agent.status, Agent.cpu, Agent.memory, Agent.disk, # Agent.entitys, Agent.endpoints, Agent.create_time], counter=Agent.agent_id, order=order, desc=desc, option=joinedload(Agent.endpoints, innerjoin=False), filter=agent_filter, page_num=page_num) for column in ret_dict['data']: endpoints = column.get('endpoints') column['endpoints'] = [] for endpoint in endpoints: column['endpoints'].append(endpoint.endpoint) return ret_dict
def index(self, req, body=None): body = body or {} jsonutils.schema_validate(body, INDEXSCHEMA) session = get_session(readonly=True) order = body.get('order', None) desc = body.get('desc', False) status = body.get('status', None) page_num = body.pop('page_num', 0) filter_list = [] start = int(body.get('start', 0)) end = int(body.get('end', 0)) if start: filter_list.append(AsyncRequest.request_time >= end) if end: if end < start: raise InvalidArgument('end time less then start time') filter_list.append(AsyncRequest.request_time < end) if status is not None: filter_list.append(AsyncRequest.status == status) request_filter = and_(*filter_list) return resultutils.bulk_results(session, model=AsyncRequest, columns=[ AsyncRequest.request_id, AsyncRequest.resultcode, AsyncRequest.status, AsyncRequest.request_time, AsyncRequest.finishtime, AsyncRequest.deadline, AsyncRequest.expire, ], counter=AsyncRequest.request_id, order=order, desc=desc, filter=request_filter, page_num=page_num, limit=200)
def index(self, req, group_id, objtype, body=None): body = body or {} group_id = int(group_id) order = body.pop('order', None) desc = body.pop('desc', False) detail = body.pop('detail', False) packages = body.pop('packages', False) page_num = int(body.pop('page_num', 0)) session = endpoint_session(readonly=True) columns = [ AppEntity.entity, AppEntity.group_id, AppEntity.agent_id, AppEntity.opentime, AppEntity.platform, AppEntity.versions, AppEntity.status, AppEntity.objtype ] joins = None if objtype == common.GAMESERVER: columns.append(AppEntity.areas) joins = joinedload(AppEntity.areas, innerjoin=False) if packages: joins = joins.joinedload(GameArea.packages, innerjoin=False) def _databases(): _maps = {} if objtype != common.GAMESERVER: return _maps query = model_query(session, AreaDatabase) for _db in query: dbinfo = dict( quote_id=_db.quote_id, subtype=_db.subtype, host=_db.host, port=_db.port, ) try: _maps[_db.entity].append(dbinfo) except KeyError: _maps[_db.entity] = [ dbinfo, ] return _maps if detail: dth = eventlet.spawn(_databases) results = resultutils.bulk_results(session, model=AppEntity, columns=columns, counter=AppEntity.entity, order=order, desc=desc, option=joins, filter=and_( AppEntity.group_id == group_id, AppEntity.objtype == objtype), page_num=page_num) if detail: dbmaps = dth.wait() if not results['data']: return results emaps = entity_controller.shows( endpoint=common.NAME, entitys=[column.get('entity') for column in results['data']]) for column in results['data']: entity = column.get('entity') entityinfo = emaps.get(entity) if detail: try: column['databases'] = dbmaps[entity] except KeyError: LOG.error('Entity %d lose database' % entity) if column['agent_id'] != entityinfo.get('agent_id'): raise RuntimeError( 'Entity agent id %d not the same as %d' % (column['agent_id'], entityinfo.get('agent_id'))) areas = column.pop('areas', []) if objtype == common.GAMESERVER: _areas = [] for area in areas: _area = dict(area_id=area.area_id, show_id=area.show_id, gid=0, areaname=area.areaname) if packages: _area.setdefault( 'packages', [parea.package_id for parea in area.packages]) _areas.append(_area) areas = _areas column['areas'] = areas column['ports'] = entityinfo.get('ports') metadata = entityinfo.get('metadata') if metadata: local_ip = metadata.get('local_ip') external_ips = metadata.get('external_ips') else: local_ip = external_ips = None column['local_ip'] = local_ip column['external_ips'] = external_ips versions = column.get('versions') if versions: column['versions'] = jsonutils.loads_as_bytes(versions) return results