[WORK] Фундамент: порты как объекты + сигнальные цепочки, вендоры/домены, тесты движка (20/20), бэкап-таймер, стойка (EIA-310), IP-план, enricher LLM с цитатами, единицы

This commit is contained in:
root committed 2026-11-06 18:23:07 +03:00
1 parent 2b00676119
commit 8c16ba7c8c
9 files changed
+630 -4

No files matched your search

+11
View File
@@ -74,10 +74,21 @@ def matrix(q, body):
"hosts": [h["name"] for h in host_list]}
def vendors(q, body):
return {"vendors": C.vendors()}
def port_objects(q, body):
name = (q.get("name") or q.get("device") or [""])[0]
return {"device": name, "ports": C.port_objects(name)}
serve({
"/devices": devices,
"/device": device,
"/ports": ports,
"/hosts": hosts,
"/matrix": matrix,
"/vendors": vendors,
"/port-objects": port_objects,
}, int(sys.argv[1]) if len(sys.argv) > 1 else 8101, "catalog")
+55
View File
@@ -91,7 +91,62 @@ def cables(q, body):
return C.cable_schedule((q.get("host") or [""])[0], _items(q))
def rack(q, body):
"""Чертёж стойки (EIA-310: 1U = 44.45 мм)."""
items = _items(q)
U = 44.45
u = 1
rows = []
for r in items:
h = 1
name = r[0]
if any(x in name.lower() for x in ("mcore", "codec", "dsp", "ap08")):
h = 1
rows.append({"device": name, "qty": r[1], "u": h, "start_u": u})
u += h * r[1]
total_u = u + 1
W, px = 420, 70
H = int(total_u * px + 80)
parts = [f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {W} {H}">',
f'<rect x="0" y="0" width="{W}" height="{H}" fill="#0a0e13"/>',
f'<text x="14" y="24" fill="#e6edf3" font-size="13" font-weight="600">'
f'Стойка: {total_u}U (EIA-310, 1U=44.45 мм)</text>']
for r in rows:
y = 60 + (r["start_u"] - 1) * px
for n in range(r["qty"]):
yy = y + n * r["u"] * px
parts.append(f'<rect x="24" y="{yy}" width="{W-48}" height="{px-4}" rx="4" '
f'fill="#161b22" stroke="#2e4a6b"/>')
parts.append(f'<text x="34" y="{yy+26}" fill="#e6edf3" font-size="12">'
f'{_esc(r["device"])[:38]}</text>')
parts.append(f'<text x="{W-34}" y="{yy+26}" fill="#8b949e" font-size="10" '
f'text-anchor="end">U{r["start_u"]+n}</text>')
parts.append("</svg>")
return {"svg": "".join(parts), "total_u": total_u,
"height_mm": round(total_u * U, 1)}
def ipplan(q, body):
"""IP-план: выдаёт адреса по порядку для сетевых устройств."""
base = (q.get("net") or ["10.10.20."])[0]
start = int((q.get("start") or ["10"])[0])
items = _items(q)
rows, n = [], start
for r in items:
name, qty = r[0], r[1]
ins, outs, src = C.ports(name)
if "LAN" not in (ins + outs):
continue
for _ in range(qty):
rows.append({"device": name, "ip": "%s%d" % (base, n),
"purpose": "управление", "vlan": (q.get("vlan") or ["20"])[0]})
n += 1
return {"base": base, "rows": rows, "count": len(rows)}
serve({
"/diagram": diagram,
"/cables": cables,
"/rack": rack,
"/ipplan": ipplan,
}, int(sys.argv[1]) if len(sys.argv) > 1 else 8104, "draw")
+50 -1
View File
@@ -25,7 +25,7 @@ def groups(q, body):
if g["id"] == "infra":
for x in (C.infra.get("devices") or []):
items.append({"model": x["device"], "role": "infrastructure",
"max_qty": 4, "condition": x.get("why") or "",
"max_qty": 8, "condition": (x.get("evidence") or "")[:110],
"specs": x.get("specs") or {}})
out.append({"id": g["id"], "name": g["name"],
"hint": "PoE-коммутаторы и хабы", "items": items})
@@ -284,6 +284,51 @@ def xlsx(q, body):
"content_type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"}
def signals(q, body):
return C.signal_chains((q.get("host") or [""])[0], _items(q))
def port_objects(q, body):
name = (q.get("device") or [""])[0]
return {"device": name, "ports": C.port_objects(name)}
def review(q, body):
"""Ревью проекта: проблемы с серьёзностью, до закупки."""
hk = cc.norm((q.get("host") or [""])[0])
if hk not in C.devices:
return {"error": "хост не найден"}
items = _items(q)
issues = []
cap = C.capacity(hk, items, q.get("infra") or [])
for i in cap["issues"]:
issues.append({"level": "blocker", "text": i})
sig = C.signal_chains(hk, items)
for r in sig["chains"]:
if not r["ok"]:
issues.append({"level": "blocker",
"text": "%s: %s" % (r["device"], r["reason"])})
comp = C.completeness(hk)
if comp["level"] != "full":
issues.append({"level": "warning", "text": "неполные данные: " + comp["note"]})
if cap["missing_power"]:
issues.append({"level": "warning",
"text": "нет данных о питании: " + ", ".join(cap["missing_power"][:6])})
# крепления в комплекте
for r in items:
if C.mount_included(r[0]):
issues.append({"level": "info",
"text": "%s: крепление уже в комплекте" % r[0]})
blockers = sum(1 for i in issues if i["level"] == "blocker")
return {"host": C.devices[hk]["name"], "issues": issues,
"blockers": blockers, "warnings": sum(1 for i in issues if i["level"] == "warning"),
"ready": blockers == 0, "checks": len("checklist")}
def vendors(q, body):
return {"vendors": C.vendors()}
serve({
"/groups": groups,
"/check": check,
@@ -294,5 +339,9 @@ serve({
"/autofill": autofill,
"/accessory": accessory_hosts,
"/checklist": checklist,
"/signals": signals,
"/ports-objects": port_objects,
"/review": review,
"/vendors": vendors,
"/xlsx": xlsx,
}, int(sys.argv[1]) if len(sys.argv) > 1 else 8102, "engine")