Fix: 2-step create + run, paginated get_instances, v1.0.22
This commit is contained in:
+1
-1
@@ -6,7 +6,7 @@ from routes.main import bp as main_bp
|
||||
from routes.api import bp as api_bp
|
||||
from routes.api_test import bp as api_test_bp
|
||||
|
||||
VERSION = "1.0.21"
|
||||
VERSION = "1.0.22"
|
||||
|
||||
app = Flask(__name__, template_folder="templates", static_folder="static")
|
||||
app.config["NUBES_API_ENDPOINT"] = os.getenv("NUBES_API_ENDPOINT", "https://lk-api-gateway-dev.ngcloud.ru/api/v1/svc")
|
||||
|
||||
@@ -2,8 +2,15 @@ from api.http_client import HttpClient
|
||||
|
||||
|
||||
def get_instances(client):
|
||||
data = client.get("/instances", params={"pageSize": 200})
|
||||
return data.get("results", [])
|
||||
results = []
|
||||
page = 1
|
||||
while True:
|
||||
data = client.get("/instances", params={"pageSize": 200, "page": page})
|
||||
results.extend(data.get("results", []))
|
||||
if len(results) >= data.get("total", 0):
|
||||
break
|
||||
page += 1
|
||||
return results
|
||||
|
||||
|
||||
def get_organization(client):
|
||||
|
||||
+21
-9
@@ -93,12 +93,15 @@ def api_test():
|
||||
payload = {"serviceId": svc_id, "displayName": display_name, "descr": "autotest"}
|
||||
# cfsParams — отдельным шагом, не в POST /instances
|
||||
resp = client.post("/instances", payload)
|
||||
instance_uid = resp.get("instanceUid") or _find_uid(resp)
|
||||
# Location header: /instances/{uid}
|
||||
loc = resp.get("_location", "")
|
||||
if not instance_uid and loc:
|
||||
parts = loc.rstrip("/").split("/")
|
||||
instance_uid = parts[-1] if len(parts[-1]) == 36 else None
|
||||
instance_uid = resp.get("instanceUid") or _find_uid(resp) or _uid_from_location(resp.get("_location", ""))
|
||||
|
||||
# Шаг 2: запустить операцию create
|
||||
if instance_uid:
|
||||
op_resp = client.post("/instanceOperations", {"instanceUid": instance_uid, "operation": "create"})
|
||||
# run
|
||||
op_uid = _find_uid(op_resp) or _uid_from_location(op_resp.get("_location", ""))
|
||||
if op_uid:
|
||||
client.post(f"/instanceOperations/{op_uid}/run")
|
||||
|
||||
# wait
|
||||
deadline = time.time() + 300
|
||||
@@ -116,10 +119,11 @@ def api_test():
|
||||
else:
|
||||
if not instance_uid:
|
||||
return jsonify({"status": "FAIL", "error": "Нет instanceUid"}), 400
|
||||
payload = {"instanceUid": instance_uid, "svcOperationId": svc_op_id}
|
||||
# все операции: {instanceUid, operation}
|
||||
op_payload = {"instanceUid": instance_uid, "operation": op_name}
|
||||
if params:
|
||||
payload["cfsParams"] = [{"svcOperationCfsParamId": int(k), "paramValue": str(v)} for k, v in params.items()]
|
||||
client.post("/instanceOperations", payload)
|
||||
op_payload["cfsParams"] = [{"svcOperationCfsParamId": int(k), "paramValue": str(v)} for k, v in params.items()]
|
||||
client.post("/instanceOperations", op_payload)
|
||||
|
||||
deadline = time.time() + 300
|
||||
while time.time() < deadline:
|
||||
@@ -149,3 +153,11 @@ def _find_uid(resp):
|
||||
if isinstance(v, str) and len(v) == 36 and v.count("-") == 4:
|
||||
return v
|
||||
return None
|
||||
|
||||
|
||||
def _uid_from_location(loc):
|
||||
if loc:
|
||||
parts = loc.rstrip("/").split("/")
|
||||
if len(parts[-1]) == 36:
|
||||
return parts[-1]
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user