From 4a414f457a1bf5e9292f0192dfe3d5f6eb205f48 Mon Sep 17 00:00:00 2001 From: Alexandra Belousov Date: Tue, 3 Sep 2024 16:28:02 +0300 Subject: [PATCH] print only running clusters --- runhouse/main.py | 58 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/runhouse/main.py b/runhouse/main.py index 0cc345bdd..8b428eb40 100644 --- a/runhouse/main.py +++ b/runhouse/main.py @@ -659,6 +659,9 @@ def cluster_list(): 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. cluster_name = f'[reset]{den_cluster.get("name").split("/")[-1]}' @@ -666,14 +669,61 @@ 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, + } + ) + + # TODO: will be used if we'll need to print not-running clusters + # 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(clusters_in_den) + table_title = f"[bold cyan]{rns_client.username}'s Clusters (Running: {len(running_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") + + # TODO: will be used if we'll need to print not-running clusters + # all_clusters = running_clusters + not_running_clusters + + for rh_cluster in running_clusters: + table.add_row( + rh_cluster.get("Name"), + rh_cluster.get("Cluster Type"), + get_status_color(rh_cluster.get("Status")), + ) console.print(table) - if len(on_demand_clusters_sky) > 0: + live_clusters_not_in_den = len(on_demand_clusters_sky) + if live_clusters_not_in_den > 0: + live_sky_clusters_str = ( + f"There are {live_clusters_not_in_den} live clusters that are not saved in Den." + if live_clusters_not_in_den > 1 + else "There is 1 live cluster that is not saved in Den." + ) + + clusters_pronoun = "them" if live_clusters_not_in_den > 1 else "it" + console.print( - f"There are {len(on_demand_clusters_sky)} live clusters that are not saved in Den. To get information about them, please run [bold italic]sky status -r[/bold italic]." + f"{live_sky_clusters_str} To get information about {clusters_pronoun}, please run [bold italic]sky status -r[/bold italic]." )