spb/maclustr-dispatch
Public
1"""maclustr-dispatch — configuration centrale.23Tout tourne SUR la passerelle (M1M32). Python 3.9 (système macOS) : pas de syntaxe > 3.9.4"""5import os67USER = "simon-pierreboucher"8HOME = os.path.expanduser("~")9GATEWAY = "M1M32"10DOMAIN = "maclustr.io"11LAN_PREFIX = "192.168.2."12SSH_KEY = os.path.join(HOME, ".ssh", "id_ed25519") # clé « maclustr-m1m32 », autorisée sur tous les nœuds13STATE = os.path.join(HOME, "dispatch") # état : apps/, stage/, registry.json, lan.json, logs/14APPS_DIR = os.path.join(STATE, "apps")15STAGE_DIR = os.path.join(STATE, "stage")16LOG_DIR = os.path.join(STATE, "logs")17REGISTRY = os.path.join(STATE, "registry.json")18LAN_CACHE = os.path.join(STATE, "lan.json")19SCAN_CACHE = os.path.join(STATE, "scan.json")20RUN_DIR = "~/dispatch-run" # sur les nœuds : ecosystem PM2 générés21SUDO_PW_FILE = os.path.join(STATE, ".sudo") # mot de passe sudo des nœuds (0600), pour `prepare`22HEAL_STATE = os.path.join(STATE, "heal-state.json") # mémoire de `mld heal` (actions récentes, nœuds en panne)2324# MacLustr Tunnel (remplace ngrok depuis le 2026-09-10) : passerelles OVH = hub WireGuard + Caddy (TLS auto), pilotées25# par `tunnelctl` (sudo sans mot de passe pour ubuntu). La clé de la passerelle M1M32 est autorisée pour `ubuntu`.26# Chaque Mac porte une interface par passerelle (wg1 → BHS64, wg0 → R9128), LaunchDaemon io.maclustr.wireguard-<iface>.27TUNNEL_GATEWAYS = {28 "BHS64": {"host": "51.161.112.61", "user": "ubuntu", "subnet": "10.67.0", "iface": "wg1", "endpoint": "51.161.112.61:443", "place": "OVH Beauharnois (Québec)"},29 "R9128": {"host": "51.255.75.61", "user": "ubuntu", "subnet": "10.66.0", "iface": "wg0", "endpoint": "51.255.75.61:51820", "place": "OVH Gravelines (France)"},30}31TUNNEL_DEFAULT = "BHS64"3233# Inventaire statique (alias -> cœurs, RAM Go, modèle). Les IP LAN sont découvertes en live.34NODES = {35 "M3U96a": {"cores": 32, "ram_gb": 96, "model": "Mac Studio"},36 "M3U96b": {"cores": 32, "ram_gb": 96, "model": "Mac Studio"},37 "M2U64": {"cores": 24, "ram_gb": 64, "model": "Mac Studio"},38 "M4M64a": {"cores": 16, "ram_gb": 64, "model": "Mac Studio"},39 "M4M64b": {"cores": 16, "ram_gb": 64, "model": "Mac Studio"},40 "M4M64c": {"cores": 16, "ram_gb": 64, "model": "Mac Studio"}, # ajouté 2026-09-25 (Mac16,9, M4 Max, LAN, Tailscale 100.125.225.117, S/N JX0PHFQHF1)41 "M5M36": {"cores": 18, "ram_gb": 36, "model": "Mac Studio"}, # ajouté 2026-09-26 (Mac17,14, M5 Max, LAN, Tailscale 100.69.26.91, S/N LY5Q6FD2PL)42 "M4BP48": {"cores": 16, "ram_gb": 48, "model": "MacBook Pro"},43 "M4BP36": {"cores": 14, "ram_gb": 36, "model": "MacBook Pro"},44 "M4M36": {"cores": 14, "ram_gb": 36, "model": "Mac Studio"},45 "M2M32": {"cores": 12, "ram_gb": 32, "model": "Mac Studio"},46 "M2M32b": {"cores": 12, "ram_gb": 32, "model": "Mac Studio"},47 "M2M32c": {"cores": 12, "ram_gb": 32, "model": "Mac Studio"},48 "m4mc": {"cores": 12, "ram_gb": 24, "model": "Mac mini"},49 "M1M32": {"cores": 10, "ram_gb": 32, "model": "Mac Studio"},50 "m4ma": {"cores": 10, "ram_gb": 24, "model": "Mac mini"},51 "m4mb": {"cores": 10, "ram_gb": 16, "model": "Mac mini"},52 "m2m16": {"cores": 10, "ram_gb": 16, "model": "Mac mini"},53 "M3BA24": {"cores": 8, "ram_gb": 24, "model": "MacBook Air"},54 "M3BA16": {"cores": 8, "ram_gb": 16, "model": "MacBook Air"},55 "m2m8a": {"cores": 8, "ram_gb": 8, "model": "Mac mini"},56 "m2m8b": {"cores": 8, "ram_gb": 8, "model": "Mac mini"},57 "m4md": {"cores": 10, "ram_gb": 16, "model": "Mac mini"}, # ajouté 2026-09-04 (Mac16,10, M4, 100.78.227.79)58 "m4ml": {"cores": 10, "ram_gb": 16, "model": "Mac mini"}, # ajouté 2026-09-21 (Mac16,10, M4, LAN, Tailscale 100.70.177.46, S/N VLXC9XWJLY)59 "m4mm": {"cores": 12, "ram_gb": 48, "model": "Mac mini"}, # ajouté 2026-09-21 (Mac16,11, M4 Pro, LAN, Tailscale 100.115.250.59, S/N DYH4X6RW3R)60 "m4mn": {"cores": 12, "ram_gb": 48, "model": "Mac mini"}, # ajouté 2026-09-21 (Mac16,11, M4 Pro, LAN, Tailscale 100.95.88.71, S/N J322FLVRW6)61 "m6ma": {"cores": 12, "ram_gb": 24, "model": "Mac mini"}, # ajouté 2026-09-26 (Mac18,5, M6, LAN, Tailscale 100.83.195.67, S/N FQ452T6L2W)62 "m6mb": {"cores": 12, "ram_gb": 24, "model": "Mac mini"}, # ajouté 2026-09-28 (Mac18,5, M6, LAN, Tailscale 100.102.242.94, S/N QR7JC5WMYC)63 "m5ma": {"cores": 15, "ram_gb": 24, "model": "Mac mini"}, # ajouté 2026-09-28 (Mac17,16, M5 Pro, LAN, Tailscale 100.117.72.79, S/N X6YL6N495W)64}6566# Nœuds HORS LAN : IP publique fixe + autre utilisateur + autre mot de passe sudo. Ils ne sont pas trouvés par le67# balayage 192.168.2.x : `discover` s'y connecte directement et vérifie le marqueur ~/.maclustr-node.68REMOTE_NODES = {69 # 2026-09-25 : les 12 Macs loués (Macly, MacStadium, rentamac) ont été retirés du cluster (voir NODES.md).70}717273def _remote(key):74 for alias, r in REMOTE_NODES.items():75 if key in (alias, r["host"]):76 return r77 return None787980def user_of(key=None):81 """Utilisateur SSH d'un nœud (alias ou IP) — simon-pierreboucher partout sauf REMOTE_NODES."""82 r = _remote(key) if key else None83 return r["user"] if r else USER848586def home_of(key=None):87 return "/Users/%s" % user_of(key)888990def sudo_pw_file(key=None):91 r = _remote(key) if key else None92 return r["sudo_pw_file"] if r else SUDO_PW_FILE939495# Nœuds réservés : inéligibles au placement automatique (sauf app épinglée dessus).96RESERVED = {97 "M3U96b": "réservé à hfmarketdata (lac FirstRate Data) depuis le 2026-09-04",98}99100# Rôles : gateway = jamais d'app ; worker = éligible. Un nœud absent du scan est « offline ».101ROLES = {alias: ("gateway" if alias == GATEWAY else "worker") for alias in NODES}102103# Runtimes que `prepare` sait installer via Homebrew, et comment les détecter sur un nœud.104RUNTIME_CHECKS = {105 "node": "test -x /opt/homebrew/bin/node",106 "pnpm": "test -x /opt/homebrew/bin/pnpm",107 "pm2": "test -x /opt/homebrew/bin/pm2",108 # raccordé au MacLustr Tunnel (wg1 → BHS64 monté) : informatif, `mld deploy` raccorde lui-même un nœud qui ne l'est pas109 "tunnel": "test -f /Library/LaunchDaemons/io.maclustr.wireguard-wg1.plist && ifconfig 2>/dev/null | grep -q 'inet 10\\.67\\.0\\.'",110 "python@3.14": "test -x /opt/homebrew/opt/python@3.14/bin/python3.14",111 "python@3.13": "test -x /opt/homebrew/opt/python@3.13/bin/python3.13",112 "python@3.12": "test -x /opt/homebrew/opt/python@3.12/bin/python3.12",113 "uv": "test -x /opt/homebrew/bin/uv || test -x $HOME/.local/bin/uv",114 "uv-python@3.12": "ls -d $HOME/.local/share/uv/python/cpython-3.12* >/dev/null 2>&1",115 "redis": "test -x /opt/homebrew/bin/redis-server && redis-cli ping >/dev/null 2>&1",116 "docker": "test -x /opt/homebrew/bin/docker",117 "postgresql@17": "test -x /opt/homebrew/opt/postgresql@17/bin/postgres",118 "brew": "test -x /opt/homebrew/bin/brew",119 "git": "test -x /opt/homebrew/bin/git || test -x /usr/bin/git",120}121BREW_FORMULAE = {122 "node": "node", "pnpm": "pnpm", "pm2": "pm2", "python@3.14": "python@3.14", "python@3.13": "python@3.13",123 "python@3.12": "python@3.12", "uv": "uv", "redis": "redis", "docker": "docker", "postgresql@17": "postgresql@17", "git": "git",124}125BREW_CASKS = {} # ngrok (cask) retiré le 2026-09-10 : l'exposition publique passe par TUNNEL_GATEWAYS126127os.makedirs(APPS_DIR, exist_ok=True)128os.makedirs(STAGE_DIR, exist_ok=True)129os.makedirs(LOG_DIR, exist_ok=True)130