Skip to content

Commit 42ca399

Browse files
committed
Fix: We can't access size_mib about Ephemeral and Persistant class because of some changes on aleph_message
Before any change, there were classes dedicated to the size of Ephemeral and Persistent class such as PersistentVolumeSizeMb and EphemeralVolumeSizeMb. Now, the size is included inside the classes EphemeralVolume and PersistentVolume so have to access the size by another method. - Creating a function to get the max and min size, that way it is more rigorous - Calling this function to get max and min size of the different volumes
1 parent 36c2d8b commit 42ca399

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

src/aleph_client/commands/instance/__init__.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@
4545
NodeRequirements,
4646
TrustedExecutionEnvironment,
4747
)
48-
from aleph_message.models.execution.volume import PersistentVolumeSizeMib
48+
from aleph_message.models.execution.volume import PersistentVolume
4949
from aleph_message.models.item_hash import ItemHash
50+
from aleph_message.utils import Gigabytes
5051
from click import echo
5152
from rich import box
5253
from rich.console import Console
@@ -71,6 +72,7 @@
7172
filter_only_valid_messages,
7273
find_sevctl_or_exit,
7374
found_gpus_by_model,
75+
get_field_constraints,
7476
get_or_prompt_volumes,
7577
setup_logging,
7678
str_to_datetime,
@@ -91,6 +93,7 @@
9193
metavar_valid_chains = f"[{'|'.join(hold_chains)}]"
9294
super_token_chains = get_chains_with_super_token()
9395
metavar_valid_payg_chains = f"[{'|'.join(super_token_chains)}]"
96+
_, max_rootfs_size = get_field_constraints(PersistentVolume, "size_mib", Gigabytes(2048), 0)
9497

9598

9699
@app.command()
@@ -118,9 +121,7 @@ async def create(
118121
compute_units: Annotated[Optional[int], typer.Option(help=help_strings.COMPUTE_UNITS)] = None,
119122
vcpus: Annotated[Optional[int], typer.Option(help=help_strings.VCPUS)] = None,
120123
memory: Annotated[Optional[int], typer.Option(help=help_strings.MEMORY)] = None,
121-
rootfs_size: Annotated[
122-
Optional[int], typer.Option(help=help_strings.ROOTFS_SIZE, max=PersistentVolumeSizeMib.le)
123-
] = None,
124+
rootfs_size: Annotated[Optional[int], typer.Option(help=help_strings.ROOTFS_SIZE, max=max_rootfs_size)] = None,
124125
timeout_seconds: Annotated[float, typer.Option(help=help_strings.TIMEOUT_SECONDS)] = settings.DEFAULT_VM_TIMEOUT,
125126
ssh_pubkey_file: Annotated[Path, typer.Option(help=help_strings.SSH_PUBKEY_FILE)] = Path(
126127
"~/.ssh/id_rsa.pub"
@@ -341,7 +342,7 @@ async def create(
341342
disk_size_info = f"Rootfs Size: {round(disk_size/1024, 2)} GiB (defaulted to included storage in tier)"
342343
if not isinstance(rootfs_size, int):
343344
rootfs_size = validated_int_prompt(
344-
"Custom Rootfs Size (MiB)", min_value=disk_size, max_value=PersistentVolumeSizeMib.le, default=disk_size
345+
"Custom Rootfs Size (MiB)", min_value=disk_size, max_value=max_rootfs_size, default=disk_size
345346
)
346347
if rootfs_size > disk_size:
347348
disk_size = rootfs_size
@@ -1197,7 +1198,6 @@ async def confidential_init_session(
11971198

11981199
# Generate sessions certificate files
11991200
if not ((session_dir / "vm_godh.b64").exists() and keep_session):
1200-
12011201
code, platform_file = await client.get_certificates()
12021202
if code != 200:
12031203
echo(
@@ -1367,9 +1367,7 @@ async def confidential_create(
13671367
compute_units: Annotated[Optional[int], typer.Option(help=help_strings.COMPUTE_UNITS)] = None,
13681368
vcpus: Annotated[Optional[int], typer.Option(help=help_strings.VCPUS)] = None,
13691369
memory: Annotated[Optional[int], typer.Option(help=help_strings.MEMORY)] = None,
1370-
rootfs_size: Annotated[
1371-
Optional[int], typer.Option(help=help_strings.ROOTFS_SIZE, max=PersistentVolumeSizeMib.le)
1372-
] = None,
1370+
rootfs_size: Annotated[Optional[int], typer.Option(help=help_strings.ROOTFS_SIZE, max=max_rootfs_size)] = None,
13731371
timeout_seconds: Annotated[float, typer.Option(help=help_strings.TIMEOUT_SECONDS)] = settings.DEFAULT_VM_TIMEOUT,
13741372
ssh_pubkey_file: Annotated[Path, typer.Option(help=help_strings.SSH_PUBKEY_FILE)] = Path(
13751373
"~/.ssh/id_rsa.pub"
@@ -1515,9 +1513,7 @@ async def gpu_create(
15151513
compute_units: Annotated[Optional[int], typer.Option(help=help_strings.COMPUTE_UNITS)] = None,
15161514
vcpus: Annotated[Optional[int], typer.Option(help=help_strings.VCPUS)] = None,
15171515
memory: Annotated[Optional[int], typer.Option(help=help_strings.MEMORY)] = None,
1518-
rootfs_size: Annotated[
1519-
Optional[int], typer.Option(help=help_strings.ROOTFS_SIZE, max=PersistentVolumeSizeMib.le)
1520-
] = None,
1516+
rootfs_size: Annotated[Optional[int], typer.Option(help=help_strings.ROOTFS_SIZE, max=max_rootfs_size)] = None,
15211517
premium: Annotated[Optional[bool], typer.Option(help=help_strings.GPU_PREMIUM_OPTION)] = None,
15221518
timeout_seconds: Annotated[float, typer.Option(help=help_strings.TIMEOUT_SECONDS)] = settings.DEFAULT_VM_TIMEOUT,
15231519
ssh_pubkey_file: Annotated[Path, typer.Option(help=help_strings.SSH_PUBKEY_FILE)] = Path(

src/aleph_client/commands/utils.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
from aleph.sdk.types import GenericMessage
1919
from aleph.sdk.utils import safe_getattr
2020
from aleph_message.models import AlephMessage, InstanceMessage, ItemHash, ProgramMessage
21-
from aleph_message.models.execution.volume import (
22-
EphemeralVolumeSize,
23-
PersistentVolumeSizeMib,
24-
)
21+
from aleph_message.models.execution.volume import EphemeralVolume, PersistentVolume
2522
from aleph_message.status import MessageStatus
23+
from aleph_message.utils import Gigabytes
24+
from pydantic import BaseModel
2625
from pygments import highlight
2726
from pygments.formatters.terminal256 import Terminal256Formatter
2827
from pygments.lexers import JsonLexer
@@ -89,6 +88,14 @@ def is_valid_mount_path(mount: str) -> bool:
8988
return mount.startswith("/") and len(mount) > 1
9089

9190

91+
def get_field_constraints(model: type[BaseModel], field_name: str, default_min: int, default_max: int):
92+
"""Get the constraints for a field in a model"""
93+
field_metadata = model.model_fields[field_name].metadata
94+
max_value = next((meta.le for meta in field_metadata if hasattr(meta, "le")), default_max)
95+
min_value = next((meta.gt for meta in field_metadata if hasattr(meta, "gt")), default_min)
96+
return min_value, max_value
97+
98+
9299
def prompt_for_volumes():
93100
while yes_no_input("Add volume?", default=False):
94101
mount = validated_prompt("Mount path (must be absolute, ex: /opt/data)", is_valid_mount_path)
@@ -108,10 +115,11 @@ def prompt_for_volumes():
108115
if yes_no_input("Copy from a parent volume?", default=False):
109116
parent = {"ref": validated_prompt("Item hash", lambda text: len(text) == 64), "use_latest": True}
110117
name = validated_prompt("Name", lambda text: len(text) > 0)
118+
min_size, max_size = get_field_constraints(PersistentVolume, "size_mib", Gigabytes(2048), 0)
111119
size_mib = validated_int_prompt(
112120
"Size (MiB)",
113-
min_value=PersistentVolumeSizeMib.gt + 1,
114-
max_value=PersistentVolumeSizeMib.le,
121+
min_value=max_size,
122+
max_value=min_size,
115123
)
116124
yield {
117125
**base_volume,
@@ -121,9 +129,8 @@ def prompt_for_volumes():
121129
"size_mib": size_mib,
122130
}
123131
else: # Ephemeral
124-
size_mib = validated_int_prompt(
125-
"Size (MiB)", min_value=EphemeralVolumeSize.gt + 1, max_value=EphemeralVolumeSize.le
126-
)
132+
min_size, max_size = get_field_constraints(EphemeralVolume, "size_mib", Gigabytes(1), 0)
133+
size_mib = validated_int_prompt("Size (MiB)", min_value=min_size + 1, max_value=max_size)
127134
yield {
128135
**base_volume,
129136
"ephemeral": True,

0 commit comments

Comments
 (0)