Skip to content
Open
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
24 changes: 21 additions & 3 deletions src/aleph_client/commands/instance/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import asyncio
import json
import json as json_lib
import logging
import shutil
from decimal import Decimal
Expand Down Expand Up @@ -864,7 +864,25 @@ async def list_instances(
raise typer.Exit(code=1)

execution = await client.instance.get_instance_executions_info(allocations)
await show_instances(messages=instances, allocations=allocations, executions=execution)

if not json:
await show_instances(messages=instances, allocations=allocations, executions=execution)
else:
# Create a single JSON array with one object per instance, combining all related data
instances_data = []
for message in instances:
allocation = allocations.root.get(message.item_hash, None)
execution_info = execution.root.get(message.item_hash, None)

instance_entry = {
"instance": message.model_dump(),
"allocation": allocation.model_dump() if allocation else None,
"execution": execution_info.model_dump() if execution_info else None,
}
instances_data.append(instance_entry)

console = Console()
console.print(json_lib.dumps(instances_data, indent=2, default=str))


@app.command()
Expand Down Expand Up @@ -956,7 +974,7 @@ async def logs(
async with VmClient(account, domain) as manager:
try:
async for log in manager.get_logs(vm_id=vm_id):
log_data = json.loads(log)
log_data = json_lib.loads(log)
if "message" in log_data:
echo(log_data["message"])
except aiohttp.ClientConnectorError as e:
Expand Down
Loading