salescrm/b/cpcc/cpcpodyaml/get_cpcpodyaml.dspy
2025-10-27 15:50:44 +08:00

134 lines
3.7 KiB
Plaintext

async def get_cpcpodyaml(params_kw={}):
ns = params_kw.copy()
debug(f'获取资源实例静态配置入参:{ns=}')
cpcid = params_kw.cpcid
clusterid = params_kw.clusterid
if not ns.get('page'):
ns['page'] = 1
if not ns.get('sort'):
ns['sort'] = 'id'
sql = f'''SELECT yc.*, u.username from yaml_config as yc join users as u on yc.userid = u.id where cpcid="{cpcid}" and clusterid="{clusterid}"'''
filterjson = params_kw.get('data_filter')
if not filterjson:
fields = [ f['name'] for f in [
{
"name": "id",
"title": "id",
"type": "str",
"length": 32
},
{
"name": "name",
"title": "名称",
"type": "str",
"length": 255
},
{
"name": "devicetype",
"title": "设备类型",
"type": "str",
"length": 1
},
{
"name": "ip",
"title": "内网ip",
"type": "str",
"length": 90
},
{
"name": "sshport",
"title": "ssh端口号",
"type": "short"
},
{
"name": "adminuser",
"title": "管理账号",
"type": "str",
"length": 99
},
{
"name": "adminpwd",
"title": "管理密码",
"type": "str",
"length": 99
},
{
"name": "cpcid",
"title": "算力中心id",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "node_status",
"title": "节点状态",
"type": "str",
"length": 1,
"nullable": "yes"
},
{
"name": "clusterid",
"title": "所属集群",
"type": "long",
"length": 32,
"nullable": "yes"
},
{
"name": "enable_date",
"title": "启用日期",
"type": "date",
"length": 255
},
{
"name": "export_date",
"title": "停用日期",
"type": "date",
"length": 255
}
] ]
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 = await rfexe('get_module_dbname', 'cpcc')
dbname = 'kboss'
async with db.sqlorContext(dbname) as sor:
cpcs = await sor.R('cpclist', {'id':cpcid})
# 判断是否无人操作
if len(cpcs) < 1:
e = Exception(f'cpclist {cpcid=} not exists')
exception(f'{e}')
raise e
cpclusters = await sor.R('cpccluster', {'id':clusterid})
if len(cpclusters) < 1:
e = Exception(f'cpclist {clusterid=} not exists')
raise e
r = await sor.sqlPaging(sql, ns)
return {'status': True,'msg': '获取资源实例静态配置成功','data': r}
return {'status': False,'msg': '获取资源实例静态配置失败'}
ret = await get_cpcpodyaml(params_kw)
return ret