refactor(hands): листание komodo становится публичным - им ходят и джобы
This commit is contained in:
1 parent
0ab77a6b69
commit
da237ec616
1 file changed
+16
-8
@@ -148,7 +148,7 @@ class Komodo:
|
||||
|
||||
async def _status(self) -> str:
|
||||
servers, stacks = await asyncio.gather(
|
||||
self._list("ListServers"), self._list("ListStacks")
|
||||
self.listing("ListServers"), self.listing("ListStacks")
|
||||
)
|
||||
lines = [f"{s['name']:24} {s['info']['state']}" for s in servers]
|
||||
bad = [s for s in stacks if s["info"]["state"] != "running"]
|
||||
@@ -165,7 +165,7 @@ class Komodo:
|
||||
return "\n".join(lines)
|
||||
|
||||
async def _stacks(self) -> str:
|
||||
stacks = await self._list("ListStacks")
|
||||
stacks = await self.listing("ListStacks")
|
||||
lines = []
|
||||
for s in sorted(stacks, key=lambda s: s["name"]):
|
||||
info = s["info"]
|
||||
@@ -181,11 +181,13 @@ class Komodo:
|
||||
|
||||
async def _containers(self, server: str | None) -> str:
|
||||
names = (
|
||||
[server] if server else [s["name"] for s in await self._list("ListServers")]
|
||||
[server]
|
||||
if server
|
||||
else [s["name"] for s in await self.listing("ListServers")]
|
||||
)
|
||||
lines = []
|
||||
for name in names:
|
||||
containers = await self._list("ListDockerContainers", {"server": name})
|
||||
containers = await self.listing("ListDockerContainers", {"server": name})
|
||||
lines.append(f"{name}:")
|
||||
lines.extend(
|
||||
f" {c['state']:10} {c['name']:36} {c.get('status', '')}"
|
||||
@@ -270,7 +272,7 @@ class Komodo:
|
||||
return out[:want], len(out) > want or page is not None
|
||||
|
||||
async def _resource_names(self) -> dict[str, str]:
|
||||
lists = await asyncio.gather(*(self._list(r) for r in RESOURCE_LISTS))
|
||||
lists = await asyncio.gather(*(self.listing(r) for r in RESOURCE_LISTS))
|
||||
return {r["id"]: r["name"] for rows in lists for r in rows}
|
||||
|
||||
async def _update(self, update_id: str) -> str:
|
||||
@@ -316,15 +318,21 @@ class Komodo:
|
||||
return f"{header}\n{self._clip(output.strip())}"
|
||||
|
||||
async def _server_of(self, container: str) -> str | None:
|
||||
for s in await self._list("ListServers"):
|
||||
containers = await self._list("ListDockerContainers", {"server": s["name"]})
|
||||
for s in await self.listing("ListServers"):
|
||||
containers = await self.listing(
|
||||
"ListDockerContainers", {"server": s["name"]}
|
||||
)
|
||||
if any(c["name"] == container for c in containers):
|
||||
return s["name"]
|
||||
return None
|
||||
|
||||
async def _list(
|
||||
async def listing(
|
||||
self, request: str, params: dict[str, Any] | None = None
|
||||
) -> list[Any]:
|
||||
"""Любой ``List*`` целиком: страницами, пока Komodo не отдаст неполную.
|
||||
|
||||
Публичная: этим же листанием ходят джобы, второго такого не пишем.
|
||||
"""
|
||||
out: list[Any] = []
|
||||
for page in range(LIST_PAGES):
|
||||
chunk = await self.read(
|
||||
|
||||
Reference in new issue
Block a user