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