fix: разделение клиентов — сервисы из real API, инстансы/операции из polygon (v1.2.28)

This commit is contained in:
2026-08-01 09:22:02 +04:00
parent ca2367724e
commit dcd978808d
4 changed files with 54 additions and 29 deletions
+2 -2
View File
@@ -31,7 +31,7 @@ import json
import fcntl
from api.http_client import HttpClient, detect_endpoint, stand_name
from api.auth import get_token, get_client, get_client_id, get_stand, get_token_info
from api.auth import get_token, get_client, get_real_client, get_client_id, get_stand, get_token_info
from api.utils import find_uid, uid_from_location
from operations.get_services import get_services, get_service_detail
from operations.get_instances import get_instances
@@ -103,7 +103,7 @@ def _unique_display_name(client, requested_name):
@bp.route("/api/services")
def api_services():
try:
raw = get_services(get_client())
raw = get_services(get_real_client())
svc_list = [{"svcId": s["svcId"], "svc": s["svc"], "svcExtendedName": s.get("svcExtendedName", "")} for s in raw]
svc_list.sort(key=lambda s: s["svcId"])
return jsonify(svc_list)
+19 -15
View File
@@ -11,7 +11,7 @@ GET /api/operations/<svc_id> — операции и autotest-инста
from flask import Blueprint, current_app, render_template, request, make_response, jsonify, redirect
from api.http_client import HttpClient, detect_endpoint, create_client, stand_name
from api.auth import get_token, get_client_id, get_token_info, get_token_masked, get_client, get_stand
from api.auth import get_token, get_client_id, get_token_info, get_token_masked, get_client, get_real_client, get_stand
from operations.get_instances import get_organization, get_instances
from operations.get_services import get_services, get_service_detail
from operations.service_list import load_service_ids
@@ -105,24 +105,26 @@ def index():
config["service_ids"] = []
stand = "?"
if active_token:
# get_client — учитывает POLYGON_ENDPOINT
client = get_client()
# Сервисы — ВСЕГДА из реального API (метаданные)
real_client = get_real_client()
# Инстансы — из polygon если POLYGON_ENDPOINT задан
inst_client = get_client()
endpoint = current_app.config["NUBES_API_ENDPOINT"]
stand = get_stand()
if client:
if real_client:
try:
# Организация — инстанс с serviceId=19
org = get_organization(client)
# Организация — инстанс с serviceId=19 (из реального API)
org = get_organization(real_client)
# Все сервисы — сортировка по svcId
raw_svc = get_services(client)
# Все сервисы — из реального API
raw_svc = get_services(real_client)
services = sorted(raw_svc, key=lambda s: (s.get("svcId", 0), s.get("svc", "")))
# Инфраструктурные инстансы — только определённые serviceId
# Инфраструктурные инстансы — из polygon или реального API
# 19=Org, 21=vDC, 22=NSX-T, 25=External IP, 26=vApp, 29=vDC Group
# 2=Template, 12=S3, 110=?, 150=K8s
infra_ids = {2, 12, 21, 22, 25, 26, 29, 110, 150}
raw_inst = get_instances(client)
raw_inst = get_instances(inst_client)
instances = [i for i in raw_inst
if i.get("explainedStatus") not in ("deleted", "not created")
and i.get("serviceId") in infra_ids]
@@ -168,20 +170,22 @@ def api_operations(svc_id):
active_token = user_token or env_token
try:
# get_client — учитывает POLYGON_ENDPOINT
client = get_client()
# Сервисы — ВСЕГДА из реального API (метаданные)
real_client = get_real_client()
# Инстансы — из polygon если POLYGON_ENDPOINT задан
inst_client = get_client()
endpoint = current_app.config["NUBES_API_ENDPOINT"]
# Детали сервиса: список операций (modify, delete, suspend, ...)
detail = get_service_detail(client, svc_id)
detail = get_service_detail(real_client, svc_id)
ops = detail.get("operations", [])
# Трекер: наши autotest-инстансы (изолирован по пользователю и стенду)
tracked = tracker_list(get_client_id(), stand_name(endpoint))
tracked_by_uid = {t["instanceUid"]: t for t in tracked if t["svcId"] == svc_id}
# Все инстансы из облака
instances = get_instances(client)
# Все инстансы из polygon или реального API
instances = get_instances(inst_client)
nubes_uids = {i["instanceUid"] for i in instances}
svc_instances = []