init: pccs module skeleton — models, CRUD, API, load_path
This commit is contained in:
commit
a86dab8c58
68
scripts/load_path.py
Normal file
68
scripts/load_path.py
Normal file
@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env python3
|
||||
"""pccs RBAC 权限管理"""
|
||||
import subprocess, os, sys, json, glob
|
||||
|
||||
def find_sage_root():
|
||||
for c in [os.path.expanduser("~/sage"), os.path.expanduser("~/repos/sage")]:
|
||||
if os.path.isdir(os.path.join(c, "py3")): return c
|
||||
return None
|
||||
|
||||
SAGE = find_sage_root()
|
||||
if not SAGE: sys.exit("Sage root not found")
|
||||
PY = os.path.join(SAGE, "py3", "bin", "python")
|
||||
SET = os.path.join(SAGE, "set_role_perm.py")
|
||||
|
||||
JSON_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "json")
|
||||
API_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "wwwroot", "api")
|
||||
|
||||
def load_cruds():
|
||||
defs = []
|
||||
for f in sorted(glob.glob(os.path.join(JSON_DIR, "*.json"))):
|
||||
try:
|
||||
d = json.load(open(f))
|
||||
defs.append({"tblname": d["tblname"], "alias": d.get("alias", d["tblname"]), "subtables": d.get("params", {}).get("subtables", [])})
|
||||
except: pass
|
||||
return defs
|
||||
|
||||
def get_apis():
|
||||
if not os.path.isdir(API_DIR): return []
|
||||
return [f"/pccs/api/{f}" for f in sorted(os.listdir(API_DIR)) if f.endswith(".dspy")]
|
||||
|
||||
cruds = load_cruds()
|
||||
apis = get_apis()
|
||||
|
||||
PATHS_ANY = [
|
||||
f"/pccs/menu.ui",
|
||||
]
|
||||
PATHS_LOGINED = [
|
||||
f"/pccs",
|
||||
f"/pccs/index.ui",
|
||||
]
|
||||
for d in cruds:
|
||||
PATHS_ANY.append(f"/pccs/{d['alias']}")
|
||||
PATHS_LOGINED.append(f"/pccs/{d['alias']}/index.ui")
|
||||
for act in ["get", "add", "update", "delete"]:
|
||||
PATHS_LOGINED.append(f"/pccs/{d['alias']}/{act}_{d['tblname']}.dspy")
|
||||
for api in apis:
|
||||
PATHS_LOGINED.append(api)
|
||||
|
||||
PATHS_OPERATOR = list(PATHS_LOGINED)
|
||||
|
||||
PATHS_ANY = list(dict.fromkeys(PATHS_ANY))
|
||||
PATHS_LOGINED = list(dict.fromkeys(PATHS_LOGINED))
|
||||
PATHS_OPERATOR = list(dict.fromkeys(PATHS_OPERATOR))
|
||||
|
||||
def reg(role, paths):
|
||||
ok = 0
|
||||
for p in paths:
|
||||
r = subprocess.run([PY, SET, role, p], capture_output=True, text=True)
|
||||
if r.returncode == 0: ok += 1
|
||||
print(f" {role}: {ok}/{len(paths)}")
|
||||
return ok
|
||||
|
||||
total = 0
|
||||
print(f"{mod_name}: any={len(PATHS_ANY)} logined={len(PATHS_LOGINED)} operator={len(PATHS_OPERATOR)}")
|
||||
total += reg("any", PATHS_ANY)
|
||||
total += reg("logined", PATHS_LOGINED)
|
||||
total += reg("reseller.operator", PATHS_OPERATOR)
|
||||
print(f"Done. {total} entries.")
|
||||
8
setup.json
Normal file
8
setup.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "pccs",
|
||||
"version": "0.1.0",
|
||||
"description": "PCCS Sage 顶层模块 — 算力中心集群系统,聚合 pcpool + pcc",
|
||||
"packages": [],
|
||||
"install_requires": ["pcpool", "pcc"],
|
||||
"python_requires": ">=3.10"
|
||||
}
|
||||
19
wwwroot/menu.ui
Normal file
19
wwwroot/menu.ui
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"widgettype": "VBox",
|
||||
"options": {"width": "100%", "height": "100%"},
|
||||
"subwidgets": [
|
||||
{"widgettype": "Text", "options": {"otext": "算力中心集群系统", "i18n": true, "cfontsize": 1.5, "fontWeight": "bold", "margin": "10px"}},
|
||||
{"widgettype": "Tree", "id": "pccs_menu", "options": {
|
||||
"data": [
|
||||
{"id": "pool", "label": "算力池管理", "children": [
|
||||
{"id": "pool_list", "label": "算力池列表", "url": "/pcpool/compute_pool_list/index.ui"},
|
||||
{"id": "node_list", "label": "算力节点列表", "url": "/pcpool/compute_node_list/index.ui"}
|
||||
]},
|
||||
{"id": "cluster", "label": "集群管理", "children": [
|
||||
{"id": "cluster_list", "label": "集群列表", "url": "/pcc/cluster_list/index.ui"},
|
||||
{"id": "cn_list", "label": "节点分配", "url": "/pcc/cluster_node_list/index.ui"}
|
||||
]}
|
||||
]
|
||||
}}
|
||||
]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user