v1.0.51: auto-detect stand (dev/test); init instance_groups; _finish_op full try/except

This commit is contained in:
2026-07-27 09:54:49 +04:00
parent a271e863f3
commit 1786bc67dd
4 changed files with 203 additions and 47 deletions
+43 -23
View File
@@ -8,6 +8,24 @@ from runner import load_config
bp = Blueprint("main", __name__)
STANDS = [
"https://lk-api-gateway-dev.ngcloud.ru/api/v1/svc",
"https://lk-api-gateway-test.ngcloud.ru/api/v1/svc",
]
def _detect_endpoint(token):
"""Пробуем токен против dev и test стендов, возвращаем рабочий URL."""
for ep in STANDS:
try:
c = HttpClient(ep, token)
data = c.get("/instances", params={"pageSize": 1, "page": 1})
if data.get("results") is not None:
return ep
except Exception:
continue
return None
def _mask(s):
if not s or len(s) < 8:
@@ -74,32 +92,34 @@ def index():
services = []
instances = []
instance_groups = {}
config = {}
if active_token:
try:
client = HttpClient(
current_app.config["NUBES_API_ENDPOINT"],
active_token,
)
org = get_organization(client)
raw_svc = get_services(client)
services = sorted(raw_svc, key=lambda s: (s.get("svcId", 0), s.get("svc", "")))
# инфраструктурные сервисы (платформа/среда)
infra_ids = {2, 12, 21, 22, 25, 26, 29, 110, 150}
raw_inst = get_instances(client)
instances = [i for i in raw_inst
if i.get("explainedStatus") not in ("deleted", "not created")
and i.get("serviceId") in infra_ids]
instances.sort(key=lambda i: (0 if i.get("serviceId") == 19 else 1, i.get("displayName", "")))
endpoint = _detect_endpoint(active_token)
if endpoint:
try:
client = HttpClient(endpoint, active_token)
org = get_organization(client)
raw_svc = get_services(client)
services = sorted(raw_svc, key=lambda s: (s.get("svcId", 0), s.get("svc", "")))
# инфраструктурные сервисы (платформа/среда)
infra_ids = {2, 12, 21, 22, 25, 26, 29, 110, 150}
raw_inst = get_instances(client)
instances = [i for i in raw_inst
if i.get("explainedStatus") not in ("deleted", "not created")
and i.get("serviceId") in infra_ids]
instances.sort(key=lambda i: (0 if i.get("serviceId") == 19 else 1, i.get("displayName", "")))
# group by service type
instance_groups = {}
for i in instances:
svc_name = i.get("svc", "Прочее")
instance_groups.setdefault(svc_name, []).append(i)
config = load_config()
except Exception as e:
error = str(e)
# group by service type
instance_groups = {}
for i in instances:
svc_name = i.get("svc", "Прочее")
instance_groups.setdefault(svc_name, []).append(i)
config = load_config()
except Exception as e:
error = str(e)
else:
error = "Токен невалиден или просрочен"
return render_template("index.html",
organization=org, error=error,