@@ -163,7 +163,7 @@ def make_client(self) -> ClientLibrary:
163
163
return client
164
164
165
165
166
- class Diagnostics (Enum ):
166
+ class DiagnosticCategory (Enum ):
167
167
COMPUTES = "computes"
168
168
LABS = "labs"
169
169
LAB_EVENTS = "lab_events"
@@ -207,7 +207,7 @@ class ClientLibrary:
207
207
"labs" : "labs" ,
208
208
"lab" : "labs/{lab_id}" ,
209
209
"lab_topology" : "labs/{lab_id}/topology" ,
210
- "diagnostics" : "diagnostics" ,
210
+ "diagnostics" : "diagnostics/{category} " ,
211
211
"system_health" : "system_health" ,
212
212
"system_stats" : "system_stats" ,
213
213
"populate_lab_tiles" : "populate_lab_tiles" ,
@@ -639,16 +639,11 @@ def all_labs(self, show_all: bool = False) -> list[Lab]:
639
639
:param show_all: Whether to get only labs owned by the admin or all user labs.
640
640
:returns: A list of Lab objects.
641
641
"""
642
- url = {"url" : self ._url_for ("labs" )}
643
- if show_all :
644
- url ["params" ] = {"show_all" : True }
645
- lab_ids = self ._session .get (** url ).json ()
646
-
642
+ lab_ids = self .get_lab_list (show_all = show_all )
647
643
result = []
648
644
for lab_id in lab_ids :
649
645
lab = self .join_existing_lab (lab_id )
650
646
result .append (lab )
651
-
652
647
return result
653
648
654
649
@locked
@@ -823,30 +818,30 @@ def join_existing_lab(self, lab_id: str, sync_lab: bool = True) -> Lab:
823
818
self ._labs [lab_id ] = lab
824
819
return lab
825
820
826
- def get_diagnostics (self , types : list [Diagnostics ] | None = None ) -> dict :
821
+ def get_diagnostics (
822
+ self , categories : list [DiagnosticCategory ] | None = None
823
+ ) -> dict :
827
824
"""
828
825
Return selected diagnostic data as a JSON object.
829
826
830
- :param types : List of diagnostic types to fetch. If None, fetch all.
827
+ :param categories : List of diagnostic categories to fetch. If None, fetch all.
831
828
:returns: The diagnostic data.
832
829
"""
833
- if types is None :
834
- types = list (Diagnostics )
830
+ if categories is None :
831
+ categories = list (DiagnosticCategory )
835
832
836
833
diagnostics_data = {}
837
- for diag_type in types :
838
- # Construct the endpoint path using given diagnostics value
839
- endpoint = f"diagnostics/{ diag_type .value } "
840
- url = self ._url_for (endpoint )
841
- response = self ._session .get (url )
842
-
843
- if response .status_code == 200 :
844
- diagnostics_data [diag_type .value ] = response .json ()
845
- else :
846
- diagnostics_data [diag_type .value ] = {
847
- "error" : f"Failed to fetch { diag_type .value } diagnostics"
834
+ for category in categories :
835
+ value = category .value
836
+ url = self ._url_for ("diagnostics" , category = value )
837
+ try :
838
+ response = self ._session .get (url )
839
+ response .raise_for_status ()
840
+ diagnostics_data [value ] = response .json ()
841
+ except httpx .HTTPStatusError :
842
+ diagnostics_data [value ] = {
843
+ "error" : f"Failed to fetch { value } diagnostics"
848
844
}
849
-
850
845
return diagnostics_data
851
846
852
847
def get_system_health (self ) -> dict :
0 commit comments