Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion python/lightning_sdk/cli/vm/list.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""VM list command."""

from datetime import datetime
from typing import Optional

import rich_click as click
Expand Down Expand Up @@ -39,7 +40,7 @@ def list_vms(teamspace: Optional[str] = None, all_teamspaces: bool = False) -> N
table.add_column("SSH host", no_wrap=True)

for resolved_teamspace, vm in sorted(rows, key=lambda row: row[1].name or ""):
created = vm.created_at.strftime("%Y-%m-%d %H:%M") if vm.created_at else ""
created = _created_label(vm.created_at)
table.add_row(
vm.name or "",
f"{resolved_teamspace.owner.name}/{resolved_teamspace.name}",
Expand All @@ -50,3 +51,11 @@ def list_vms(teamspace: Optional[str] = None, all_teamspaces: bool = False) -> N
)

click.echo(rich_to_str(table), color=True)


def _created_label(value: object) -> str:
if not value:
return ""
if isinstance(value, datetime):
return value.strftime("%Y-%m-%d %H:%M")
return str(value)[:16].replace("T", " ")
20 changes: 18 additions & 2 deletions python/tests/cli/vm/test_vm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from datetime import datetime
from types import SimpleNamespace
from unittest.mock import MagicMock

Expand Down Expand Up @@ -100,8 +101,21 @@ def test_create_surfaces_server_message(monkeypatch) -> None:
def test_list_renders_table(monkeypatch) -> None:
api = MagicMock()
api.list_vms.return_value = [
V1Instance(id="vm-1", name="sim-1", status="running", instance_type="lit-h100-1", ssh_host="1.2.3.4"),
V1Instance(id="vm-2", name="sim-2", status="pending", instance_type="lit-h100-8"),
V1Instance(
id="vm-1",
name="sim-1",
status="running",
instance_type="lit-h100-1",
ssh_host="1.2.3.4",
created_at="2026-09-15T16:00:01.225419Z",
),
V1Instance(
id="vm-2",
name="sim-2",
status="pending",
instance_type="lit-h100-8",
created_at=datetime(2026, 9, 14, 8, 30),
),
]
monkeypatch.setattr("lightning_sdk.cli.vm.list.iter_teamspaces", lambda teamspace, all_teamspaces: [_teamspace()])
monkeypatch.setattr("lightning_sdk.cli.vm.list.VMApi", MagicMock(return_value=api))
Expand All @@ -114,6 +128,8 @@ def test_list_renders_table(monkeypatch) -> None:
assert "running" in result.output
assert "1.2.3.4" in result.output
assert "lit-h100-8" in result.output
assert "2026-09-15 16:00" in result.output
assert "2026-09-14 08:30" in result.output
api.list_vms.assert_called_once_with("ts-1")


Expand Down
Loading