Skip to content

Commit

Permalink
cluster list prints Running clusters first
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandra Belousov authored and Alexandra Belousov committed Sep 3, 2024
1 parent 6543de7 commit a1b7d05
Showing 1 changed file with 46 additions and 16 deletions.
62 changes: 46 additions & 16 deletions runhouse/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,8 @@ def cluster_list():
not in clusters_in_den_names
]

total_clusters = len(on_demand_clusters_sky) + len(clusters_in_den)
table_title = f"[bold cyan]{rns_client.username}'s Clusters (Total: {total_clusters})[/bold cyan]"

table = Table(title=table_title)

# Add columns to the table
table.add_column("Name", justify="left", no_wrap=True)
table.add_column("Cluster Type", justify="center", no_wrap=True)
table.add_column("Status", justify="left")
running_clusters = []
not_running_clusters = []

for den_cluster in clusters_in_den:
# get just name, not full rns address. reset is used so the name will be printed all in white.
Expand All @@ -578,15 +571,52 @@ def cluster_list():
cluster_status = (
den_cluster.get("status") if den_cluster.get("status") else "unknown"
)
cluster_status_colored = get_status_color(cluster_status)
table.add_row(cluster_name, cluster_type, cluster_status_colored)
if cluster_status == "running":
running_clusters.append(
{
"Name": cluster_name,
"Cluster Type": cluster_type,
"Status": cluster_status,
}
)
else:
not_running_clusters.append(
{
"Name": cluster_name,
"Cluster Type": cluster_type,
"Status": cluster_status,
}
)

for sky_cluster in on_demand_clusters_sky:
cluster_name = sky_cluster.get("name")
cluster_type = "OnDemandCluster"
cluster_status = "running"
cluster_status_colored = get_status_color(cluster_status)
table.add_row(cluster_name, cluster_type, cluster_status_colored)
running_clusters.append(
{
"Name": sky_cluster.get("name"),
"Cluster Type": "OnDemandCluster",
"Status": "running",
}
)

# Sort not-running clusters by the 'Status' column
not_running_clusters = sorted(not_running_clusters, key=lambda x: x["Status"])

# creating the clusters table
total_clusters = len(on_demand_clusters_sky) + len(clusters_in_den)
table_title = f"[bold cyan]{rns_client.username}'s Clusters (Total: {total_clusters})[/bold cyan]"
table = Table(title=table_title)

# Add columns to the table
table.add_column("Name", justify="left", no_wrap=True)
table.add_column("Cluster Type", justify="center", no_wrap=True)
table.add_column("Status", justify="left")

all_clusters = running_clusters + not_running_clusters
for rh_cluster in all_clusters:
table.add_row(
rh_cluster.get("Name"),
rh_cluster.get("Cluster Type"),
get_status_color(rh_cluster.get("Status")),
)

console.print(table)

Expand Down

0 comments on commit a1b7d05

Please sign in to comment.