Skip to content

Commit bff740b

Browse files
committed
- Expose resources for executions
1 parent 1e2a8c5 commit bff740b

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/aleph/vm/orchestrator/utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from logging import getLogger
44
from typing import Any, TypedDict
55

6+
from aleph_message.models import InstanceContent, ProgramContent
7+
68
from aleph.vm.conf import settings
79
from aleph.vm.orchestrator.cache import AsyncTTLCache
810
from aleph.vm.orchestrator.http import get_session
@@ -88,3 +90,20 @@ def get_compatible_gpus() -> list[Any]:
8890
if not cached:
8991
return []
9092
return cached["compatible_gpus"]
93+
94+
95+
def get_execution_disk_size(message: InstanceContent | ProgramContent) -> int:
96+
disk_size_mib = 0
97+
98+
# For Programs the disk size depends on the runtime
99+
# TODO: Find the real size of the runtime and for the code volumes
100+
if isinstance(message, InstanceContent):
101+
disk_size_mib = message.rootfs.size_mib
102+
103+
# For volumes, only the persistent and ephemeral volumes have a size field
104+
# TODO: Find the real size of Inmutable volumes
105+
for volume in message.volumes:
106+
if getattr(volume, "size_mib", None):
107+
disk_size_mib += volume.size_mib
108+
109+
return disk_size_mib

src/aleph/vm/orchestrator/views/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
from aleph.vm.orchestrator.utils import (
5353
format_cost,
5454
get_community_wallet_address,
55+
get_execution_disk_size,
5556
is_after_community_wallet_start,
5657
update_aggregate_settings,
5758
)
@@ -263,6 +264,11 @@ async def list_executions_v2(request: web.Request) -> web.Response:
263264
if execution.vm and execution.vm.tap_interface
264265
else {}
265266
),
267+
"resources": {
268+
"vcpus": execution.message.resources.vcpus,
269+
"memory": execution.message.resources.memory,
270+
"disk_mib": get_execution_disk_size(execution.message),
271+
},
266272
"status": execution.times,
267273
"running": running_states.get(item_hash, False),
268274
}

tests/supervisor/test_views.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,11 @@ async def test_v2_executions_list_one_vm(aiohttp_client, mock_app_with_pool, moc
389389
assert await response.json() == {
390390
"decadecadecadecadecadecadecadecadecadecadecadecadecadecadecadeca": {
391391
"networking": {},
392+
"resources": {
393+
"vcpus": 1,
394+
"memory": 256,
395+
"disk_mib": 1000,
396+
},
392397
"status": {
393398
"defined_at": str(execution.times.defined_at),
394399
"preparing_at": None,
@@ -464,6 +469,11 @@ async def test_v2_executions_list_vm_network(aiohttp_client, mocker, mock_app_wi
464469
"ipv6_ip": "fc00:1:2:3:3:deca:deca:dec1",
465470
"mapped_ports": {},
466471
},
472+
"resources": {
473+
"vcpus": 1,
474+
"memory": 256,
475+
"disk_mib": 1000,
476+
},
467477
"status": {
468478
"defined_at": str(execution.times.defined_at),
469479
"preparing_at": None,

0 commit comments

Comments
 (0)