update(ui): add time on duty for metal
This commit is contained in:
@@ -27,6 +27,22 @@ def calculate_time_on_duty(creation_timestamp):
|
||||
return f"{hours} hours" if hours > 1 else "1 hour"
|
||||
return f"{delta.days} days" if delta.days > 1 else "1 day"
|
||||
|
||||
def calculate_time_on_duty_hours(hours):
|
||||
"""
|
||||
Convert hours into a human-readable time format (days, hours, or minutes).
|
||||
"""
|
||||
if hours < 1:
|
||||
minutes = round(hours * 60)
|
||||
return f"{minutes} minutes" if minutes > 1 else "less than a minute"
|
||||
elif hours < 24:
|
||||
return f"{round(hours)} hours" if hours > 1 else "1 hour"
|
||||
else:
|
||||
days = hours // 24
|
||||
remaining_hours = hours % 24
|
||||
if remaining_hours:
|
||||
return f"{int(days)} days {int(remaining_hours)} hours"
|
||||
return f"{int(days)} days"
|
||||
|
||||
def convert_cpu_to_cores(cpu):
|
||||
if "n" in cpu:
|
||||
return round(int(cpu.replace("n", "")) / 1e9, 4)
|
||||
@@ -64,9 +80,11 @@ def display_metal_nodes():
|
||||
table.add_column("CPU", justify="right", style="yellow")
|
||||
table.add_column("Memory (GB)", justify="right", style="cyan")
|
||||
table.add_column("Storage", style="magenta")
|
||||
table.add_column("Time on Duty", justify="right", style="magenta")
|
||||
|
||||
nodes = fetch_all("metal_nodes")
|
||||
for node in nodes:
|
||||
time_on_duty = calculate_time_on_duty_hours(node[7])
|
||||
table.add_row(
|
||||
f"{node[0]}",
|
||||
node[1],
|
||||
@@ -74,7 +92,8 @@ def display_metal_nodes():
|
||||
node[3],
|
||||
f"{node[4]}",
|
||||
node[5],
|
||||
node[6]
|
||||
node[6],
|
||||
time_on_duty
|
||||
)
|
||||
|
||||
console.print(table)
|
||||
@@ -88,9 +107,11 @@ def display_virtual_machines():
|
||||
table.add_column("Memory (GB)", justify="right", style="cyan")
|
||||
table.add_column("Storage", style="magenta")
|
||||
table.add_column("Type", style="green")
|
||||
table.add_column("Time on Duty", justify="right", style="magenta")
|
||||
|
||||
vms = fetch_all("virtual_machines")
|
||||
for vm in vms:
|
||||
time_on_duty = calculate_time_on_duty_hours(vm[7])
|
||||
table.add_row(
|
||||
f"{vm[0]}",
|
||||
vm[1],
|
||||
@@ -98,7 +119,8 @@ def display_virtual_machines():
|
||||
f"{vm[3]}",
|
||||
vm[4],
|
||||
vm[5],
|
||||
vm[6]
|
||||
vm[6],
|
||||
time_on_duty
|
||||
)
|
||||
|
||||
console.print(table)
|
||||
|
||||
Reference in New Issue
Block a user