67 lines
2.1 KiB
Plaintext
67 lines
2.1 KiB
Plaintext
async def obtaining_gpuinfo(params_kw={}):
|
|
ns = params_kw.copy()
|
|
cpcid = ns.get("cpcid")
|
|
clusterid = ns.get("clusterid")
|
|
#if not cpcid:
|
|
# return {'status': False,'msg': '无算力集群ID'}
|
|
|
|
debug(f'obtaining_gpuinfo.dspy:{ns=} {cpcid=} {clusterid=}')
|
|
if not ns.get('page'):
|
|
ns['page'] = 1
|
|
if not ns.get('sort'):
|
|
|
|
ns['sort'] = 'id'
|
|
|
|
sql = f'''select distinct id, model, stock, consumed, (stock-consumed) as avail_stock from cpcwidget where type="gpu"'''
|
|
if cpcid:
|
|
sql += f''' and cpcid="{cpcid}"'''
|
|
if clusterid:
|
|
sql += f''' and clusterid="{clusterid}"'''
|
|
|
|
filterjson = params_kw.get('data_filter')
|
|
if not filterjson:
|
|
fields = [ f['name'] for f in [
|
|
{
|
|
"name": "model",
|
|
"title": "显卡型号",
|
|
"type": "str"
|
|
},
|
|
{
|
|
"name": "stock",
|
|
"title": "库存量",
|
|
"type": "str"
|
|
},
|
|
{
|
|
"name": "avail_stock",
|
|
"title": "可用库存量",
|
|
"type": "str"
|
|
},
|
|
] ]
|
|
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 = 'kboss'
|
|
async with db.sqlorContext(dbname) as sor:
|
|
r = await sor.sqlPaging(sql, ns)
|
|
return {'status': True,'msg': '获取集群GPU资源库存成功','data': {row.model: row.avail_stock for row in r.get("rows")}}
|
|
return {'status': False,'msg': '获取集群GPU资源库存失败'}
|
|
|
|
ret = await obtaining_gpuinfo(params_kw)
|
|
return ret |