33from dataclasses import dataclass , field
44from datetime import datetime , timedelta
55
6- import yaml
76from google .protobuf import duration_pb2 , field_mask_pb2 , json_format
87from grpc .aio import Channel
98from jumpstarter_protocol import client_pb2 , client_pb2_grpc , kubernetes_pb2
10- from pydantic import BaseModel , ConfigDict , Field , field_serializer
9+ from pydantic import ConfigDict , Field , field_serializer
1110
1211from jumpstarter .common .grpc import translate_grpc_exceptions
12+ from jumpstarter .common .pydantic import SerializableBaseModel
1313
1414
1515def parse_identifier (identifier : str , kind : str ) -> (str , str ):
@@ -35,7 +35,7 @@ def parse_lease_identifier(identifier: str) -> (str, str):
3535 return parse_identifier (identifier , "leases" )
3636
3737
38- class Exporter (BaseModel ):
38+ class Exporter (SerializableBaseModel ):
3939 namespace : str
4040 name : str
4141 labels : dict [str , str ]
@@ -46,7 +46,7 @@ def from_protobuf(cls, data: client_pb2.Exporter) -> Exporter:
4646 return cls (namespace = namespace , name = name , labels = data .labels )
4747
4848
49- class Lease (BaseModel ):
49+ class Lease (SerializableBaseModel ):
5050 namespace : str
5151 name : str
5252 selector : str
@@ -92,14 +92,8 @@ def from_protobuf(cls, data: client_pb2.Lease) -> Lease:
9292 conditions = data .conditions ,
9393 )
9494
95- def dump_json (self ):
96- return self .model_dump_json (indent = 4 , by_alias = True )
9795
98- def dump_yaml (self ):
99- return yaml .safe_dump (self .model_dump (mode = "json" , by_alias = True ), indent = 2 )
100-
101-
102- class ExporterList (BaseModel ):
96+ class ExporterList (SerializableBaseModel ):
10397 exporters : list [Exporter ]
10498 next_page_token : str | None = Field (exclude = True )
10599
@@ -110,14 +104,8 @@ def from_protobuf(cls, data: client_pb2.ListExportersResponse) -> ExporterList:
110104 next_page_token = data .next_page_token ,
111105 )
112106
113- def dump_json (self ):
114- return self .model_dump_json (indent = 4 , by_alias = True )
115-
116- def dump_yaml (self ):
117- return yaml .safe_dump (self .model_dump (mode = "json" , by_alias = True ), indent = 2 )
118107
119-
120- class LeaseList (BaseModel ):
108+ class LeaseList (SerializableBaseModel ):
121109 leases : list [Lease ]
122110 next_page_token : str | None = Field (exclude = True )
123111
@@ -128,12 +116,6 @@ def from_protobuf(cls, data: client_pb2.ListLeasesResponse) -> LeaseList:
128116 next_page_token = data .next_page_token ,
129117 )
130118
131- def dump_json (self ):
132- return self .model_dump_json (indent = 4 , by_alias = True )
133-
134- def dump_yaml (self ):
135- return yaml .safe_dump (self .model_dump (mode = "json" , by_alias = True ), indent = 2 )
136-
137119
138120@dataclass (kw_only = True , slots = True )
139121class ClientService :
0 commit comments