Compare commits
2 Commits
57e5c736c0
...
6acd5bd8e5
| Author | SHA1 | Date | |
|---|---|---|---|
| 6acd5bd8e5 | |||
| 76d22f5e7c |
57
models/components.json
Normal file
57
models/components.json
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
{
|
||||||
|
"summary": [
|
||||||
|
{
|
||||||
|
"name": "components",
|
||||||
|
"title": "部件表",
|
||||||
|
"primary": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"title": "id",
|
||||||
|
"type": "str",
|
||||||
|
"length": 32
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "name",
|
||||||
|
"title": "名称",
|
||||||
|
"type": "str",
|
||||||
|
"length": 255
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ccatelogid",
|
||||||
|
"title": "部件分类",
|
||||||
|
"type": "str",
|
||||||
|
"length": 255
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "cmodel",
|
||||||
|
"title": "型号",
|
||||||
|
"type": "str",
|
||||||
|
"length": 255
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "unitname",
|
||||||
|
"title": "计量名",
|
||||||
|
"type": "str",
|
||||||
|
"length": 32
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "unitvalue",
|
||||||
|
"title": "计量值",
|
||||||
|
"type": "short"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"codes": [
|
||||||
|
{
|
||||||
|
"field": "ccatelogid",
|
||||||
|
"table": "appcodes_kv",
|
||||||
|
"valuefield": "k",
|
||||||
|
"textfield": "v",
|
||||||
|
"cond": "parentid='ccatelog'"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
71
models/cpccluster.json
Normal file
71
models/cpccluster.json
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
{
|
||||||
|
"summary": [
|
||||||
|
{
|
||||||
|
"name": "cpccluster",
|
||||||
|
"title": "算力集群",
|
||||||
|
"primary": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"title": "id",
|
||||||
|
"type": "str",
|
||||||
|
"length": 32
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "name",
|
||||||
|
"title": "名称",
|
||||||
|
"type": "str",
|
||||||
|
"length": 255
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "cpcid",
|
||||||
|
"title": "算力中心id",
|
||||||
|
"type": "str",
|
||||||
|
"length": 32,
|
||||||
|
"nullable": "no"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "clustertype",
|
||||||
|
"title": "集群类型",
|
||||||
|
"type": "str",
|
||||||
|
"length": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "controllerid",
|
||||||
|
"title": "控制节点id",
|
||||||
|
"type": "str",
|
||||||
|
"length": 32
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "enable_date",
|
||||||
|
"title": "启用日期",
|
||||||
|
"type": "date",
|
||||||
|
"length": 255
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "export_date",
|
||||||
|
"title": "停用日期",
|
||||||
|
"type": "date",
|
||||||
|
"length": 255
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"codes": [
|
||||||
|
{
|
||||||
|
"field": "clustertype",
|
||||||
|
"table": "appcodes_kv",
|
||||||
|
"valuefield": "k",
|
||||||
|
"textfield": "v",
|
||||||
|
"cond": "parentid='clustertype'"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"field": "controllerid",
|
||||||
|
"table": "hostdev",
|
||||||
|
"valuefield": "id",
|
||||||
|
"textfield": "name"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
81
models/cpclist.json
Normal file
81
models/cpclist.json
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
{
|
||||||
|
"summary": [
|
||||||
|
{
|
||||||
|
"name": "cpclist",
|
||||||
|
"title": "算力中心列表",
|
||||||
|
"primary": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"title": "id",
|
||||||
|
"type": "str",
|
||||||
|
"length": 32
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "name",
|
||||||
|
"title": "名称",
|
||||||
|
"type": "str",
|
||||||
|
"length": 255
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "orgid",
|
||||||
|
"title": "属主机构id",
|
||||||
|
"type": "str",
|
||||||
|
"length": 32
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "pcapi_url",
|
||||||
|
"title": "pcapi网址",
|
||||||
|
"type": "str",
|
||||||
|
"length": 500
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "api_user",
|
||||||
|
"title": "接口用户",
|
||||||
|
"type": "str",
|
||||||
|
"length": 100
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "api_pwd",
|
||||||
|
"title": "接口密码",
|
||||||
|
"type": "str",
|
||||||
|
"length": 100
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "enable_date",
|
||||||
|
"title": "启用日期",
|
||||||
|
"type": "date",
|
||||||
|
"length": 255
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "expire_date",
|
||||||
|
"title": "停用日期",
|
||||||
|
"type": "date",
|
||||||
|
"length": 255
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "contactname",
|
||||||
|
"title": "联系人",
|
||||||
|
"type": "str",
|
||||||
|
"length": 100
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "contactphone",
|
||||||
|
"title": "联系电话",
|
||||||
|
"type": "str",
|
||||||
|
"length": 100
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"codes": [
|
||||||
|
{
|
||||||
|
"field": "orgid",
|
||||||
|
"table": "organization",
|
||||||
|
"valuefield": "id",
|
||||||
|
"textfield": "orgname"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
90
models/cpcnode.json
Normal file
90
models/cpcnode.json
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
{
|
||||||
|
"summary": [
|
||||||
|
{
|
||||||
|
"name": "cpcnode",
|
||||||
|
"title": "算力节点",
|
||||||
|
"primary": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"title": "id",
|
||||||
|
"type": "str",
|
||||||
|
"length": 32
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "name",
|
||||||
|
"title": "名称",
|
||||||
|
"type": "str",
|
||||||
|
"length": 255
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"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
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"codes": [
|
||||||
|
{
|
||||||
|
"field": "node_status",
|
||||||
|
"table": "appcodes_kv",
|
||||||
|
"valuefield": "k",
|
||||||
|
"textfield": "v",
|
||||||
|
"cond": "parentid='node_status'"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
45
models/cpcnode_config.json
Normal file
45
models/cpcnode_config.json
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
{
|
||||||
|
"summary": [
|
||||||
|
{
|
||||||
|
"name": "cpcnode_config",
|
||||||
|
"title": "节点配置表",
|
||||||
|
"primary": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"title": "id",
|
||||||
|
"type": "str",
|
||||||
|
"length": 32
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nodeid",
|
||||||
|
"title": "节点名称",
|
||||||
|
"type": "str",
|
||||||
|
"length": 32
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "name",
|
||||||
|
"title": "名称",
|
||||||
|
"type": "str",
|
||||||
|
"length": 255
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "description",
|
||||||
|
"title": "描述",
|
||||||
|
"type": "str",
|
||||||
|
"length": 3000
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"codes": [
|
||||||
|
{
|
||||||
|
"field": "nodeid",
|
||||||
|
"table": "cpnode",
|
||||||
|
"valuefield": "id",
|
||||||
|
"textfield": "name"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
49
models/cpcnode_config_detail.json
Normal file
49
models/cpcnode_config_detail.json
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
{
|
||||||
|
"summary": [
|
||||||
|
{
|
||||||
|
"name": "cpcnode_config_detail",
|
||||||
|
"title": "节点配置明细项",
|
||||||
|
"primary": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"title": "id",
|
||||||
|
"type": "str",
|
||||||
|
"length": 32
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "nodeconfigid",
|
||||||
|
"title": "节点配置id",
|
||||||
|
"type": "str",
|
||||||
|
"length": 32
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "comid",
|
||||||
|
"title": "部件id",
|
||||||
|
"type": "str",
|
||||||
|
"length": 32
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "comcnt",
|
||||||
|
"title": "部件数量",
|
||||||
|
"type": "short"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"codes": [
|
||||||
|
{
|
||||||
|
"field": "comid",
|
||||||
|
"table": "components",
|
||||||
|
"valuefield": "id",
|
||||||
|
"textfield": "name"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"field": "nodeconfigid",
|
||||||
|
"table": "cpnode_config",
|
||||||
|
"textfield": "name"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
52
models/cpvalue.json
Normal file
52
models/cpvalue.json
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
{
|
||||||
|
"summary": [
|
||||||
|
{
|
||||||
|
"name": "cpvalue",
|
||||||
|
"title": "算力值",
|
||||||
|
"primary": [
|
||||||
|
"id"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"title": "id",
|
||||||
|
"type": "str",
|
||||||
|
"length": 32
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "comid",
|
||||||
|
"title": "部件id",
|
||||||
|
"type": "str",
|
||||||
|
"length": 255
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "cpval",
|
||||||
|
"title": "算力值",
|
||||||
|
"type": "float",
|
||||||
|
"length": 18
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "cpunit",
|
||||||
|
"title": "算力单位",
|
||||||
|
"type": "str",
|
||||||
|
"length": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"codes": [
|
||||||
|
{
|
||||||
|
"field": "comid",
|
||||||
|
"table": "components",
|
||||||
|
"valuefield": "id",
|
||||||
|
"textfield": "name"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"field": "cpunit",
|
||||||
|
"table": "appcodes_kv",
|
||||||
|
"valuefield": "id",
|
||||||
|
"textfield": "value",
|
||||||
|
"cond": "parentid='cpunit'"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
128
scripts/load_path.py
Normal file
128
scripts/load_path.py
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
cpcc 模块 RBAC 权限管理脚本
|
||||||
|
|
||||||
|
使用方法:
|
||||||
|
cd ~/repos/sage
|
||||||
|
./py3/bin/python ~/cpcc/scripts/load_path.py
|
||||||
|
|
||||||
|
每次代码变更如有新 path 出现,需同步更新此脚本。
|
||||||
|
"""
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def find_sage_root():
|
||||||
|
candidates = [
|
||||||
|
os.path.expanduser("~/repos/sage"),
|
||||||
|
os.path.expanduser("~/sage"),
|
||||||
|
os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))),
|
||||||
|
]
|
||||||
|
for c in candidates:
|
||||||
|
if os.path.isdir(os.path.join(c, "py3")) and os.path.isdir(os.path.join(c, "wwwroot")):
|
||||||
|
return c
|
||||||
|
return None
|
||||||
|
|
||||||
|
SAGE_ROOT = find_sage_root()
|
||||||
|
if not SAGE_ROOT:
|
||||||
|
print("ERROR: Cannot find Sage root directory")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
PYTHON = os.path.join(SAGE_ROOT, "py3", "bin", "python")
|
||||||
|
SET_PERM_SCRIPT = os.path.join(SAGE_ROOT, "set_role_perm.py")
|
||||||
|
|
||||||
|
MOD = "cpcc"
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# 权限路径定义 — 每次新增页面或API时同步更新
|
||||||
|
# ============================================================
|
||||||
|
|
||||||
|
# any — 无需登录(菜单、登录页等)
|
||||||
|
PATHS_ANY = [
|
||||||
|
f"/cpcc/menu.ui",]
|
||||||
|
|
||||||
|
# logined — 需要认证的页面和 API
|
||||||
|
PATHS_LOGINED = [
|
||||||
|
f"/cpcc",
|
||||||
|
f"/cpcc/app_panel.ui",
|
||||||
|
f"/cpcc/bottom.ui",
|
||||||
|
f"/cpcc/center.ui",
|
||||||
|
f"/cpcc/components",
|
||||||
|
f"/cpcc/components/add_components.dspy",
|
||||||
|
f"/cpcc/components/delete_components.dspy",
|
||||||
|
f"/cpcc/components/get_components.dspy",
|
||||||
|
f"/cpcc/components/index.ui",
|
||||||
|
f"/cpcc/components/update_components.dspy",
|
||||||
|
f"/cpcc/cpccluster",
|
||||||
|
f"/cpcc/cpccluster/add_cpccluster.dspy",
|
||||||
|
f"/cpcc/cpccluster/delete_cpccluster.dspy",
|
||||||
|
f"/cpcc/cpccluster/get_cpccluster.dspy",
|
||||||
|
f"/cpcc/cpccluster/index.ui",
|
||||||
|
f"/cpcc/cpccluster/update_cpccluster.dspy",
|
||||||
|
f"/cpcc/cpclist",
|
||||||
|
f"/cpcc/cpclist/add_cpclist.dspy",
|
||||||
|
f"/cpcc/cpclist/delete_cpclist.dspy",
|
||||||
|
f"/cpcc/cpclist/get_cpclist.dspy",
|
||||||
|
f"/cpcc/cpclist/index.ui",
|
||||||
|
f"/cpcc/cpclist/update_cpclist.dspy",
|
||||||
|
f"/cpcc/cpcnode",
|
||||||
|
f"/cpcc/cpcnode/add_cpcnode.dspy",
|
||||||
|
f"/cpcc/cpcnode/delete_cpcnode.dspy",
|
||||||
|
f"/cpcc/cpcnode/get_cpcnode.dspy",
|
||||||
|
f"/cpcc/cpcnode/index.ui",
|
||||||
|
f"/cpcc/cpcnode/update_cpcnode.dspy",
|
||||||
|
f"/cpcc/cpcpod",
|
||||||
|
f"/cpcc/cpcpod/get_cpcpod.dspy",
|
||||||
|
f"/cpcc/cpcpod/get_node_labels.dspy",
|
||||||
|
f"/cpcc/cpcpod/index.ui",
|
||||||
|
f"/cpcc/cpcpod/new_cpcpodyaml.dspy",
|
||||||
|
f"/cpcc/cpcpod/new_podyaml.ui",
|
||||||
|
f"/cpcc/cpcpodyaml",
|
||||||
|
f"/cpcc/cpcpodyaml/delete_cpcpodyaml.dspy",
|
||||||
|
f"/cpcc/cpcpodyaml/get_cpcpodyaml.dspy",
|
||||||
|
f"/cpcc/cpcpodyaml/index.ui",
|
||||||
|
f"/cpcc/cpcpodyaml/update_cpcpodyaml.dspy",
|
||||||
|
f"/cpcc/cpcworker",
|
||||||
|
f"/cpcc/cpcworker/add_cpcworker.dspy",
|
||||||
|
f"/cpcc/cpcworker/delete_cpcworker.dspy",
|
||||||
|
f"/cpcc/cpcworker/get_availableworker.dspy",
|
||||||
|
f"/cpcc/cpcworker/get_cpcworker.dspy",
|
||||||
|
f"/cpcc/cpcworker/index.ui",
|
||||||
|
f"/cpcc/cpcworker/new_cpcworker.dspy",
|
||||||
|
f"/cpcc/cpcworker/new_worker.ui",
|
||||||
|
f"/cpcc/cpcworker/update_cpcworker.dspy",
|
||||||
|
f"/cpcc/handy",
|
||||||
|
f"/cpcc/handy/get_cpcnodes.dspy",
|
||||||
|
f"/cpcc/handy/new_cluster.dspy",
|
||||||
|
f"/cpcc/handy/new_cluster.ui",
|
||||||
|
f"/cpcc/index.ui",
|
||||||
|
f"/cpcc/top.ui",]
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# 执行注册
|
||||||
|
# ============================================================
|
||||||
|
|
||||||
|
def run_set_perm(role, path):
|
||||||
|
cmd = [PYTHON, SET_PERM_SCRIPT, role, path]
|
||||||
|
result = subprocess.run(cmd, capture_output=True, text=True)
|
||||||
|
return result.returncode == 0
|
||||||
|
|
||||||
|
def register_role_paths(role, paths):
|
||||||
|
count = 0
|
||||||
|
for p in paths:
|
||||||
|
if run_set_perm(role, p):
|
||||||
|
count += 1
|
||||||
|
print(f" {role}: {count}/{len(paths)} paths registered")
|
||||||
|
return count
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print(f"Sage root: {SAGE_ROOT}")
|
||||||
|
total = 0
|
||||||
|
total += register_role_paths("any", PATHS_ANY)
|
||||||
|
total += register_role_paths("logined", PATHS_LOGINED)
|
||||||
|
print(f"\nDone. Total {total} permission entries registered.")
|
||||||
|
print("NOTE: Restart Sage after permission changes to reload RBAC cache.")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
x
Reference in New Issue
Block a user