refactor(api): remove DI callables, routers import common directly
This commit is contained in:
+1
-60
@@ -8,16 +8,8 @@ from app_networks import init_networks_router
|
||||
from fastapi import FastAPI, HTTPException
|
||||
import requests_unixsocket
|
||||
from common import (
|
||||
_build_pod_to_containers_map as _common_build_pod_to_containers_map,
|
||||
_map_pod_to_unit as _common_map_pod_to_unit,
|
||||
_podman_action_post as _common_podman_action_post,
|
||||
_podman_delete as _common_podman_delete,
|
||||
_podman_get_json as _common_podman_get_json,
|
||||
_podman_get_json_checked as _common_podman_get_json_checked,
|
||||
_podman_get_text as _common_podman_get_text,
|
||||
_podman_post as _common_podman_post,
|
||||
_systemctl as _common_systemctl,
|
||||
_systemd_then_podman as _common_systemd_then_podman,
|
||||
)
|
||||
import uvicorn
|
||||
|
||||
@@ -30,28 +22,6 @@ WORKLOADS_DIR = "/app/workloads"
|
||||
async def _startup_stats_poller():
|
||||
await start_stats_poller()
|
||||
|
||||
# --- ADAPTERS (contract-neutral helpers) ---
|
||||
# Centralize Podman socket and systemctl invocation.
|
||||
# MUST NOT change endpoint outputs, status codes, or side-effects.
|
||||
|
||||
def _podman_get_json_checked(url: str):
|
||||
return _common_podman_get_json_checked(SESSION, url)
|
||||
|
||||
def _podman_get_json(url: str):
|
||||
return _common_podman_get_json(SESSION, url)
|
||||
|
||||
def _podman_get_text(url: str) -> str:
|
||||
return _common_podman_get_text(SESSION, url)
|
||||
|
||||
def _podman_post(url: str, **kwargs):
|
||||
return _common_podman_post(SESSION, url, **kwargs)
|
||||
|
||||
def _podman_action_post(kind: str, name: str, action: str):
|
||||
return _common_podman_action_post(SESSION, PODMAN_API_BASE, kind, name, action)
|
||||
|
||||
def _podman_delete(url: str):
|
||||
return _common_podman_delete(SESSION, url)
|
||||
|
||||
def _systemctl(cmd):
|
||||
return _common_systemctl(cmd, run)
|
||||
|
||||
@@ -90,20 +60,6 @@ def health():
|
||||
return {"ok": ok, "podman": {"ok": podman_ok}, "systemd_user": {"reachable": systemd_reachable}}
|
||||
|
||||
|
||||
# --- DASHBOARD HELPERS (contract-neutral, no ordering/sorting changes) ---
|
||||
|
||||
def _build_pod_to_containers_map(containers: list):
|
||||
return _common_build_pod_to_containers_map(containers)
|
||||
|
||||
|
||||
def _map_pod_to_unit(podname: str) -> str | None:
|
||||
return _common_map_pod_to_unit(podname)
|
||||
|
||||
|
||||
def _systemd_then_podman(systemd_callable, podman_callable):
|
||||
return _common_systemd_then_podman(systemd_callable, podman_callable)
|
||||
|
||||
|
||||
# --- ROUTERS ---
|
||||
# Images API lives in dedicated modules to keep this file from growing further.
|
||||
app.include_router(init_images_router(SESSION, PODMAN_API_BASE))
|
||||
@@ -113,28 +69,13 @@ app.include_router(init_containers_router(
|
||||
SESSION,
|
||||
PODMAN_API_BASE,
|
||||
WORKLOADS_DIR,
|
||||
_podman_get_json,
|
||||
_podman_get_text,
|
||||
_podman_post,
|
||||
_podman_action_post,
|
||||
_podman_delete,
|
||||
_systemctl,
|
||||
_systemd_then_podman,
|
||||
_map_pod_to_unit,
|
||||
_build_pod_to_containers_map,
|
||||
))
|
||||
app.include_router(init_pods_router(
|
||||
SESSION,
|
||||
PODMAN_API_BASE,
|
||||
WORKLOADS_DIR,
|
||||
_podman_get_json,
|
||||
_podman_post,
|
||||
_podman_delete,
|
||||
_systemctl,
|
||||
_podman_action_post,
|
||||
_map_pod_to_unit,
|
||||
_systemd_then_podman,
|
||||
_build_pod_to_containers_map,
|
||||
))
|
||||
|
||||
|
||||
@@ -151,7 +92,7 @@ def test_hybrid():
|
||||
|
||||
# 2. Check Podman API
|
||||
try:
|
||||
api_containers = _podman_get_json(f"{PODMAN_API_BASE}/libpod/containers/json?all=true")
|
||||
api_containers = _common_podman_get_json(SESSION, f"{PODMAN_API_BASE}/libpod/containers/json?all=true")
|
||||
except Exception as e:
|
||||
api_containers = f"API Fout: {str(e)}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user