Some checks failed
CI / test (push) Failing after 15s
Co-authored-by: Copilot <copilot@github.com>
51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
"""Data collection routines built on top of the SSH client."""
|
|
|
|
from dataclasses import dataclass
|
|
|
|
from tai.plan import CollectionPlan
|
|
from tai.ssh_client import SSHCommandResult, SSHSession
|
|
|
|
|
|
@dataclass(slots=True)
|
|
class CollectedItem:
|
|
"""Single collected diagnostic command result."""
|
|
|
|
name: str
|
|
result: SSHCommandResult
|
|
|
|
|
|
@dataclass(slots=True)
|
|
class CollectionReport:
|
|
"""Collection summary for a batch of diagnostics."""
|
|
|
|
host: str
|
|
items: list[CollectedItem]
|
|
|
|
@property
|
|
def total(self) -> int:
|
|
return len(self.items)
|
|
|
|
@property
|
|
def failed(self) -> int:
|
|
return sum(1 for item in self.items if item.result.exit_code != 0)
|
|
|
|
|
|
async def collect_from_plan(
|
|
session: SSHSession,
|
|
plan: CollectionPlan,
|
|
*,
|
|
max_output_bytes: int = 32768,
|
|
) -> CollectionReport:
|
|
"""Execute all commands in *plan* over a shared SSH session."""
|
|
items: list[CollectedItem] = []
|
|
|
|
for name, command in plan.commands:
|
|
result = await session.run_read_only_command(
|
|
command,
|
|
timeout_seconds=30.0,
|
|
max_output_bytes=max_output_bytes,
|
|
)
|
|
items.append(CollectedItem(name=name, result=result))
|
|
|
|
return CollectionReport(host=session._client.summary(), items=items)
|