37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
from fastapi import FastAPI, HTTPException
|
|
import requests_unixsocket
|
|
import os
|
|
import yaml
|
|
|
|
app = FastAPI(title="Podman MVP Control Plane")
|
|
SESSION = requests_unixsocket.Session()
|
|
# Podman API URL format voor unix sockets
|
|
PODMAN_API_BASE = "http+unix://%2Frun%2Fuser%2F1000%2Fpodman%2Fpodman.sock/v5.4.2"
|
|
WORKLOADS_DIR = "/app/workloads"
|
|
|
|
@app.get("/workloads")
|
|
def list_workloads():
|
|
files = [f for f in os.listdir(WORKLOADS_DIR) if f.endswith('.yaml')]
|
|
return {"workloads": files}
|
|
|
|
@app.post("/workloads/deploy/{filename}")
|
|
def deploy_workload(filename: str):
|
|
path = os.path.join(WORKLOADS_DIR, filename)
|
|
if not os.path.exists(path):
|
|
raise HTTPException(status_code=404, detail="YAML niet gevonden")
|
|
|
|
with open(path, 'r') as f:
|
|
# Podman Kube Play endpoint: /libpod/kube/play
|
|
# We versturen de content direct als body
|
|
url = f"{PODMAN_API_BASE}/libpod/kube/play"
|
|
response = SESSION.post(url, data=f.read())
|
|
|
|
if response.status_code >= 400:
|
|
raise HTTPException(status_code=response.status_code, detail=response.json())
|
|
|
|
return response.json()
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run(app, host="127.0.0.1", port=8000)
|