107 lines
2.7 KiB
Plaintext
107 lines
2.7 KiB
Plaintext
|
|
ns = params_kw.copy()
|
|
|
|
|
|
userorgid = await get_userorgid()
|
|
if not userorgid:
|
|
return {
|
|
"widgettype":"Error",
|
|
"options":{
|
|
"title":"Authorization Error",
|
|
"timeout":3,
|
|
"cwidth":16,
|
|
"cheight":9,
|
|
"message":"Please login"
|
|
}
|
|
}
|
|
ns['resellerid'] = userorgid
|
|
ns['userorgid'] = userorgid
|
|
|
|
debug(f'get_cluster_node.dspy:{ns=}')
|
|
if not ns.get('page'):
|
|
ns['page'] = 1
|
|
if not ns.get('sort'):
|
|
|
|
ns['sort'] = 'id'
|
|
|
|
|
|
sql = '''select a.*, b.cluster_id_text, c.node_id_text, d.role_text, e.status_text
|
|
from (select * from cluster_node where 1=1 [[filterstr]]) a left join (select id as cluster_id,
|
|
name as cluster_id_text from cluster where 1 = 1) b on a.cluster_id = b.cluster_id left join (select id as node_id,
|
|
name as node_id_text from compute_node where 1 = 1) c on a.node_id = c.node_id left join (select k as role,
|
|
v as role_text from appcodes_kv where parentid='node_role') d on a.role = d.role left join (select k as status,
|
|
v as status_text from appcodes_kv where parentid='node_status') e on a.status = e.status'''
|
|
|
|
filterjson = params_kw.get('data_filter')
|
|
if not filterjson:
|
|
fields = [ f['name'] for f in [
|
|
{
|
|
"name": "id",
|
|
"title": "id",
|
|
"type": "str",
|
|
"length": 32,
|
|
"nullable": "no"
|
|
},
|
|
{
|
|
"name": "cluster_id",
|
|
"title": "所属集群",
|
|
"type": "str",
|
|
"length": 32,
|
|
"nullable": "no"
|
|
},
|
|
{
|
|
"name": "node_id",
|
|
"title": "算力节点",
|
|
"type": "str",
|
|
"length": 32,
|
|
"nullable": "no"
|
|
},
|
|
{
|
|
"name": "role",
|
|
"title": "角色(control/compute/storage)",
|
|
"type": "char",
|
|
"length": 16,
|
|
"nullable": "no"
|
|
},
|
|
{
|
|
"name": "status",
|
|
"title": "状态(joining/active/draining/removed)",
|
|
"type": "char",
|
|
"length": 16,
|
|
"default": "joining"
|
|
},
|
|
{
|
|
"name": "assigned_at",
|
|
"title": "分配时间",
|
|
"type": "timestamp",
|
|
"nullable": "no"
|
|
}
|
|
] ]
|
|
filterjson = default_filterjson(fields, ns)
|
|
filterdic = ns.copy()
|
|
filterdic['filterstr'] = ''
|
|
filterdic['userorgid'] = '${userorgid}$'
|
|
filterdic['userid'] = '${userid}$'
|
|
if filterjson:
|
|
dbf = DBFilter(filterjson)
|
|
conds = dbf.gen(ns)
|
|
if conds:
|
|
ns.update(dbf.consts)
|
|
conds = f' and {conds}'
|
|
filterdic['filterstr'] = conds
|
|
ac = ArgsConvert('[[', ']]')
|
|
vars = ac.findAllVariables(sql)
|
|
NameSpace = {v:'${' + v + '}$' for v in vars if v != 'filterstr' }
|
|
filterdic.update(NameSpace)
|
|
sql = ac.convert(sql, filterdic)
|
|
|
|
debug(f'{sql=}')
|
|
db = DBPools()
|
|
dbname = get_module_dbname('pcc')
|
|
async with db.sqlorContext(dbname) as sor:
|
|
r = await sor.sqlPaging(sql, ns)
|
|
return r
|
|
return {
|
|
"total":0,
|
|
"rows":[]
|
|
} |