1313from jumpstarter_protocol import client_pb2 , client_pb2_grpc , jumpstarter_pb2_grpc , kubernetes_pb2 , router_pb2_grpc
1414from pydantic import BaseModel , ConfigDict , Field , field_serializer
1515
16+ from jumpstarter .common import ExporterStatus
1617from jumpstarter .common .grpc import translate_grpc_exceptions
1718
1819
1920@dataclass
2021class WithOptions :
2122 show_online : bool = False
2223 show_leases : bool = False
24+ show_status : bool = False
2325
2426
2527def add_display_columns (table , options : WithOptions = None ):
@@ -28,6 +30,8 @@ def add_display_columns(table, options: WithOptions = None):
2830 table .add_column ("NAME" )
2931 if options .show_online :
3032 table .add_column ("ONLINE" )
33+ if options .show_status :
34+ table .add_column ("STATUS" )
3135 table .add_column ("LABELS" )
3236 if options .show_leases :
3337 table .add_column ("LEASED BY" )
@@ -42,6 +46,9 @@ def add_exporter_row(table, exporter, options: WithOptions = None, lease_info: t
4246 row_data .append (exporter .name )
4347 if options .show_online :
4448 row_data .append ("yes" if exporter .online else "no" )
49+ if options .show_status :
50+ status_str = str (exporter .status ) if exporter .status else "UNKNOWN"
51+ row_data .append (status_str )
4552 row_data .append ("," .join (("{}={}" .format (k , v ) for k , v in sorted (exporter .labels .items ()))))
4653 if options .show_leases :
4754 if lease_info :
@@ -81,12 +88,16 @@ class Exporter(BaseModel):
8188 name : str
8289 labels : dict [str , str ]
8390 online : bool = False
91+ status : ExporterStatus | None = None
8492 lease : Lease | None = None
8593
8694 @classmethod
8795 def from_protobuf (cls , data : client_pb2 .Exporter ) -> Exporter :
8896 namespace , name = parse_exporter_identifier (data .name )
89- return cls (namespace = namespace , name = name , labels = data .labels , online = data .online )
97+ status = None
98+ if hasattr (data , "status" ) and data .status :
99+ status = ExporterStatus .from_proto (data .status )
100+ return cls (namespace = namespace , name = name , labels = data .labels , online = data .online , status = status )
90101
91102 @classmethod
92103 def rich_add_columns (cls , table , options : WithOptions = None ):
@@ -244,6 +255,7 @@ class ExporterList(BaseModel):
244255 next_page_token : str | None = Field (exclude = True )
245256 include_online : bool = Field (default = False , exclude = True )
246257 include_leases : bool = Field (default = False , exclude = True )
258+ include_status : bool = Field (default = False , exclude = True )
247259
248260 @classmethod
249261 def from_protobuf (cls , data : client_pb2 .ListExportersResponse ) -> ExporterList :
@@ -253,11 +265,15 @@ def from_protobuf(cls, data: client_pb2.ListExportersResponse) -> ExporterList:
253265 )
254266
255267 def rich_add_columns (self , table ):
256- options = WithOptions (show_online = self .include_online , show_leases = self .include_leases )
268+ options = WithOptions (
269+ show_online = self .include_online , show_leases = self .include_leases , show_status = self .include_status
270+ )
257271 Exporter .rich_add_columns (table , options )
258272
259273 def rich_add_rows (self , table ):
260- options = WithOptions (show_online = self .include_online , show_leases = self .include_leases )
274+ options = WithOptions (
275+ show_online = self .include_online , show_leases = self .include_leases , show_status = self .include_status
276+ )
261277 for exporter in self .exporters :
262278 exporter .rich_add_rows (table , options )
263279
@@ -274,6 +290,8 @@ def model_dump_json(self, **kwargs):
274290 exclude_fields .add ("lease" )
275291 if not self .include_online :
276292 exclude_fields .add ("online" )
293+ if not self .include_status :
294+ exclude_fields .add ("status" )
277295
278296 data = {"exporters" : [exporter .model_dump (mode = "json" , exclude = exclude_fields ) for exporter in self .exporters ]}
279297 return json .dumps (data , ** json_kwargs )
@@ -284,6 +302,8 @@ def model_dump(self, **kwargs):
284302 exclude_fields .add ("lease" )
285303 if not self .include_online :
286304 exclude_fields .add ("online" )
305+ if not self .include_status :
306+ exclude_fields .add ("status" )
287307
288308 return {"exporters" : [exporter .model_dump (mode = "json" , exclude = exclude_fields ) for exporter in self .exporters ]}
289309
0 commit comments