Files
app-autotest/site/operations/get_instances.py
T

37 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
Операции с инстансами Nubes — получение списка и организации через API.
"""
from api.http_client import HttpClient
def get_instances(client):
"""GET /instances с пагинацией → ВСЕ инстансы пользователя.
pageSize=200 — максимум за один запрос.
Остановка по len(batch) < pageSize (НЕ доверяет total — бывали баги).
Возвращает полный list[dict]."""
results = []
page = 1
page_size = 200
while True:
data = client.get("/instances", params={"pageSize": page_size, "page": page})
batch = data.get("results", []) or []
results.extend(batch)
# Если страница неполная — данные закончились.
# Не проверяем total, потому что API иногда врёт про total.
if len(batch) < page_size:
break
page += 1
return results
def get_organization(client):
"""Первый инстанс с serviceId=19 (Организация).
Организация всегда одна на пользователя. Используется в UI: название, статус, ClientID."""
for inst in get_instances(client):
if inst.get("serviceId") == 19:
return inst
return None