v1.0.76: modify shows actual instance param values (preview operation)
This commit is contained in:
+41
-3
@@ -100,10 +100,40 @@ def api_operations(svc_id):
|
||||
@bp.route("/api/params/<int:op_id>")
|
||||
def api_params(op_id):
|
||||
try:
|
||||
instance_uid = request.args.get("instanceUid")
|
||||
op_name = request.args.get("opName")
|
||||
|
||||
if instance_uid and op_name:
|
||||
# Создать pending-операцию чтобы прочитать ТЕКУЩИЕ значения параметров инстанса
|
||||
op_payload = {"instanceUid": instance_uid, "svcOperationId": op_id, "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", ""))
|
||||
if not preview_op_uid:
|
||||
return jsonify({"error": "Не удалось создать preview-операцию"}), 500
|
||||
|
||||
op_data = _client().get(f"/instanceOperations/{preview_op_uid}")
|
||||
cfs_params = op_data.get("instanceOperation", {}).get("cfsParams", [])
|
||||
|
||||
result = []
|
||||
for p in cfs_params:
|
||||
dd = p.get("dataDescriptor")
|
||||
result.append({
|
||||
"svcOperationCfsParamId": p["svcOperationCfsParamId"],
|
||||
"name": p.get("svcOperationCfsParam", ""),
|
||||
"dataType": p.get("dataType", ""),
|
||||
"isRequired": p.get("isRequired", False),
|
||||
"defaultValue": p.get("paramValue"), # текущее значение из инстанса
|
||||
"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,
|
||||
})
|
||||
return jsonify({"params": result, "previewOpUid": preview_op_uid})
|
||||
|
||||
# Без instanceUid — шаблонные значения по умолчанию
|
||||
data = _client().get(f"/instanceOperations/default/{op_id}")
|
||||
params = data["svcOperation"]["cfsParams"]
|
||||
result = []
|
||||
for p in params:
|
||||
dd = p.get("dataDescriptor")
|
||||
result.append({
|
||||
"svcOperationCfsParamId": p["svcOperationCfsParamId"],
|
||||
"name": p.get("svcOperationCfsParam", ""),
|
||||
@@ -111,9 +141,9 @@ def api_params(op_id):
|
||||
"isRequired": p.get("isRequired", False),
|
||||
"defaultValue": p.get("defaultValue"),
|
||||
"valueList": p.get("valueList"),
|
||||
"dataDescriptor": {k: {"dataType": v.get("dataType",""), "valueList": v.get("valueList",""), "isRequired": v.get("isRequired", False)} for k, v in p.get("dataDescriptor", {}).items()} if p.get("dataDescriptor") else None,
|
||||
"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,
|
||||
})
|
||||
return jsonify(result)
|
||||
return jsonify({"params": result})
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
@@ -130,6 +160,7 @@ 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()
|
||||
|
||||
@@ -172,7 +203,14 @@ def api_test():
|
||||
if not instance_uid:
|
||||
return jsonify({"status": "FAIL", "error": "Нет instanceUid"}), 400
|
||||
|
||||
if op_name == "redeploy":
|
||||
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":
|
||||
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