pcc/wwwroot/api/unit_release.dspy

20 lines
995 B
Plaintext

# 算力单元回收
# params: cluster_id, unit_name
cluster_id = params_kw.get('cluster_id', '')
unit_name = params_kw.get('unit_name', '')
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.release_unit(env, cluster_id, unit_name)
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}}