pcpool/wwwroot/api/node_allocate.dspy

29 lines
1.1 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 从算力池分配节点到集群 (算力单元分配)
# params:
# pool_id - 算力池 ID (必填)
# cluster_id - 目标集群 ID
# role - 节点角色: control/compute (默认 compute)
# count - 分配数量 (默认 1)
# cpu - 每节点 CPU 核数要求 (可选0 表示不限制)
# memory - 每节点内存 GB 要求 (可选)
# gpu - 每节点 GPU 数量要求 (可选)
# return: {status, allocated_nodes: [node_id, ...]}
result = await allocate_nodes(request, params_kw)
if isinstance(result, dict) and result.get('status') == 'ok':
return {
'widgettype': 'Message',
'options': {
'title': '分配成功',
'message': '已分配 {} 个节点:\n{}'.format(
len(result.get('allocated_nodes', [])),
', '.join(result.get('allocated_nodes', []))
),
'type': 'success',
'timeout': 5
}
}
return result if isinstance(result, dict) else {
'widgettype': 'Error',
'options': {'title': '分配失败', 'message': str(result), 'cwidth': 16, 'cheight': 9, 'timeout': 3}
}