Add NAS dashboard MVP: Docker mgmt, Gitea, Files, Terminal
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import docker
|
||||
from fastapi import APIRouter
|
||||
from config import DOCKER_HOST
|
||||
|
||||
router = APIRouter()
|
||||
client = docker.DockerClient(base_url=DOCKER_HOST)
|
||||
|
||||
|
||||
@router.get("/containers")
|
||||
def list_containers():
|
||||
return [
|
||||
{
|
||||
"id": c.short_id,
|
||||
"name": c.name,
|
||||
"status": c.status,
|
||||
"image": c.image.tags[0] if c.image.tags else str(c.image.id)[:20],
|
||||
"ports": c.ports,
|
||||
}
|
||||
for c in client.containers.list(all=True)
|
||||
]
|
||||
|
||||
|
||||
@router.post("/containers/{container_id}/{action}")
|
||||
def container_action(container_id: str, action: str):
|
||||
if action not in ("start", "stop", "restart"):
|
||||
return {"error": "invalid action"}
|
||||
c = client.containers.get(container_id)
|
||||
getattr(c, action)()
|
||||
return {"ok": True}
|
||||
|
||||
|
||||
@router.get("/containers/{container_id}/logs")
|
||||
def container_logs(container_id: str, tail: int = 200):
|
||||
c = client.containers.get(container_id)
|
||||
return {"logs": c.logs(tail=tail, timestamps=True).decode(errors="replace")}
|
||||
Reference in New Issue
Block a user