v1.0.81: get_params.py — current values from GET /instances/{uid} state.params
This commit is contained in:
+12
-44
@@ -8,6 +8,7 @@ from operations.get_services import get_services, get_service_detail
|
||||
from operations.get_instances import get_instances
|
||||
from operations.tracker import add as tracker_add, list_all as tracker_list
|
||||
from operations.tracker import remove as tracker_remove
|
||||
from operations.get_params import get_params_with_current_values
|
||||
|
||||
bp = Blueprint("api_test", __name__)
|
||||
|
||||
@@ -129,45 +130,20 @@ def api_operations(svc_id):
|
||||
|
||||
@bp.route("/api/params/<int:op_id>")
|
||||
def api_params(op_id):
|
||||
"""Параметры операции. Если передан instanceUid — с текущими значениями из API."""
|
||||
try:
|
||||
instance_uid = request.args.get("instanceUid")
|
||||
op_name = request.args.get("opName")
|
||||
_log(f"[api_params] op_id={op_id} instanceUid={instance_uid!r} opName={op_name!r}")
|
||||
_log(f"[api_params] op_id={op_id} instanceUid={instance_uid!r}")
|
||||
|
||||
if instance_uid and op_name:
|
||||
_log(f"[api_params] PREVIEW branch: creating operation for instance={instance_uid}")
|
||||
# ВАЖНО: без svcOperationId — API сам подтянет текущие paramValue из инстанса
|
||||
# (с svcOperationId — возвращает None для всех paramValue)
|
||||
op_payload = {"instanceUid": instance_uid, "operation": op_name}
|
||||
op_resp = _client().post("/instanceOperations", op_payload)
|
||||
preview_op_uid = _find_uid(op_resp) or _uid_from_location(op_resp.get("_location", ""))
|
||||
_log(f"[api_params] preview_op_uid={preview_op_uid!r}")
|
||||
if not preview_op_uid:
|
||||
return jsonify({"error": "Не удалось создать preview-операцию"}), 500
|
||||
if instance_uid:
|
||||
# Текущие значения: GET /instances/{uid} → state.params + шаблон → слияние
|
||||
result = get_params_with_current_values(_client(), op_id, instance_uid)
|
||||
_log(f"[api_params] MERGED returning {len(result)} params from state.params")
|
||||
for p in result:
|
||||
_log(f"[api_params] {p['name']}: defaultValue={p['defaultValue']!r}")
|
||||
return jsonify({"params": result})
|
||||
|
||||
op_data = _client().get(f"/instanceOperations/{preview_op_uid}")
|
||||
cfs_params = op_data.get("instanceOperation", {}).get("cfsParams", [])
|
||||
_log(f"[api_params] cfsParams count={len(cfs_params)}")
|
||||
|
||||
result = []
|
||||
for p in cfs_params:
|
||||
dd = p.get("dataDescriptor")
|
||||
pv = p.get("paramValue")
|
||||
dv = p.get("defaultValue")
|
||||
_log(f"[api_params] {p.get('svcOperationCfsParam')}: paramValue={pv!r} defaultValue={dv!r}")
|
||||
result.append({
|
||||
"svcOperationCfsParamId": p["svcOperationCfsParamId"],
|
||||
"name": p.get("svcOperationCfsParam", ""),
|
||||
"dataType": p.get("dataType", ""),
|
||||
"isRequired": p.get("isRequired", False),
|
||||
"defaultValue": pv, # текущее значение из инстанса
|
||||
"valueList": p.get("valueList"),
|
||||
"dataDescriptor": {k: {"dataType": v.get("dataType",""), "valueList": v.get("valueList",""), "isRequired": v.get("isRequired", False)} for k, v in dd.items()} if isinstance(dd, dict) else None,
|
||||
})
|
||||
_log(f"[api_params] PREVIEW returning {len(result)} params")
|
||||
return jsonify({"params": result, "previewOpUid": preview_op_uid})
|
||||
|
||||
# Без instanceUid — шаблонные значения по умолчанию
|
||||
# Без instanceUid — шаблонные значения по умолчанию (CREATE)
|
||||
_log(f"[api_params] DEFAULT branch: template defaults")
|
||||
data = _client().get(f"/instanceOperations/default/{op_id}")
|
||||
params = data["svcOperation"]["cfsParams"]
|
||||
@@ -204,7 +180,6 @@ def api_test():
|
||||
params = data.get("params", {})
|
||||
instance_uid = data.get("instanceUid")
|
||||
display_name = data.get("displayName") or ""
|
||||
preview_op_uid = data.get("previewOpUid")
|
||||
|
||||
client = _client()
|
||||
|
||||
@@ -247,14 +222,7 @@ def api_test():
|
||||
if not instance_uid:
|
||||
return jsonify({"status": "FAIL", "error": "Нет instanceUid"}), 400
|
||||
|
||||
if preview_op_uid:
|
||||
# Переиспользовать preview-операцию (уже создана в api_params)
|
||||
op_uid = preview_op_uid
|
||||
for pid, pval in params.items():
|
||||
client.post("/instanceOperationCfsParams",
|
||||
{"instanceOperationUid": op_uid, "svcOperationCfsParamId": int(pid), "paramValue": str(pval)})
|
||||
client.post(f"/instanceOperations/{op_uid}/run")
|
||||
elif op_name == "redeploy":
|
||||
if op_name == "redeploy":
|
||||
op_payload = {"instanceUid": instance_uid, "svcOperationId": svc_op_id, "operation": op_name}
|
||||
op_resp = client.post("/instanceOperations", op_payload)
|
||||
op_uid = _find_uid(op_resp) or _uid_from_location(op_resp.get("_location", ""))
|
||||
|
||||
Reference in New Issue
Block a user