/** * `celilo system discover-network` — record the network this box sits on. * * The celilo-side half of "celilo owns the network namespace" * (openspec/changes/networks-are-declared-not-written/specs/network-declaration/spec.md). * `system apply-config` refuses `network.*` keys outright, so this is the surface * that writes the one network nobody can be asked about: the management box's * own, which celilo reads off the kernel rather than out of anyone's config. * * Idempotent and non-destructive — a value already set is left alone, so a * redeploy cannot clobber an operator's addressing. */ import { getDb } from '../../db/client'; import { discoverAndRecordNetwork } from '../../services/network-discovery'; import type { CommandResult } from '../types'; export async function handleSystemDiscoverNetwork(): Promise { const result = discoverAndRecordNetwork(getDb()); if (result.applied.length === 0) { // Not an error. "Nothing to record" is the ordinary outcome of a redeploy, // and an undiscoverable route is a fact to report rather than a failure to // abort a deploy on — the operator can set the value by hand. return { success: true, message: `No network recorded: ${result.skipped ?? 'nothing to do'}.`, }; } return { success: true, message: `Recorded the network this box sits on:\n ${result.applied.join('\n ')}`, }; }