2020class WithOptions :
2121 show_online : bool = False
2222 show_leases : bool = False
23+ show_start_time : bool = False
24+ show_end_time : bool = False
2325
2426
2527def add_display_columns (table , options : WithOptions = None ):
@@ -32,10 +34,15 @@ def add_display_columns(table, options: WithOptions = None):
3234 if options .show_leases :
3335 table .add_column ("LEASED BY" )
3436 table .add_column ("LEASE STATUS" )
35- table .add_column ("START TIME" )
37+ if options .show_start_time :
38+ table .add_column ("START TIME" )
39+ if options .show_end_time :
40+ table .add_column ("END TIME" )
3641
3742
38- def add_exporter_row (table , exporter , options : WithOptions = None , lease_info : tuple [str , str , str ] | None = None ):
43+ def add_exporter_row (
44+ table , exporter , options : WithOptions = None , lease_info : tuple [str , str , str , str ] | None = None
45+ ):
3946 if options is None :
4047 options = WithOptions ()
4148 row_data = []
@@ -45,10 +52,15 @@ def add_exporter_row(table, exporter, options: WithOptions = None, lease_info: t
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 :
48- lease_client , lease_status , start_time = lease_info
55+ lease_client , lease_status , start_time , end_time = lease_info
4956 else :
50- lease_client , lease_status , start_time = "" , "Available" , ""
51- row_data .extend ([lease_client , lease_status , start_time ])
57+ lease_client , lease_status , start_time , end_time = "" , "Available" , "" , ""
58+ lease_row = [lease_client , lease_status ]
59+ if options .show_start_time :
60+ lease_row .append (start_time )
61+ if options .show_end_time :
62+ lease_row .append (end_time )
63+ row_data .extend (lease_row )
5264
5365 table .add_row (* row_data )
5466
@@ -98,11 +110,14 @@ def rich_add_rows(self, table, options: WithOptions = None):
98110 lease_client = self .lease .client
99111 lease_status = self .lease .get_status ()
100112 start_time = ""
101- if self .lease .effective_begin_time :
113+ if options . show_start_time and self .lease .effective_begin_time :
102114 start_time = self .lease .effective_begin_time .strftime ("%Y-%m-%d %H:%M:%S" )
103- lease_info = (lease_client , lease_status , start_time )
115+ end_time = ""
116+ if options .show_end_time and self .lease .effective_end_time :
117+ end_time = self .lease .effective_end_time .strftime ("%Y-%m-%d %H:%M:%S" )
118+ lease_info = (lease_client , lease_status , start_time , end_time )
104119 elif options and options .show_leases :
105- lease_info = ("" , "Available" , "" )
120+ lease_info = ("" , "Available" , "" , "" )
106121 add_exporter_row (table , self , options , lease_info )
107122
108123 def rich_add_names (self , names ):
@@ -118,6 +133,7 @@ class Lease(BaseModel):
118133 exporter : str
119134 conditions : list [kubernetes_pb2 .Condition ]
120135 effective_begin_time : datetime | None = None
136+ effective_end_time : datetime | None = None
121137
122138 model_config = ConfigDict (
123139 arbitrary_types_allowed = True ,
@@ -144,6 +160,12 @@ def from_protobuf(cls, data: client_pb2.Lease) -> Lease:
144160 tzinfo = datetime .now ().astimezone ().tzinfo ,
145161 )
146162
163+ effective_end_time = None
164+ if data .effective_end_time :
165+ effective_end_time = data .effective_end_time .ToDatetime (
166+ tzinfo = datetime .now ().astimezone ().tzinfo ,
167+ )
168+
147169 return cls (
148170 namespace = namespace ,
149171 name = name ,
@@ -152,6 +174,7 @@ def from_protobuf(cls, data: client_pb2.Lease) -> Lease:
152174 client = client ,
153175 exporter = exporter ,
154176 effective_begin_time = effective_begin_time ,
177+ effective_end_time = effective_end_time ,
155178 conditions = data .conditions ,
156179 )
157180
@@ -197,6 +220,8 @@ class ExporterList(BaseModel):
197220 next_page_token : str | None = Field (exclude = True )
198221 include_online : bool = Field (default = False , exclude = True )
199222 include_leases : bool = Field (default = False , exclude = True )
223+ include_start_time : bool = Field (default = False , exclude = True )
224+ include_end_time : bool = Field (default = False , exclude = True )
200225
201226 @classmethod
202227 def from_protobuf (cls , data : client_pb2 .ListExportersResponse ) -> ExporterList :
@@ -206,11 +231,21 @@ def from_protobuf(cls, data: client_pb2.ListExportersResponse) -> ExporterList:
206231 )
207232
208233 def rich_add_columns (self , table ):
209- options = WithOptions (show_online = self .include_online , show_leases = self .include_leases )
234+ options = WithOptions (
235+ show_online = self .include_online ,
236+ show_leases = self .include_leases ,
237+ show_start_time = self .include_start_time ,
238+ show_end_time = self .include_end_time ,
239+ )
210240 Exporter .rich_add_columns (table , options )
211241
212242 def rich_add_rows (self , table ):
213- options = WithOptions (show_online = self .include_online , show_leases = self .include_leases )
243+ options = WithOptions (
244+ show_online = self .include_online ,
245+ show_leases = self .include_leases ,
246+ show_start_time = self .include_start_time ,
247+ show_end_time = self .include_end_time ,
248+ )
214249 for exporter in self .exporters :
215250 exporter .rich_add_rows (table , options )
216251
0 commit comments