def get_tenant_list_by_region(self, eid, region_id, page=1, page_size=10): teams = team_repo.get_team_by_enterprise_id(eid) team_maps = {} if teams: for team in teams: team_maps[team.tenant_id] = team res, body = region_api.list_tenants(eid, region_id, page, page_size) tenant_list = [] total = 0 if body.get("bean"): tenants = body.get("bean").get("list") total = body.get("bean").get("total") if tenants: for tenant in tenants: tenant_alias = team_maps.get(tenant["UUID"]).tenant_alias if team_maps.get(tenant["UUID"]) else '' tenant_list.append({ "tenant_id": tenant["UUID"], "team_name": tenant_alias, "tenant_name": tenant["Name"], "memory_request": tenant["memory_request"], "cpu_request": tenant["cpu_request"], "memory_limit": tenant["memory_limit"], "cpu_limit": tenant["cpu_limit"], "running_app_num": tenant["running_app_num"], "running_app_internal_num": tenant["running_app_internal_num"], "running_app_third_num": tenant["running_app_third_num"], "set_limit_memory": tenant["LimitMemory"], }) else: logger.error(body) return tenant_list, total
def list_all(self, query="", page=None, page_size=None): ents = enterprise_repo.list_all(query) total = ents.count() if total == 0: return [], 0 paginator = Paginator(ents, page_size) pp = paginator.page(page) data = [] for ent in pp: data.append({ "enterprise_id": ent.enterprise_id, "enterprise_name": ent.enterprise_name, "enterprise_alias": ent.enterprise_alias, "create_time": ent.create_time, "is_active": ent.is_active, "region_num": region_repo.get_regions_by_enterprise_id( ent.enterprise_id).count(), "user_num": user_repo.get_enterprise_users(ent.enterprise_id).count(), "team_num": team_repo.get_team_by_enterprise_id(ent.enterprise_id).count() }) return data, total
def get_regions_by_enterprise_id(self, enterprise_id): teams = team_repo.get_team_by_enterprise_id(enterprise_id) team_ids = [t.tenant_id for t in teams] region_names = region_repo.get_regions_by_tenant_ids(team_ids) return region_repo.get_region_by_region_names(region_names)