fix(app): use CBR and correct sa
This commit is contained in:
@@ -1,19 +1,38 @@
|
||||
# Export data in YAML or JSON format
|
||||
from fastapi import APIRouter
|
||||
from database import fetch_all
|
||||
import yaml
|
||||
import json
|
||||
from kubernetes import client, config
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
def fetch_k8s_data():
|
||||
config.load_incluster_config()
|
||||
v1 = client.CoreV1Api()
|
||||
# Nodes
|
||||
nodes = v1.list_node()
|
||||
node_data = [{
|
||||
"node_name": node.metadata.name,
|
||||
"cpu": node.status.capacity.get("cpu"),
|
||||
"memory": node.status.capacity.get("memory"),
|
||||
"pods_allocatable": node.status.allocatable.get("pods")
|
||||
} for node in nodes.items]
|
||||
|
||||
# Namespaces
|
||||
namespaces = [ns.metadata.name for ns in v1.list_namespace().items]
|
||||
|
||||
return {"nodes": node_data, "namespaces": namespaces}
|
||||
|
||||
@router.get("/export")
|
||||
def export_data(format: str = "yaml"):
|
||||
# Fetch database and Kubernetes data
|
||||
data = {
|
||||
"metal_nodes": fetch_all("metal_nodes"),
|
||||
"virtual_machines": fetch_all("virtual_machines"),
|
||||
"kubernetes_nodes": fetch_all("kubernetes_nodes"),
|
||||
"kubernetes": fetch_k8s_data(),
|
||||
}
|
||||
# Return data in the requested format
|
||||
|
||||
# Return 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