Files
vacuum-wall/webui/api/network.py
T
mteehan faa076370d refactor: daemon collectors, thin webui proxies, pure config reads
- move state collectors from lib/state.py to daemon/collectors/ (7
  modules, registration side-effect; daemon/server.py imports the
  package before the first populate())
- webui/api: new daemon_route() decorator factory in common.py
  collapses the try/except daemon-proxy boilerplate in all 8
  blueprints (rules/params/body/transform keep responses identical)
- firewall: interface-coverage invariant — config is the source of
  truth for zone interfaces (absent key = empty, no hands-off
  zones); pure validate_coverage() enforced at save (400) and apply
  (409, force: true overrides), top-level `unmanaged` exemption
- lib: get_config() reads are now pure (no dir creation or writes);
  new lib/bootstrap.py creates runtime dirs and persists the
  one-shot nginx legacy migration at daemon start, after
  system_import (lib.nginx.migrate_config_file)
- lib/common: compute_pending() apply-bookkeeping helper
- daemon: emit_and_refresh() handler helper; refresh_state(bump=) so
  /status/refresh no longer bumps versions (poll/mutation only)
- acme: move --log last so acme.sh never treats a real arg as the
  log-file argument
- docs: AGENTS.md, config.md, state-model.md, api.md updated;
  HARDEN.md dropped (plan implemented); apply-confirm force wording

Tests: 917 passed; ruff check + format clean.
2026-09-03 00:40:56 +00:00

84 lines
2.3 KiB
Python

"""Network management API blueprint.
Exposes /api/network/* and delegates to vacuum-walld for interface
IP configuration via systemd-networkd.
"""
from typing import Any
from flask import Blueprint
from daemon.client import ( # noqa: F401 (resolved via module globals at dispatch)
get,
post,
)
from daemon.iface import (
GET_NETWORK_INFER_DHCP_RANGES,
GET_NETWORK_INFER_ZONES,
GET_NETWORK_INTERFACE_NAME,
GET_NETWORK_INTERFACES,
POST_NETWORK_APPLY,
POST_NETWORK_INTERFACE_NAME,
POST_NETWORK_INTERFACE_RELOAD,
)
from lib.common import validate_interface_name
from webui.api.common import daemon_route
bp = Blueprint("network", __name__)
def _check_iface(_json: Any, view_args: dict[str, Any]) -> None:
"""Validate the interface name path param (400 on a bad name)."""
validate_interface_name(view_args["name"])
def _applied(_data: Any, view_args: dict[str, Any], _sent: Any) -> Any:
return {"name": view_args["name"], "applied": True}
def _reloaded(_data: Any, view_args: dict[str, Any], _sent: Any) -> Any:
return {"name": view_args["name"], "reloaded": True}
@daemon_route(GET_NETWORK_INTERFACES, bp)
def list_interfaces():
"""GET /api/network/interfaces — List interfaces with config + runtime state."""
@daemon_route(GET_NETWORK_INTERFACE_NAME, bp, precheck=_check_iface)
def get_interface():
"""GET /api/network/interfaces/<name> — Config + runtime state for one interface."""
@daemon_route(
POST_NETWORK_INTERFACE_NAME, bp, precheck=_check_iface, transform=_applied
)
def save_interface():
"""POST /api/network/interfaces/<name> — Save and apply an interface's config."""
@daemon_route(
POST_NETWORK_INTERFACE_RELOAD,
bp,
precheck=_check_iface,
body={},
transform=_reloaded,
)
def reload_interface():
"""POST /api/network/interfaces/<name>/reload — Reload networkd for one interface."""
@daemon_route(POST_NETWORK_APPLY, bp)
def apply_all():
"""POST /api/network/apply — Apply network config for ALL interfaces."""
@daemon_route(GET_NETWORK_INFER_DHCP_RANGES, bp)
def infer_dhcp_ranges():
"""GET /api/network/infer-dhcp-ranges — Suggest candidate DHCP ranges."""
@daemon_route(GET_NETWORK_INFER_ZONES, bp)
def infer_zones():
"""GET /api/network/infer-zones — Suggest firewalld zone assignments."""