Replaces LICENSE (GPLv3 -> AGPLv3) and prepends `SPDX-License-Identifier: AGPL-3.0-or-later` to every source file across decnet/, decnet_web/, tests/, scripts/, and tools/. Rationale: closes the GPLv3 ASP loophole so any party operating a modified DECNET as a network service must offer their modified source. Personal copyright (Samuel Paschuan) + inbound=outbound contributions make a future unilateral relicense infeasible. - LICENSE: full AGPL-3.0 text (gnu.org/licenses/agpl-3.0.txt) - COPYRIGHT: project copyright notice - tools/add_spdx_headers.py: idempotent header injector (shebang- and PEP 263-aware) Touches 1565 source files (.py, .ts, .tsx, .js, .jsx, .css, .sh). No behavior change; comments only.
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""GET /system/deployment-mode — tells the UI whether a deploy will shard
|
|
across SWARM workers or land on the master itself.
|
|
|
|
Logic mirrors the auto-mode branch in ``api_deploy_deckies``: master role
|
|
plus at least one reachable enrolled worker = swarm; otherwise unihost.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
from fastapi import APIRouter, Depends
|
|
from pydantic import BaseModel
|
|
|
|
from decnet.web.db.repository import BaseRepository
|
|
from decnet.web.dependencies import get_repo
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
class DeploymentModeResponse(BaseModel):
|
|
mode: str # "swarm" or "unihost"
|
|
role: str # "master" or "agent"
|
|
swarm_host_count: int
|
|
|
|
|
|
@router.get("/deployment-mode", response_model=DeploymentModeResponse)
|
|
async def get_deployment_mode(
|
|
repo: BaseRepository = Depends(get_repo),
|
|
) -> DeploymentModeResponse:
|
|
role = os.environ.get("DECNET_MODE", "master").lower()
|
|
hosts = 0
|
|
if role == "master":
|
|
hosts = sum(
|
|
1 for h in await repo.list_swarm_hosts()
|
|
if h.get("status") in ("active", "enrolled") and h.get("address")
|
|
)
|
|
return DeploymentModeResponse(
|
|
mode="swarm" if hosts > 0 else "unihost",
|
|
role=role,
|
|
swarm_host_count=hosts,
|
|
)
|