feat(containers-dashboard): voeg host_ip toe aan gepubliceerde poorten en corrigeer portweergave

This commit is contained in:
kodi
2026-02-18 11:33:13 +01:00
parent 3142e9fbd0
commit 1c4dc3b809
2 changed files with 27 additions and 1 deletions
+1 -1
View File
@@ -3,5 +3,5 @@ WORKDIR /app
RUN apt-get update && apt-get install -y curl systemd && rm -rf /var/lib/apt/lists/* RUN apt-get update && apt-get install -y curl systemd && rm -rf /var/lib/apt/lists/*
RUN pip install fastapi uvicorn requests-unixsocket pyyaml pytest httpx RUN pip install fastapi uvicorn requests-unixsocket pyyaml pytest httpx
COPY app.py . COPY app.py .
COPY tests/ ./tests/ #COPY tests/ ./tests/
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"] CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
+26
View File
@@ -439,6 +439,31 @@ def find_defined_containers():
defined[name] = rel defined[name] = rel
return defined return defined
def _extract_published_ports(container: dict) -> list[str]:
"""
Normalize Podman API Ports into a stable display list:
- "127.0.0.1:8080:8000/tcp"
- "8080:8000/tcp" (if no host ip)
"""
out: list[str] = []
for p in (container.get("Ports") or []):
host_ip = p.get("host_ip") or p.get("HostIp") or ""
host_port = p.get("host_port") or p.get("HostPort")
cont_port = p.get("container_port") or p.get("ContainerPort")
proto = p.get("protocol") or p.get("Protocol") or ""
if host_port is None or cont_port is None:
continue
s = ""
if host_ip:
s += f"{host_ip}:"
s += f"{host_port}:{cont_port}"
if proto:
s += f"/{proto}"
out.append(s)
return out
@app.get("/containers-dashboard") @app.get("/containers-dashboard")
def containers_dashboard(): def containers_dashboard():
@@ -449,6 +474,7 @@ def containers_dashboard():
for c in real: for c in real:
_ensure_container_status_field(c) _ensure_container_status_field(c)
c["_dashboard_source"] = "podman" c["_dashboard_source"] = "podman"
c["_dashboard_published_ports"] = _extract_published_ports(c)
dashboard.append(c) dashboard.append(c)
# B) Dedup set (HOTFIX 3.3) — exact extraction, no sorting # B) Dedup set (HOTFIX 3.3) — exact extraction, no sorting