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.
81 lines
2.6 KiB
Python
81 lines
2.6 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""POST /topologies/{id}/teardown — transition an active/degraded/failed
|
|
topology to ``tearing_down`` and fire the background teardown.
|
|
|
|
Mirrors :mod:`api_deploy_topology`: the real Docker work runs in a
|
|
BackgroundTask, the caller returns ``202 Accepted``, and
|
|
:func:`decnet.engine.deployer.teardown_topology` writes the terminal
|
|
``torn_down`` status when it finishes.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import logging
|
|
|
|
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException, status
|
|
|
|
from decnet.engine.deployer import teardown_topology
|
|
from decnet.telemetry import traced as _traced
|
|
from decnet.topology.status import TopologyStatus
|
|
from decnet.web.db.models import TopologySummary
|
|
from decnet.web.dependencies import repo, require_admin
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
router = APIRouter()
|
|
|
|
# Statuses that can legally transition to TEARING_DOWN (see
|
|
# decnet.topology.status._LEGAL).
|
|
_TEARDOWNABLE: frozenset[str] = frozenset(
|
|
{
|
|
TopologyStatus.ACTIVE,
|
|
TopologyStatus.DEGRADED,
|
|
TopologyStatus.FAILED,
|
|
TopologyStatus.DEPLOYING,
|
|
}
|
|
)
|
|
|
|
|
|
async def _run_teardown(topology_id: str) -> None:
|
|
try:
|
|
await teardown_topology(repo, topology_id)
|
|
except asyncio.CancelledError: # pragma: no cover — shutdown
|
|
raise
|
|
except Exception as exc: # noqa: BLE001
|
|
log.error("background teardown of %s failed: %s", topology_id, exc)
|
|
|
|
|
|
@router.post(
|
|
"/{topology_id}/teardown",
|
|
tags=["MazeNET Topologies"],
|
|
response_model=TopologySummary,
|
|
status_code=status.HTTP_202_ACCEPTED,
|
|
responses={
|
|
400: {"description": "Malformed path parameters"},
|
|
401: {"description": "Missing or invalid credentials"},
|
|
403: {"description": "Insufficient permissions"},
|
|
404: {"description": "Topology not found"},
|
|
409: {"description": "Topology cannot be torn down from its current status"},
|
|
},
|
|
)
|
|
@_traced("api.topology.teardown")
|
|
async def api_teardown_topology(
|
|
topology_id: str,
|
|
background: BackgroundTasks,
|
|
_admin: dict = Depends(require_admin),
|
|
) -> TopologySummary:
|
|
topo = await repo.get_topology(topology_id)
|
|
if topo is None:
|
|
raise HTTPException(status_code=404, detail="Topology not found")
|
|
if topo.status not in _TEARDOWNABLE:
|
|
raise HTTPException(
|
|
status_code=409,
|
|
detail=(
|
|
f"Topology is {topo.status!r}; cannot teardown "
|
|
f"(allowed from: {sorted(_TEARDOWNABLE)})."
|
|
),
|
|
)
|
|
|
|
background.add_task(_run_teardown, topology_id)
|
|
return topo
|