27 lines
1.1 KiB
Plaintext
27 lines
1.1 KiB
Plaintext
# 查询集群已分配节点
|
|
# params: cluster_id (必填)
|
|
cluster_id = params_kw.get('cluster_id', '')
|
|
if not cluster_id:
|
|
return {'status': 'error', 'message': 'Missing cluster_id'}
|
|
|
|
env = request._run_ns
|
|
dbname = env.get_module_dbname('pccs')
|
|
async with DBPools().sqlorContext(dbname) as sor:
|
|
rows = await sor.sqlExe(
|
|
"SELECT cn.id as node_id, cn.name, cn.ip_address, cn.cpu_cores, cn.memory_gb, "
|
|
"cn.gpu_count, cn.gpu_type, cnn.role, cnn.status as node_status, cnn.assigned_at "
|
|
"FROM cluster_node cnn "
|
|
"JOIN compute_node cn ON cn.id = cnn.node_id "
|
|
"WHERE cnn.cluster_id = ${cid}$ AND cnn.status != 'removed' "
|
|
"ORDER BY cnn.role, cn.name",
|
|
{'cid': cluster_id}
|
|
)
|
|
result = [{
|
|
'node_id': r.node_id, 'name': r.name, 'ip_address': r.ip_address,
|
|
'cpu_cores': r.cpu_cores, 'memory_gb': r.memory_gb,
|
|
'gpu_count': r.gpu_count, 'gpu_type': r.gpu_type,
|
|
'role': r.role, 'status': r.node_status,
|
|
'assigned_at': str(r.assigned_at)
|
|
} for r in rows]
|
|
return {'status': 'ok', 'data': result, 'total': len(result)}
|