add(pseudo): colors

This commit is contained in:
Aleksandr Tcitlionok
2024-12-05 07:42:41 +00:00
parent 182b9c8a2b
commit 633c4285d8

View File

@@ -30,40 +30,50 @@ def convert_memory_to_mib(memory):
def display_metal_nodes(): def display_metal_nodes():
console = Console() console = Console()
table = Table(title="Metal Nodes") table = Table(title="🖥️ Metal Nodes", style="bold green")
table.add_column("ID", justify="right") table.add_column("ID", justify="right", style="cyan")
table.add_column("Name") table.add_column("Name", style="magenta")
table.add_column("Location") table.add_column("Location", style="blue")
table.add_column("Vendor") table.add_column("Vendor", style="green")
table.add_column("CPU", justify="right") table.add_column("CPU", justify="right", style="yellow")
table.add_column("Memory") table.add_column("Memory (GB)", justify="right", style="cyan")
table.add_column("Storage") table.add_column("Storage", style="magenta")
nodes = fetch_all("metal_nodes") nodes = fetch_all("metal_nodes")
for node in nodes: for node in nodes:
table.add_row( table.add_row(
str(node[0]), node[1], node[2], node[3], f"{node[0]}",
str(node[4]), node[5], node[6] node[1],
node[2],
node[3],
f"{node[4]}",
node[5],
node[6]
) )
console.print(table) console.print(table)
def display_virtual_machines(): def display_virtual_machines():
console = Console() console = Console()
table = Table(title="Virtual Machines") table = Table(title="💻 Virtual Machines", style="bold blue")
table.add_column("ID", justify="right") table.add_column("ID", justify="right", style="cyan")
table.add_column("Name") table.add_column("Name", style="magenta")
table.add_column("Location") table.add_column("Location", style="blue")
table.add_column("CPU", justify="right") table.add_column("CPU", justify="right", style="yellow")
table.add_column("Memory") table.add_column("Memory (GB)", justify="right", style="cyan")
table.add_column("Storage") table.add_column("Storage", style="magenta")
table.add_column("Type") table.add_column("Type", style="green")
vms = fetch_all("virtual_machines") vms = fetch_all("virtual_machines")
for vm in vms: for vm in vms:
table.add_row( table.add_row(
str(vm[0]), vm[1], vm[2], f"{vm[0]}",
str(vm[3]), vm[4], vm[5], vm[6] vm[1],
vm[2],
f"{vm[3]}",
vm[4],
vm[5],
vm[6]
) )
console.print(table) console.print(table)
@@ -73,18 +83,18 @@ def display_kubernetes_nodes():
config.load_incluster_config() config.load_incluster_config()
v1 = client.CoreV1Api() v1 = client.CoreV1Api()
table = Table(title="Kubernetes Nodes") table = Table(title="📦 Kubernetes Nodes", style="bold yellow")
table.add_column("Node Name") table.add_column("Node Name", style="blue")
table.add_column("CPU", justify="right") table.add_column("CPU", justify="right", style="yellow")
table.add_column("Memory (MiB)", justify="right") table.add_column("Memory (MiB)", justify="right", style="cyan")
table.add_column("Pods Allocatable", justify="right") table.add_column("Pods Allocatable", justify="right", style="green")
nodes = v1.list_node() nodes = v1.list_node()
for node in nodes.items: for node in nodes.items:
table.add_row( table.add_row(
node.metadata.name, node.metadata.name,
node.status.capacity.get("cpu"), node.status.capacity.get("cpu"),
str(round(convert_memory_to_mib(node.status.capacity.get("memory")), 2)), f"{round(convert_memory_to_mib(node.status.capacity.get('memory')), 2)}",
node.status.allocatable.get("pods") node.status.allocatable.get("pods")
) )
@@ -95,10 +105,10 @@ def display_namespace_usage():
config.load_incluster_config() config.load_incluster_config()
metrics_client = client.CustomObjectsApi() metrics_client = client.CustomObjectsApi()
table = Table(title="Namespace Resource Usage") table = Table(title="📊 Namespace Resource Usage", style="bold magenta")
table.add_column("Namespace") table.add_column("Namespace", style="blue")
table.add_column("CPU (Cores)", justify="right") table.add_column("CPU (Cores)", justify="right", style="yellow")
table.add_column("Memory (MiB)", justify="right") table.add_column("Memory (MiB)", justify="right", style="cyan")
namespace_usage = {} namespace_usage = {}
pod_metrics = metrics_client.list_cluster_custom_object( pod_metrics = metrics_client.list_cluster_custom_object(
@@ -127,7 +137,11 @@ def display_namespace_usage():
console.print(table) console.print(table)
if __name__ == "__main__": if __name__ == "__main__":
console = Console()
console.print("✨ [bold green]Welcome to the Metal Check Dashboard![/bold green] ✨\n")
display_metal_nodes() display_metal_nodes()
display_virtual_machines() display_virtual_machines()
display_kubernetes_nodes() display_kubernetes_nodes()
display_namespace_usage() display_namespace_usage()
console.print("\n🚀 [bold cyan]Dashboard rendering complete![/bold cyan] 🚀")