Enhance logging functionality in CLI and tunnel operations. Updated gpu-rent logs to provide a complete journal output, including cloud-init logs by default. Added log digest printing for better visibility during VM operations, especially on failure scenarios. Improved error handling and added tests for new log digest features.
This commit is contained in:
+19
-44
@@ -62,6 +62,15 @@ def _stop_after_failed_up(cfg, cause: BaseException) -> None:
|
||||
warn(
|
||||
"up упал — гашу GPU (UP_STOP_ON_FAIL; оставить: --keep-on-fail / UP_STOP_ON_FAIL=false)"
|
||||
)
|
||||
try:
|
||||
from gpu_rent.state import load_state
|
||||
from gpu_rent.vm_logs import print_log_digest
|
||||
|
||||
fip = load_state().floating_ip
|
||||
if fip:
|
||||
print_log_digest(cfg, fip, console=console, log=log)
|
||||
except Exception as dig_exc:
|
||||
warn(f"дайджест логов перед stop: {dig_exc}")
|
||||
try:
|
||||
cmd_stop(cfg, no_pull=True, log=log)
|
||||
ok("compute остановлен, диски на месте")
|
||||
@@ -675,6 +684,9 @@ def up(
|
||||
)
|
||||
if state.floating_ip:
|
||||
console.print(f"FIP {state.floating_ip}")
|
||||
from gpu_rent.vm_logs import print_log_digest
|
||||
|
||||
print_log_digest(cfg, state.floating_ip, console=console)
|
||||
return
|
||||
|
||||
if not state.floating_ip:
|
||||
@@ -781,55 +793,18 @@ def logs(
|
||||
) -> None:
|
||||
"""cloud-init / journalctl юнитов на VM."""
|
||||
try:
|
||||
from gpu_rent.vm_logs import fetch_logs_for_cli
|
||||
|
||||
cfg = load_config(require_auth=True)
|
||||
state = load_state()
|
||||
if not state.floating_ip:
|
||||
raise GpuRentError("нет IP — VM не поднята")
|
||||
key = (unit or "all").strip().lower().replace("_", "-")
|
||||
aliases = {
|
||||
"all": "all",
|
||||
"swarm": "swarmui",
|
||||
"swarmui": "swarmui",
|
||||
"ollama": "ollama",
|
||||
"killer": "gpu-rent-idle-killer",
|
||||
"idle-killer": "gpu-rent-idle-killer",
|
||||
"idle": "gpu-rent-idle-killer",
|
||||
"cloud-init": "cloud-init",
|
||||
"cloud": "cloud-init",
|
||||
}
|
||||
if key not in aliases:
|
||||
raise GpuRentError(
|
||||
f"неизвестный --unit={unit!r}; "
|
||||
"ожидаю: swarm|ollama|killer|cloud-init|all"
|
||||
try:
|
||||
out = fetch_logs_for_cli(
|
||||
cfg, state.floating_ip, unit=unit, lines=lines
|
||||
)
|
||||
target = aliases[key]
|
||||
n = max(10, min(int(lines), 500))
|
||||
parts: list[str] = []
|
||||
if target in {"all", "cloud-init"}:
|
||||
parts.append(
|
||||
"echo '=== cloud-init (tail) ==='; "
|
||||
"sudo -n tail -n 60 /var/log/cloud-init-output.log 2>/dev/null || true"
|
||||
)
|
||||
journal_units = []
|
||||
if target == "all":
|
||||
journal_units = ["swarmui", "ollama", "gpu-rent-idle-killer"]
|
||||
elif target != "cloud-init":
|
||||
journal_units = [target]
|
||||
for ju in journal_units:
|
||||
parts.append(
|
||||
f"echo; echo '=== systemctl {ju} ==='; "
|
||||
f"systemctl is-active {ju} 2>/dev/null || true; "
|
||||
f"echo; echo '=== journalctl -u {ju} ==='; "
|
||||
f"sudo -n journalctl -u {ju} -n {n} --no-pager 2>/dev/null || true"
|
||||
)
|
||||
cmd = "; ".join(parts)
|
||||
out = run_ssh(
|
||||
cfg,
|
||||
state.floating_ip,
|
||||
cmd,
|
||||
check=False,
|
||||
timeout=60,
|
||||
)
|
||||
except ValueError as exc:
|
||||
raise GpuRentError(str(exc)) from exc
|
||||
# markup=False: пути вида [/opt/swarmui/...] в выводе MSBuild ломают rich-разметку
|
||||
console.print(out, markup=False, highlight=False)
|
||||
except GpuRentError as exc:
|
||||
|
||||
Reference in New Issue
Block a user