v1.1.14: serviceId filter, svcShort displayName, descr, remove duplicate endpoint
This commit is contained in:
+1
-1
@@ -18,7 +18,7 @@ from routes.api import bp as api_bp
|
||||
from routes.api_test import bp as api_test_bp
|
||||
|
||||
# Версия — меняется при КАЖДОМ изменении кода. Показывается в топбаре UI.
|
||||
VERSION = "1.1.13"
|
||||
VERSION = "1.1.14"
|
||||
|
||||
app = Flask(__name__, template_folder="templates", static_folder="static")
|
||||
app.config["NUBES_API_ENDPOINT"] = os.getenv("NUBES_API_ENDPOINT", "https://lk-api-gateway-test.ngcloud.ru/api/v1/svc")
|
||||
|
||||
+2
-34
@@ -115,39 +115,6 @@ def api_instances_list():
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
|
||||
@bp.route("/api/operations/<int:svc_id>")
|
||||
def api_operations(svc_id):
|
||||
try:
|
||||
detail = get_service_detail(get_client(), svc_id)
|
||||
ops = detail.get("operations", [])
|
||||
# только отслеживаемые инстансы этого сервиса
|
||||
tracked = tracker_list(get_client_id(), get_stand())
|
||||
tracked_by_uid = {t["instanceUid"]: t for t in tracked if t["svcId"] == svc_id}
|
||||
tracked_uids = set(tracked_by_uid.keys())
|
||||
instances = get_instances(get_client())
|
||||
nubes_uids = {i["instanceUid"] for i in instances}
|
||||
svc_instances = [i for i in instances
|
||||
if i.get("instanceUid") in tracked_uids
|
||||
and i.get("explainedStatus") not in ("deleted",)]
|
||||
# Добавить tracked инстансы, которых Nubes ещё не отдаёт (creating)
|
||||
for uid, t in tracked_by_uid.items():
|
||||
if uid not in nubes_uids:
|
||||
svc_instances.append({
|
||||
"instanceUid": uid,
|
||||
"displayName": t["displayName"],
|
||||
"serviceId": svc_id,
|
||||
"svc": detail.get("svc", ""),
|
||||
"explainedStatus": "creating",
|
||||
})
|
||||
return jsonify({
|
||||
"svc": detail.get("svc", ""),
|
||||
"operations": [{"svcOperationId": o["svcOperationId"], "operation": o["operation"]} for o in ops],
|
||||
"instances": svc_instances,
|
||||
})
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
|
||||
@bp.route("/api/params/<int:op_id>")
|
||||
def api_params(op_id):
|
||||
"""Параметры операции. Если передан instanceUid — с текущими значениями из API."""
|
||||
@@ -209,7 +176,8 @@ def api_test():
|
||||
if not display_name:
|
||||
display_name = f"autotest-{svc_id}"
|
||||
display_name = _unique_display_name(client, display_name)
|
||||
payload = {"serviceId": svc_id, "displayName": display_name, "descr": ""}
|
||||
descr = f"created by autotest v{current_app.config.get('VERSION', '')}"
|
||||
payload = {"serviceId": svc_id, "displayName": display_name, "descr": descr}
|
||||
resp = client.post("/instances", payload)
|
||||
instance_uid = resp.get("instanceUid") or _find_uid(resp) or _uid_from_location(resp.get("_location", ""))
|
||||
if not instance_uid:
|
||||
|
||||
@@ -194,6 +194,8 @@ def api_operations(svc_id):
|
||||
display_name = str(i.get("displayName", "") or "")
|
||||
if not display_name.startswith(AUTOTEST_PREFIX):
|
||||
continue # не наш инстанс
|
||||
if i.get("serviceId") != svc_id:
|
||||
continue # не нашего сервиса
|
||||
if i.get("explainedStatus") in ("deleted",):
|
||||
continue # удалённые не показываем
|
||||
item = dict(i)
|
||||
@@ -220,6 +222,7 @@ def api_operations(svc_id):
|
||||
|
||||
return jsonify({
|
||||
"svc": detail.get("svc", ""),
|
||||
"svcShort": detail.get("svcShort", ""),
|
||||
"operations": ops, # [{svcOperationId, operation}, ...]
|
||||
"instances": svc_instances, # [{instanceUid, displayName, status, ...}, ...]
|
||||
})
|
||||
|
||||
+3
-2
@@ -47,6 +47,7 @@ async function selectService(svcId){
|
||||
const d=await r.json();
|
||||
svcInstances=d.instances||[];
|
||||
currentSvcName=d.svc||'';
|
||||
currentSvcShort=d.svcShort||'';
|
||||
// Обновить текст кнопки создания
|
||||
const btnSpan=document.querySelector('#create-btn-area span');
|
||||
if(btnSpan) btnSpan.textContent='+ Создать новый инстанс '+(currentSvcName||'сервиса');
|
||||
@@ -110,8 +111,8 @@ async function startCreate(){
|
||||
}
|
||||
|
||||
function makeCreateDisplayName(){
|
||||
const suffix = Date.now().toString(36);
|
||||
return suffix;
|
||||
const rand = (Math.random() * 46656 | 0).toString(36).padStart(3, '0');
|
||||
return currentSvcShort ? currentSvcShort+'-'+rand : rand;
|
||||
}
|
||||
|
||||
function runOp(opName,opId){
|
||||
|
||||
Reference in New Issue
Block a user