ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
fleet_runner_model.py
Go to the documentation of this file.
1# SPDX-License-Identifier: MIT
2# Copyright (c) 2026 Brighton Sikarskie
3"""Runner-class naming and transport derivations for the fleet model."""
4
5from __future__ import annotations
6
7import shlex
8from dataclasses import dataclass
9from typing import Any
10
11
12@dataclass(frozen=True)
13class HostClass:
14 """Describe capacity, budget, and transport behavior for one host class.
15
16 Attributes:
17 capacity_runner: Whether the host carries scalable runner capacity.
18 budget_mode: The only budget mode this class may declare.
19 transport: Direct ``ssh`` or Windows-mediated ``wsl`` transport.
20 capacity_kind: Capacity controller arm used to scale this host.
21 summary: One-line human-readable description.
22 """
23
24 capacity_runner: bool
25 budget_mode: str
26 transport: str
27 capacity_kind: str
28 summary: str
29
30
31CLASSES: dict[str, HostClass] = {
32 "arc_k8s": HostClass(
33 capacity_runner=True,
34 budget_mode="burst",
35 transport="ssh",
36 capacity_kind="k8s",
37 summary="an ARC scale set on a k8s cluster",
38 ),
39 "docker_linux": HostClass(
40 capacity_runner=True,
41 budget_mode="reserved",
42 transport="ssh",
43 capacity_kind="docker",
44 summary="runner containers on a plain Docker host",
45 ),
46 "docker_wsl": HostClass(
47 capacity_runner=True,
48 budget_mode="reserved",
49 transport="wsl",
50 capacity_kind="docker",
51 summary="runner containers inside a Windows WSL2 distro",
52 ),
53 "dev_box": HostClass(
54 # The repo-scoped HIL listener is declared by the host's hil_runner
55 # block, but deliberately is not scalable general fleet capacity.
56 capacity_runner=False,
57 budget_mode="reserved",
58 transport="ssh",
59 capacity_kind="none",
60 summary="the shared verification box and dedicated HIL listener",
61 ),
62 "hil_bench": HostClass(
63 capacity_runner=False,
64 budget_mode="reserved",
65 transport="ssh",
66 capacity_kind="none",
67 summary="the hardware-in-the-loop bench",
68 ),
69}
70
71# The ci_runner_docker role uses this base for its container instance names.
72CONTAINER_BASE = "ra8-ci-runner"
73
74
75def instance_names(name: str, host: dict[str, Any]) -> list[str]:
76 """Return the stable runner-registration names for one host."""
77 if CLASSES[host["class"]].capacity_kind != "docker":
78 return []
79 runners = host.get("runners") or {}
80 base = runners.get("name", name)
81 count = int(runners.get("instances", 0))
82 if count == 1:
83 return [base]
84 return [f"{base}-{index}" for index in range(1, count + 1)]
85
86
87def container_names(host: dict[str, Any]) -> list[str]:
88 """Return Docker container names for one host in instance order."""
89 if CLASSES[host["class"]].capacity_kind != "docker":
90 return []
91 count = int((host.get("runners") or {}).get("instances", 0))
92 if count == 1:
93 return [CONTAINER_BASE]
94 return [f"{CONTAINER_BASE}-{index}" for index in range(1, count + 1)]
95
96
97def remote_shell(host: dict[str, Any]) -> str:
98 """Return the fixed remote command that executes a stdin shell script."""
99 if CLASSES[host["class"]].transport == "wsl":
100 distro = shlex.quote(str(host["connect"]["distro"]))
101 return (
102 f"wsl -d {distro} -u root -e /usr/bin/env -i HOME=/root PATH=/usr/bin:/bin /bin/bash -s"
103 )
104 return "/bin/bash -s"
105
106
107def docker_command(host: dict[str, Any]) -> str:
108 """Return the fixed Docker command for one host's transport."""
109 if CLASSES[host["class"]].transport == "wsl":
110 return "docker"
111 return "sudo docker"