@@ -233,7 +233,7 @@ def list_cluster(
233233 print (tabulate (cluster_capacities , headers = headers , tablefmt = "presto" ))
234234 elif output == OutputFormat .JSON .value :
235235 json_list = [dict (zip (headers , value )) for value in cluster_capacities ]
236- _restructure_output (json_list , namespace )
236+ json_list = _restructure_output (json_list , namespace )
237237 print (json .dumps (json_list , indent = 4 ))
238238
239239
@@ -379,23 +379,34 @@ def _get_hyperpod_clusters(sm_client: boto3.client) -> List[str]:
379379
380380
381381def _restructure_output (summary_list , namespaces ):
382- if not namespaces :
383- return
382+ cluster_dict = dict ()
384383
385384 for node_summary in summary_list :
386- node_summary ["Namespaces" ] = {}
387- for ns in namespaces :
388- available_accelerators = node_summary [
389- ns + AVAILABLE_ACCELERATOR_DEVICES_KEY
390- ]
391- total_accelerators = node_summary [ns + TOTAL_ACCELERATOR_DEVICES_KEY ]
392- quota_accelerator_info = {
393- AVAILABLE_ACCELERATOR_DEVICES_KEY : available_accelerators ,
394- TOTAL_ACCELERATOR_DEVICES_KEY : total_accelerators ,
385+ cluster_name = node_summary ["Cluster" ]
386+ if cluster_name not in cluster_dict :
387+ cluster_dict [cluster_name ] = {
388+ "Cluster" : cluster_name ,
389+ "Instances" : []
395390 }
396- node_summary ["Namespaces" ][ns ] = quota_accelerator_info
397- node_summary .pop (ns + AVAILABLE_ACCELERATOR_DEVICES_KEY , None )
398- node_summary .pop (ns + TOTAL_ACCELERATOR_DEVICES_KEY , None )
391+ node_summary .pop ("Cluster" )
392+ if namespaces :
393+ node_summary ["Namespaces" ] = {}
394+ for ns in namespaces :
395+ available_accelerators = node_summary [
396+ ns + AVAILABLE_ACCELERATOR_DEVICES_KEY
397+ ]
398+ total_accelerators = node_summary [ns + TOTAL_ACCELERATOR_DEVICES_KEY ]
399+ quota_accelerator_info = {
400+ AVAILABLE_ACCELERATOR_DEVICES_KEY : available_accelerators ,
401+ TOTAL_ACCELERATOR_DEVICES_KEY : total_accelerators ,
402+ }
403+ node_summary ["Namespaces" ][ns ] = quota_accelerator_info
404+ node_summary .pop (ns + AVAILABLE_ACCELERATOR_DEVICES_KEY , None )
405+ node_summary .pop (ns + TOTAL_ACCELERATOR_DEVICES_KEY , None )
406+ cluster_dict [cluster_name ]["Instances" ].append (node_summary )
407+
408+ return list (cluster_dict .values ())
409+
399410
400411
401412def _aggregate_nodes_info (
0 commit comments