23 lines
1.2 KiB
Plaintext
23 lines
1.2 KiB
Plaintext
# 算力单元分配 (集群内部资源: K8s ns+quota / Slurm partition / Ray PlacementGroup)
|
|
# params: cluster_id, unit_name, cpu, memory, gpu(可选)
|
|
cluster_id = params_kw.get('cluster_id', '')
|
|
unit_name = params_kw.get('unit_name', '')
|
|
cpu = int(params_kw.get('cpu', 1))
|
|
memory = int(params_kw.get('memory', 4))
|
|
gpu = int(params_kw.get('gpu', 0))
|
|
if not cluster_id or not unit_name:
|
|
return {'widgettype': 'Error', 'options': {'title': '失败', 'message': 'Missing cluster_id or unit_name'}}
|
|
|
|
env = request._run_ns
|
|
dbname = env.get_module_dbname('pccs')
|
|
async with DBPools().sqlorContext(dbname) as sor:
|
|
recs = await sor.R('cluster', {'id': cluster_id})
|
|
if not recs:
|
|
return {'widgettype': 'Error', 'options': {'title': '失败', 'message': 'Cluster not found'}}
|
|
|
|
plugin = _get_plugin(recs[0].cluster_type)
|
|
result = await plugin.allocate_unit(env, cluster_id, unit_name, cpu, memory, gpu)
|
|
if result.get('status') == 'ok':
|
|
return {'widgettype': 'Message', 'options': {'title': '分配成功', 'message': result['message'], 'type': 'success', 'timeout': 5}}
|
|
return {'widgettype': 'Error', 'options': {'title': '分配失败', 'message': result.get('message', ''), 'cwidth': 16, 'cheight': 9, 'timeout': 3}}
|