Skip to content

Commit

Permalink
Implement default hypervisor options on settings (#573)
Browse files Browse the repository at this point in the history
Problem: The unique way to set the default hypervisor to use is hardcoded on the `models.py` class, so we can't select another one by default.

Solution: Implement `INSTANCE_DEFAULT_HYPERVISOR` field on the orchestrator configuration variables.
  • Loading branch information
nesitor authored Mar 13, 2024
1 parent fc2eae7 commit 1c0761d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/aleph/vm/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from subprocess import CalledProcessError, check_output
from typing import Any, Literal, NewType, Optional, Union

from aleph_message.models.execution.environment import HypervisorType
from pydantic import BaseSettings, Field, HttpUrl
from pydantic.env_settings import DotenvType, env_file_sentinel
from pydantic.typing import StrPath
Expand Down Expand Up @@ -255,6 +256,10 @@ class Settings(BaseSettings):
ALLOCATION_TOKEN_HASH = "151ba92f2eb90bce67e912af2f7a5c17d8654b3d29895b042107ea312a7eebda"

ENABLE_QEMU_SUPPORT: bool = Field(default=False)
INSTANCE_DEFAULT_HYPERVISOR: Optional[HypervisorType] = Field(
default=HypervisorType.firecracker, # User Firecracker
description="Default hypervisor to use on running instances, can be Firecracker or QEmu",
)

# Tests on programs

Expand Down Expand Up @@ -391,6 +396,10 @@ def setup(self):
network_interface=self.NETWORK_INTERFACE,
)

if not settings.ENABLE_QEMU_SUPPORT:
# If QEmu is not supported, ignore the setting and use Firecracker by default
settings.INSTANCE_DEFAULT_HYPERVISOR = HypervisorType.firecracker

def display(self) -> str:
attributes: dict[str, Any] = {}

Expand Down
7 changes: 5 additions & 2 deletions src/aleph/vm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@ def is_instance(self) -> bool:

@property
def hypervisor(self) -> HypervisorType:
# default to firecracker for retro compat
return self.message.environment.hypervisor or HypervisorType.firecracker
if self.is_program:
return HypervisorType.firecracker

# Hypervisor setting is only used for instances
return self.message.environment.hypervisor or settings.INSTANCE_DEFAULT_HYPERVISOR

@property
def becomes_ready(self) -> Callable[[], Coroutine]:
Expand Down

0 comments on commit 1c0761d

Please sign in to comment.