update(think): update route with storage and type

This commit is contained in:
Aleksandr Tcitlionok
2024-12-05 08:19:31 +00:00
parent 289b5bb5d3
commit 3ea939b7d6

View File

@@ -1,8 +1,8 @@
import os
from fastapi import APIRouter, HTTPException from fastapi import APIRouter, HTTPException
from kubernetes import client, config from kubernetes import client, config
from typing import List, Dict from typing import List, Dict
import requests import requests
import os
router = APIRouter() router = APIRouter()
@@ -48,15 +48,18 @@ def think_k8s():
# Format node data # Format node data
nodes = [] nodes = []
for node in v1.list_node().items: for node in v1.list_node().items:
node_data = { # Fetch ephemeral-storage and instance type
ephemeral_storage = node.status.capacity.get("ephemeral-storage", "0")
instance_type = node.metadata.labels.get("beta.kubernetes.io/instance-type", "N/A")
nodes.append({
"name": node.metadata.name, "name": node.metadata.name,
"cpu": f"{node.status.capacity.get('cpu')} cores", "cpu": f"{node.status.capacity.get('cpu')} cores",
"memory": f"{round(int(node.status.capacity.get('memory').replace('Ki', '')) / 1024 / 1024, 2)} GB", "memory": f"{round(int(node.status.capacity.get('memory').replace('Ki', '')) / 1024 / 1024, 2)} GB",
"storage": "N/A", "storage": f"{round(int(ephemeral_storage.replace('Ki', '')) / (1024 ** 2), 2)} GB",
"type": "N/A", "type": instance_type,
"namespaces": [ns.metadata.name for ns in v1.list_namespace().items()] "namespaces": [ns.metadata.name for ns in v1.list_namespace().items()]
} })
nodes.append(node_data)
# Fetch token from environment # Fetch token from environment
api_url = os.getenv("AI_API_URL") api_url = os.getenv("AI_API_URL")