Skip to content
Open
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
18 changes: 18 additions & 0 deletions src/aleph/vm/orchestrator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Any, TypedDict

import aiohttp
from aleph_message.models import InstanceContent, ProgramContent

from aleph.vm.conf import settings

Expand Down Expand Up @@ -106,3 +107,20 @@ def get_compatible_gpus() -> list[Any]:
if not LAST_AGGREGATE_SETTINGS:
return []
return LAST_AGGREGATE_SETTINGS["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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this if it's coming from the message itself? I don't like that the node can report whatever it wants.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because on the message we don't have the real sizes used on the VMs, like on volumes and on runtime and code. The idea of this PR is to show the real resources used by the VMs. Indeed the PR need tobe finished solving the TODO tasks, I have put on review just to check the format.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From our conversation earlier, the goal of this PR is unclear. Let's not merge it until its purpose is clarified.

6 changes: 6 additions & 0 deletions src/aleph/vm/orchestrator/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,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,
)
Expand Down Expand Up @@ -220,6 +221,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": execution.is_running,
}
Expand Down
10 changes: 10 additions & 0 deletions tests/supervisor/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down