v1.2.0: unified executor + flexible instance refs + params-render.js
Phase 1 — New modules: - api/utils.py: find_uid(), uid_from_location() (replaces 2 duplicates) - operations/poll.py: poll_until_done() (shared sync/async polling) - operations/executor.py: execute_operation() (single CREATE/non-CREATE flow) Phase 2 — Format + validation: - routes/api_scenario_defs.py: _validate_steps with output/instance_ref/instance_uid - operations/scenario.py: resolve instance_uid > instance_ref > service_id, use executor + poll_until_done, persist instance_bindings Phase 3 — Migration: - routes/api_test.py: create/non-create through executor, _finish_op through poll_until_done - db/init_db.py: startup cleanup of stuck scenario_runs (>1h) Phase 4 — UI shared module: - static/js/params-render.js: renderParamRow, renderMapFixedRow, collectParams - static/js/operations.js: use params-render.js (remove duplicates) - templates/index.html: include params-render.js - app.py: bump 1.1.57 → 1.2.0
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
"""
|
||||
Общие утилиты: извлечение UUID из ответов API Nubes.
|
||||
|
||||
Используется: api_test.py, scenario.py, executor.py.
|
||||
Заменяет разрозненные реализации _find_uid / _uid_from_location.
|
||||
"""
|
||||
|
||||
|
||||
def find_uid(resp):
|
||||
"""Извлечь instanceUid или instanceOperationUid из ответа API.
|
||||
|
||||
Ищет в нескольких местах:
|
||||
1. На верхнем уровне: instanceOperationUid → instanceUid → uid → Uid
|
||||
2. Во вложенных dict-значениях: {key: {instanceOperationUid: ..., instanceUid: ...}}
|
||||
"""
|
||||
if not isinstance(resp, dict):
|
||||
return None
|
||||
# Верхний уровень — прямые ключи (api_test.py-стиль)
|
||||
for key in ("instanceOperationUid", "instanceUid", "uid", "Uid"):
|
||||
v = resp.get(key)
|
||||
if isinstance(v, str) and v:
|
||||
return v
|
||||
# Вложенные dict-значения (scenario.py-стиль)
|
||||
for v in resp.values():
|
||||
if isinstance(v, dict):
|
||||
uid = v.get("instanceOperationUid") or v.get("instanceUid")
|
||||
if uid:
|
||||
return uid
|
||||
return None
|
||||
|
||||
|
||||
def uid_from_location(loc):
|
||||
"""Извлечь UUID из Location-заголовка.
|
||||
|
||||
Location бывает: "./UUID", "/api/v1/svc/instances/UUID", "/api/v1/svc/instanceOperations/UUID"
|
||||
Берём последний сегмент после split("/").
|
||||
"""
|
||||
if not loc:
|
||||
return None
|
||||
parts = str(loc).rstrip("/").split("/")
|
||||
uid = parts[-1]
|
||||
# UUID — 36 символов с 4 дефисами (уже проверено в http_client.py)
|
||||
if uid and uid != "." and len(uid) >= 32:
|
||||
return uid
|
||||
return None
|
||||
Reference in New Issue
Block a user