Files
DECNET/decnet/web/db/models/deploy.py
anti 1b90048715 fix(api): /deckies/deploy becomes additive by default
The wizard POSTs only the new decky on each submit. The handler used to
treat every INI as the complete desired fleet (config.deckies = INI) so
the reconciler tore down prior deckies as orphans — deploying a second
Windows workstation silently wiped the first.

Add replace_fleet to DeployIniRequest (default false). Default path
merges new deckies into existing config and rejects name/IP collisions
with 409. replace_fleet=true preserves set-desired-state semantics for
CLI / declarative callers. Lifecycle rows are created only for the
deckies submitted in the current call, so /deckies/lifecycle?ids=...
reflects exactly what this submit deployed.

build_deckies_from_ini gains reserved_ips so additive auto-allocation
skips IPs already held by the existing fleet.
2026-05-22 18:14:50 -04:00

43 lines
1.5 KiB
Python

"""Fleet deploy + mutate-interval request DTOs."""
from typing import Optional
from pydantic import BaseModel, ConfigDict, Field as PydanticField
from decnet.models import IniContent
class MutateIntervalRequest(BaseModel):
# Human-readable duration: <number><unit> where unit is m(inutes), d(ays), M(onths), y/Y(ears).
# Minimum granularity is 1 minute. Seconds are not accepted.
mutate_interval: Optional[str] = PydanticField(None, pattern=r"^[1-9]\d*[mdMyY]$")
class DeployIniRequest(BaseModel):
model_config = ConfigDict(extra="forbid")
# This field now enforces strict INI structure during Pydantic initialization.
# The OpenAPI schema correctly shows it as a required string.
ini_content: IniContent = PydanticField(..., description="A valid INI formatted string")
replace_fleet: bool = PydanticField(
default=False,
description=(
"If true, the INI is treated as the complete desired fleet — any "
"existing decky absent from the INI is torn down. Default false: "
"the INI is appended to the existing fleet; name or IP collisions "
"with already-deployed deckies yield 409."
),
)
class DeployResponse(BaseModel):
"""202-Accepted response: deploy spawned in background, client polls
GET /deckies/lifecycle?ids=... until each row reaches a terminal
status."""
message: str
mode: str
lifecycle_ids: list[str] = PydanticField(default_factory=list)
class PurgeResponse(BaseModel):
message: str
deleted: dict[str, int]