diff --git a/src/aleph/vm/orchestrator/utils.py b/src/aleph/vm/orchestrator/utils.py index b64282a1e..1dbeb689e 100644 --- a/src/aleph/vm/orchestrator/utils.py +++ b/src/aleph/vm/orchestrator/utils.py @@ -3,6 +3,8 @@ from logging import getLogger from typing import Any, TypedDict +from aleph_message.models import InstanceContent, ProgramContent + from aleph.vm.conf import settings from aleph.vm.orchestrator.cache import AsyncTTLCache from aleph.vm.orchestrator.http import get_session @@ -88,3 +90,20 @@ def get_compatible_gpus() -> list[Any]: if not cached: return [] return cached["compatible_gpus"] + + +def get_execution_disk_size(message: InstanceContent | ProgramContent) -> int: + disk_size_mib = 0 + + # For Programs the disk size depends on the runtime + # TODO: Find the real size of the runtime and for the code volumes + if isinstance(message, InstanceContent): + disk_size_mib = message.rootfs.size_mib + + # For volumes, only the persistent and ephemeral volumes have a size field + # TODO: Find the real size of Inmutable volumes + for volume in message.volumes: + if getattr(volume, "size_mib", None): + disk_size_mib += volume.size_mib + + return disk_size_mib diff --git a/src/aleph/vm/orchestrator/views/__init__.py b/src/aleph/vm/orchestrator/views/__init__.py index 4dccb92e1..210a7c560 100644 --- a/src/aleph/vm/orchestrator/views/__init__.py +++ b/src/aleph/vm/orchestrator/views/__init__.py @@ -52,6 +52,7 @@ from aleph.vm.orchestrator.utils import ( format_cost, get_community_wallet_address, + get_execution_disk_size, is_after_community_wallet_start, update_aggregate_settings, ) @@ -263,6 +264,11 @@ async def list_executions_v2(request: web.Request) -> web.Response: if execution.vm and execution.vm.tap_interface else {} ), + "resources": { + "vcpus": execution.message.resources.vcpus, + "memory": execution.message.resources.memory, + "disk_mib": get_execution_disk_size(execution.message), + }, "status": execution.times, "running": running_states.get(item_hash, False), } diff --git a/tests/supervisor/test_views.py b/tests/supervisor/test_views.py index 693253ce4..7d6fc8dcc 100644 --- a/tests/supervisor/test_views.py +++ b/tests/supervisor/test_views.py @@ -389,6 +389,11 @@ async def test_v2_executions_list_one_vm(aiohttp_client, mock_app_with_pool, moc assert await response.json() == { "decadecadecadecadecadecadecadecadecadecadecadecadecadecadecadeca": { "networking": {}, + "resources": { + "vcpus": 1, + "memory": 256, + "disk_mib": 1000, + }, "status": { "defined_at": str(execution.times.defined_at), "preparing_at": None, @@ -464,6 +469,11 @@ async def test_v2_executions_list_vm_network(aiohttp_client, mocker, mock_app_wi "ipv6_ip": "fc00:1:2:3:3:deca:deca:dec1", "mapped_ports": {}, }, + "resources": { + "vcpus": 1, + "memory": 256, + "disk_mib": 1000, + }, "status": { "defined_at": str(execution.times.defined_at), "preparing_at": None,