init(app): initial version
This commit is contained in:
19
app/routes/export.py
Normal file
19
app/routes/export.py
Normal file
@@ -0,0 +1,19 @@
|
||||
# Export data in YAML or JSON format
|
||||
from fastapi import APIRouter
|
||||
from database import fetch_all
|
||||
import yaml
|
||||
import json
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/export")
|
||||
def export_data(format: str = "yaml"):
|
||||
data = {
|
||||
"metal_nodes": fetch_all("metal_nodes"),
|
||||
"virtual_machines": fetch_all("virtual_machines"),
|
||||
"kubernetes_nodes": fetch_all("kubernetes_nodes"),
|
||||
}
|
||||
# Return data in the requested format
|
||||
if format.lower() == "yaml":
|
||||
return yaml.safe_dump(data)
|
||||
return json.dumps(data, indent=2)
|
||||
Reference in New Issue
Block a user