Enhance access link collection and backend status reporting

- Updated the `collect_access_links` function to provide clearer user-facing endpoint labels and notes, particularly for non-tunneled scenarios.
- Improved logging messages in the provisioning process to reflect the status of the SwarmUI and Ollama API, enhancing user feedback during setup.
- Added human-readable status messages for backend loading and running states, improving clarity during the waiting process.
- Updated tests to verify the new behavior and ensure accurate reporting of access links and backend statuses.
This commit is contained in:
Leonid Pershin
2026-08-21 09:34:13 +03:00
parent a622265bb5
commit 281ae15b12
5 changed files with 85 additions and 47 deletions
+52 -43
View File
@@ -39,52 +39,60 @@ def resolve_llm_runtime(cfg: Config) -> str:
def collect_access_links(cfg: Config, *, tunneled: bool) -> list[AccessLink]:
"""Build the list of user-facing endpoints (unit-tested)."""
"""Build the list of user-facing endpoints (unit-tested).
When ``tunneled`` is False, still lists the same localhost URLs with a
«после tunnel» note — useful mid-``up`` before SSH forward is up.
"""
links: list[AccessLink] = []
swarm = bool(getattr(cfg, "enable_swarmui", True))
if tunneled:
if swarm:
port = cfg.swarmui_local_port
base = f"http://127.0.0.1:{port}"
links.extend(
[
AccessLink("SwarmUI UI", base, "браузер"),
AccessLink("SwarmUI API", f"{base}/API/", "HTTP JSON"),
AccessLink("SwarmUI MCP", f"{base}/mcp", "Cursor mcp.json"),
]
)
runtime = resolve_llm_runtime(cfg)
if runtime == "ollama":
o = cfg.ollama_local_port
links.extend(
[
AccessLink(
"Ollama API",
f"http://127.0.0.1:{o}",
f"OLLAMA_HOST=http://127.0.0.1:{o}",
),
AccessLink("Ollama tags", f"http://127.0.0.1:{o}/api/tags", "список моделей"),
AccessLink(
"Ollama chat",
f"http://127.0.0.1:{o}/api/chat",
"POST generate",
),
]
)
if not links:
links.append(
soon = "" if tunneled else "после tunnel"
if swarm:
port = cfg.swarmui_local_port
base = f"http://127.0.0.1:{port}"
links.extend(
[
AccessLink("SwarmUI UI", base, soon or "браузер"),
AccessLink("SwarmUI API", f"{base}/API/", soon or "HTTP JSON"),
AccessLink("SwarmUI MCP", f"{base}/mcp", soon or "Cursor mcp.json"),
]
)
runtime = resolve_llm_runtime(cfg)
if runtime == "ollama":
o = cfg.ollama_local_port
links.extend(
[
AccessLink(
"Туннель",
"gpu-rent tunnel",
"нет сервисов — ENABLE_SWARMUI / LLM_RUNTIME",
)
)
else:
"Ollama API",
f"http://127.0.0.1:{o}",
soon or f"OLLAMA_HOST=http://127.0.0.1:{o}",
),
AccessLink(
"Ollama tags",
f"http://127.0.0.1:{o}/api/tags",
soon or "список моделей",
),
AccessLink(
"Ollama chat",
f"http://127.0.0.1:{o}/api/chat",
soon or "POST generate",
),
]
)
if not links:
links.append(
AccessLink(
"Туннель",
"gpu-rent tunnel --open",
"локальные URL появятся после tunnel",
"gpu-rent tunnel",
"нет сервисов — ENABLE_SWARMUI / LLM_RUNTIME",
)
)
elif not tunneled:
links.append(
AccessLink(
"Сейчас",
"ждём Idle → туннель",
"не открывай :7801 на ноутбуке — только :17801 после tunnel",
)
)
return links
@@ -139,7 +147,7 @@ def render_access_panel(
if host:
subtitle.append(f" · VM {host}", style="dim")
else:
subtitle.append("облако готово, туннеля нет", style="yellow")
subtitle.append("URL ниже — после Idle откроется туннель", style="yellow")
if host:
subtitle.append(f" · FIP {host}", style="dim")
@@ -191,11 +199,12 @@ def print_access_card(
*,
tunneled: bool = True,
host: str | None = None,
title: str = "gpu-rent · доступы",
console: Console | None = None,
log: Log | None = None,
) -> None:
"""Print Rich panel; fall back to plain lines if needed."""
panel = render_access_panel(cfg, tunneled=tunneled, host=host)
panel = render_access_panel(cfg, tunneled=tunneled, host=host, title=title)
if console is not None:
console.print()
console.print(panel)
@@ -204,7 +213,7 @@ def print_access_card(
if log is not None:
# Plain fallback for non-Rich loggers
log("")
log("══ gpu-rent · доступы ══")
log(f"══ {title} ══")
try:
notes = load_state().notes or {}
if notes.get("idle_killer") == "failed":