-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathconfig.py
57 lines (41 loc) · 1.53 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from pathlib import Path
from pydantic import BaseModel, ConfigDict, PositiveInt
VSOCK_PATH = "/tmp/v.sock"
class BootSource(BaseModel):
kernel_image_path: Path = Path("vmlinux.bin")
boot_args: str = "console=ttyS0 reboot=k panic=1 pci=off ro noapic nomodules random.trust_cpu=on"
@staticmethod
def args(enable_console: bool = True, writable: bool = False):
default = "reboot=k panic=1 pci=off noapic nomodules random.trust_cpu=on"
if writable:
default = default + " rw"
else:
default = default + " ro"
if enable_console:
return "console=ttyS0 " + default
else:
return default
class Drive(BaseModel):
drive_id: str = "rootfs"
path_on_host: Path = Path("./runtimes/aleph-alpine-3.13-python/rootfs.ext4")
is_root_device: bool = True
is_read_only: bool = True
class MachineConfig(BaseModel):
vcpu_count: PositiveInt = 1
mem_size_mib: PositiveInt = 128
smt: bool = False
class Vsock(BaseModel):
vsock_id: str = "1"
guest_cid: PositiveInt = 3
uds_path: str = VSOCK_PATH
class NetworkInterface(BaseModel):
iface_id: str = "eth0"
guest_mac: str = "AA:FC:00:00:00:01"
host_dev_name: str
class FirecrackerConfig(BaseModel):
boot_source: BootSource
drives: list[Drive]
machine_config: MachineConfig
vsock: Vsock | None = None
network_interfaces: list[NetworkInterface] | None = None
model_config = ConfigDict(populate_by_name=True, alias_generator=lambda x: x.replace("_", "-"))