From 3ea939b7d69a9ab6e66e6cb9bec7660096a8b700 Mon Sep 17 00:00:00 2001 From: Aleksandr Tcitlionok <803797+terghalin@users.noreply.github.com> Date: Thu, 5 Dec 2024 08:19:31 +0000 Subject: [PATCH] update(think): update route with storage and type --- app/routes/think.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/routes/think.py b/app/routes/think.py index f294939..0ddbfbd 100644 --- a/app/routes/think.py +++ b/app/routes/think.py @@ -1,8 +1,8 @@ -import os from fastapi import APIRouter, HTTPException from kubernetes import client, config from typing import List, Dict import requests +import os router = APIRouter() @@ -48,15 +48,18 @@ def think_k8s(): # Format node data nodes = [] 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, "cpu": f"{node.status.capacity.get('cpu')} cores", "memory": f"{round(int(node.status.capacity.get('memory').replace('Ki', '')) / 1024 / 1024, 2)} GB", - "storage": "N/A", - "type": "N/A", + "storage": f"{round(int(ephemeral_storage.replace('Ki', '')) / (1024 ** 2), 2)} GB", + "type": instance_type, "namespaces": [ns.metadata.name for ns in v1.list_namespace().items()] - } - nodes.append(node_data) + }) # Fetch token from environment api_url = os.getenv("AI_API_URL")