Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small refactoring for PR #228 (Add Qemu working runtimes) #229

Merged
merged 2 commits into from
Jul 9, 2024
Merged
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
40 changes: 18 additions & 22 deletions src/aleph_client/commands/instance/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,6 @@ def validate_ssh_pubkey_file(file: Union[str, Path]) -> Path:

account: AccountFromPrivateKey = _load_account(private_key, private_key_file)

os_firecracker_map = {
settings.UBUNTU_22_ROOTFS_ID: "Ubuntu 22",
settings.DEBIAN_12_ROOTFS_ID: "Debian 12",
settings.DEBIAN_11_ROOTFS_ID: "Debian 11",
}

os_qemu_map = {
settings.UBUNTU_22_QEMU_ROOTFS_ID: "Ubuntu 22",
settings.DEBIAN_12_QEMU_ROOTFS_ID: "Debian 12",
settings.DEBIAN_11_QEMU_ROOTFS_ID: "Debian 11",
}

hv_map = {
HypervisorType.firecracker: "firecracker",
HypervisorType.qemu: "qemu",
}

if hold:
# Holder tier
reward_address = None
Expand All @@ -138,19 +121,32 @@ def validate_ssh_pubkey_file(file: Union[str, Path]) -> Path:
lambda x: x in valid_address,
)

hypervisor = HypervisorType[
available_hypervisors = {
HypervisorType.firecracker: {
"Ubuntu 22": settings.UBUNTU_22_ROOTFS_ID,
"Debian 12": settings.DEBIAN_12_ROOTFS_ID,
"Debian 11": settings.DEBIAN_11_ROOTFS_ID,
},
HypervisorType.qemu: {
"Ubuntu 22": settings.UBUNTU_22_QEMU_ROOTFS_ID,
"Debian 12": settings.DEBIAN_12_QEMU_ROOTFS_ID,
"Debian 11": settings.DEBIAN_11_QEMU_ROOTFS_ID,
},
}

hypervisor_choice = HypervisorType[
Prompt.ask(
"Which hypervisor you want to use?",
default=hypervisor.name,
choices=[*hv_map.values()],
choices=[x.name for x in available_hypervisors],
)
]

choices = os_qemu_map if hypervisor == HypervisorType.qemu else os_firecracker_map
os_choices = available_hypervisors[hypervisor_choice]
rootfs = Prompt.ask(
"Do you want to use a custom rootfs or one of the following prebuilt ones?",
default=rootfs,
choices=[*choices.values(), "custom"],
choices=[*os_choices, "custom"],
)

if rootfs == "custom":
Expand All @@ -159,7 +155,7 @@ def validate_ssh_pubkey_file(file: Union[str, Path]) -> Path:
lambda x: len(x) == 64,
)
else:
rootfs = next(k for k, v in choices.items() if v == rootfs)
rootfs = os_choices[rootfs]

async with AlephHttpClient(api_server=sdk_settings.API_HOST) as client:
rootfs_message: StoreMessage = await client.get_message(item_hash=rootfs, message_type=StoreMessage)
Expand Down
Loading