33from typing import Dict
44import click
55from tabulate import tabulate
6- from centml .sdk import (
7- DeploymentType ,
8- DeploymentStatus ,
9- ServiceStatus ,
10- ApiException ,
11- HardwareInstanceResponse ,
12- )
6+ from centml .sdk import DeploymentType , DeploymentStatus , ServiceStatus , ApiException , HardwareInstanceResponse
137from centml .sdk .api import get_centml_client
148
159
@@ -69,12 +63,8 @@ def _get_replica_info(deployment, depl_type):
6963 """Extract replica information handling V2/V3 field differences"""
7064 if depl_type == DeploymentType .CSERVE_V3 :
7165 return {
72- "min" : getattr (
73- deployment , "min_replicas" , getattr (deployment , "min_scale" , None )
74- ),
75- "max" : getattr (
76- deployment , "max_replicas" , getattr (deployment , "max_scale" , None )
77- ),
66+ "min" : getattr (deployment , "min_replicas" , getattr (deployment , "min_scale" , None )),
67+ "max" : getattr (deployment , "max_replicas" , getattr (deployment , "max_scale" , None )),
7868 }
7969 else : # V2
8070 return {"min" : deployment .min_scale , "max" : deployment .max_scale }
@@ -83,67 +73,36 @@ def _get_replica_info(deployment, depl_type):
8373def _get_ready_status (cclient , deployment ):
8474 api_status = deployment .status
8575 service_status = (
86- cclient .get_status (deployment .id ).service_status
87- if deployment .status == DeploymentStatus .ACTIVE
88- else None
76+ cclient .get_status (deployment .id ).service_status if deployment .status == DeploymentStatus .ACTIVE else None
8977 )
9078
9179 status_styles = {
9280 (DeploymentStatus .PAUSED , None ): ("paused" , "yellow" , "black" ),
9381 (DeploymentStatus .DELETED , None ): ("deleted" , "white" , "black" ),
9482 (DeploymentStatus .ACTIVE , ServiceStatus .HEALTHY ): ("ready" , "green" , "black" ),
95- (DeploymentStatus .ACTIVE , ServiceStatus .INITIALIZING ): (
96- "starting" ,
97- "black" ,
98- "white" ,
99- ),
100- (DeploymentStatus .ACTIVE , ServiceStatus .MISSING ): (
101- "starting" ,
102- "black" ,
103- "white" ,
104- ),
83+ (DeploymentStatus .ACTIVE , ServiceStatus .INITIALIZING ): ("starting" , "black" , "white" ),
84+ (DeploymentStatus .ACTIVE , ServiceStatus .MISSING ): ("starting" , "black" , "white" ),
10585 (DeploymentStatus .ACTIVE , ServiceStatus .ERROR ): ("error" , "red" , "black" ),
10686 (DeploymentStatus .ACTIVE , ServiceStatus .CREATECONTAINERCONFIGERROR ): (
10787 "createContainerConfigError" ,
10888 "red" ,
10989 "black" ,
11090 ),
111- (DeploymentStatus .ACTIVE , ServiceStatus .CRASHLOOPBACKOFF ): (
112- "crashLoopBackOff" ,
113- "red" ,
114- "black" ,
115- ),
116- (DeploymentStatus .ACTIVE , ServiceStatus .IMAGEPULLBACKOFF ): (
117- "imagePullBackOff" ,
118- "red" ,
119- "black" ,
120- ),
121- (DeploymentStatus .ACTIVE , ServiceStatus .PROGRESSDEADLINEEXCEEDED ): (
122- "progressDeadlineExceeded" ,
123- "red" ,
124- "black" ,
125- ),
91+ (DeploymentStatus .ACTIVE , ServiceStatus .CRASHLOOPBACKOFF ): ("crashLoopBackOff" , "red" , "black" ),
92+ (DeploymentStatus .ACTIVE , ServiceStatus .IMAGEPULLBACKOFF ): ("imagePullBackOff" , "red" , "black" ),
93+ (DeploymentStatus .ACTIVE , ServiceStatus .PROGRESSDEADLINEEXCEEDED ): ("progressDeadlineExceeded" , "red" , "black" ),
12694 }
12795
128- style = status_styles .get (
129- (api_status , service_status ), ("unknown" , "black" , "white" )
130- )
96+ style = status_styles .get ((api_status , service_status ), ("unknown" , "black" , "white" ))
13197 # Handle foreground and background colors
13298 return click .style (style [0 ], fg = style [1 ], bg = style [2 ])
13399
134100
135101@click .command (help = "List all deployments" )
136- @click .argument (
137- "type" ,
138- type = click .Choice (list (depl_name_to_type_map .keys ())),
139- required = False ,
140- default = None ,
141- )
102+ @click .argument ("type" , type = click .Choice (list (depl_name_to_type_map .keys ())), required = False , default = None )
142103def ls (type ):
143104 with get_centml_client () as cclient :
144- depl_type = (
145- depl_name_to_type_map [type ] if type in depl_name_to_type_map else None
146- )
105+ depl_type = depl_name_to_type_map [type ] if type in depl_name_to_type_map else None
147106 deployments = cclient .get (depl_type )
148107 rows = []
149108 for d in deployments :
@@ -225,10 +184,7 @@ def get(type, id):
225184 elif depl_type == DeploymentType .COMPUTE_V2 :
226185 click .echo (
227186 tabulate (
228- [
229- ("Username" , "centml" ),
230- ("SSH key" , _format_ssh_key (deployment .ssh_public_key )),
231- ],
187+ [("Username" , "centml" ), ("SSH key" , _format_ssh_key (deployment .ssh_public_key ))],
232188 tablefmt = "rounded_outline" ,
233189 disable_numparse = True ,
234190 )
@@ -240,12 +196,8 @@ def get(type, id):
240196 (
241197 "Parallelism" ,
242198 {
243- "tensor" : deployment .recipe .additional_properties .get (
244- "tensor_parallel_size" , "N/A"
245- ),
246- "pipeline" : deployment .recipe .additional_properties .get (
247- "pipeline_parallel_size" , "N/A"
248- ),
199+ "tensor" : deployment .recipe .additional_properties .get ("tensor_parallel_size" , "N/A" ),
200+ "pipeline" : deployment .recipe .additional_properties .get ("pipeline_parallel_size" , "N/A" ),
249201 },
250202 ),
251203 ("Replicas" , replica_info ),
@@ -255,26 +207,14 @@ def get(type, id):
255207 # Add V3-specific rollout information
256208 if depl_type == DeploymentType .CSERVE_V3 :
257209 rollout_info = {}
258- if (
259- hasattr (deployment , "max_surge" )
260- and deployment .max_surge is not None
261- ):
210+ if hasattr (deployment , "max_surge" ) and deployment .max_surge is not None :
262211 rollout_info ["max_surge" ] = deployment .max_surge
263- if (
264- hasattr (deployment , "max_unavailable" )
265- and deployment .max_unavailable is not None
266- ):
212+ if hasattr (deployment , "max_unavailable" ) and deployment .max_unavailable is not None :
267213 rollout_info ["max_unavailable" ] = deployment .max_unavailable
268214 if rollout_info :
269215 display_rows .append (("Rollout strategy" , rollout_info ))
270216
271- click .echo (
272- tabulate (
273- display_rows ,
274- tablefmt = "rounded_outline" ,
275- disable_numparse = True ,
276- )
277- )
217+ click .echo (tabulate (display_rows , tablefmt = "rounded_outline" , disable_numparse = True ))
278218
279219
280220@click .command (help = "Delete a deployment" )
0 commit comments