33from typing import Dict
44import click
55from tabulate import tabulate
6- from centml .sdk import DeploymentType , DeploymentStatus , ServiceStatus , ApiException , HardwareInstanceResponse
6+ from centml .sdk import (
7+ DeploymentType ,
8+ DeploymentStatus ,
9+ ServiceStatus ,
10+ ApiException ,
11+ HardwareInstanceResponse ,
12+ )
713from centml .sdk .api import get_centml_client
814
915
1016depl_type_to_name_map = {
11- DeploymentType .INFERENCE : ' inference' ,
12- DeploymentType .COMPUTE : ' compute' ,
13- DeploymentType .COMPILATION : ' compilation' ,
14- DeploymentType .INFERENCE_V2 : ' inference' ,
15- DeploymentType .COMPUTE_V2 : ' compute' ,
16- DeploymentType .CSERVE : ' cserve' ,
17- DeploymentType .CSERVE_V2 : ' cserve-v2' ,
18- DeploymentType .CSERVE_V3 : ' cserve' ,
19- DeploymentType .RAG : ' rag' ,
17+ DeploymentType .INFERENCE : " inference" ,
18+ DeploymentType .COMPUTE : " compute" ,
19+ DeploymentType .COMPILATION : " compilation" ,
20+ DeploymentType .INFERENCE_V2 : " inference" ,
21+ DeploymentType .COMPUTE_V2 : " compute" ,
22+ DeploymentType .CSERVE : " cserve" ,
23+ DeploymentType .CSERVE_V2 : " cserve-v2" ,
24+ DeploymentType .CSERVE_V3 : " cserve" ,
25+ DeploymentType .RAG : " rag" ,
2026}
2127depl_name_to_type_map = {
22- ' inference' : DeploymentType .INFERENCE_V2 ,
23- ' cserve' : DeploymentType .CSERVE_V3 ,
24- ' cserve-v2' : DeploymentType .CSERVE_V2 ,
25- ' cserve-v3' : DeploymentType .CSERVE_V3 ,
26- ' compute' : DeploymentType .COMPUTE_V2 ,
27- ' rag' : DeploymentType .RAG ,
28+ " inference" : DeploymentType .INFERENCE_V2 ,
29+ " cserve" : DeploymentType .CSERVE_V3 ,
30+ " cserve-v2" : DeploymentType .CSERVE_V2 ,
31+ " cserve-v3" : DeploymentType .CSERVE_V3 ,
32+ " compute" : DeploymentType .COMPUTE_V2 ,
33+ " rag" : DeploymentType .RAG ,
2834}
2935
3036
@@ -63,8 +69,12 @@ def _get_replica_info(deployment, depl_type):
6369 """Extract replica information handling V2/V3 field differences"""
6470 if depl_type == DeploymentType .CSERVE_V3 :
6571 return {
66- "min" : getattr (deployment , 'min_replicas' , getattr (deployment , 'min_scale' , None )),
67- "max" : getattr (deployment , 'max_replicas' , getattr (deployment , 'max_scale' , None )),
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+ ),
6878 }
6979 else : # V2
7080 return {"min" : deployment .min_scale , "max" : deployment .max_scale }
@@ -73,36 +83,67 @@ def _get_replica_info(deployment, depl_type):
7383def _get_ready_status (cclient , deployment ):
7484 api_status = deployment .status
7585 service_status = (
76- cclient .get_status (deployment .id ).service_status if deployment .status == DeploymentStatus .ACTIVE else None
86+ cclient .get_status (deployment .id ).service_status
87+ if deployment .status == DeploymentStatus .ACTIVE
88+ else None
7789 )
7890
7991 status_styles = {
8092 (DeploymentStatus .PAUSED , None ): ("paused" , "yellow" , "black" ),
8193 (DeploymentStatus .DELETED , None ): ("deleted" , "white" , "black" ),
8294 (DeploymentStatus .ACTIVE , ServiceStatus .HEALTHY ): ("ready" , "green" , "black" ),
83- (DeploymentStatus .ACTIVE , ServiceStatus .INITIALIZING ): ("starting" , "black" , "white" ),
84- (DeploymentStatus .ACTIVE , ServiceStatus .MISSING ): ("starting" , "black" , "white" ),
95+ (DeploymentStatus .ACTIVE , ServiceStatus .INITIALIZING ): (
96+ "starting" ,
97+ "black" ,
98+ "white" ,
99+ ),
100+ (DeploymentStatus .ACTIVE , ServiceStatus .MISSING ): (
101+ "starting" ,
102+ "black" ,
103+ "white" ,
104+ ),
85105 (DeploymentStatus .ACTIVE , ServiceStatus .ERROR ): ("error" , "red" , "black" ),
86106 (DeploymentStatus .ACTIVE , ServiceStatus .CREATECONTAINERCONFIGERROR ): (
87107 "createContainerConfigError" ,
88108 "red" ,
89109 "black" ,
90110 ),
91- (DeploymentStatus .ACTIVE , ServiceStatus .CRASHLOOPBACKOFF ): ("crashLoopBackOff" , "red" , "black" ),
92- (DeploymentStatus .ACTIVE , ServiceStatus .IMAGEPULLBACKOFF ): ("imagePullBackOff" , "red" , "black" ),
93- (DeploymentStatus .ACTIVE , ServiceStatus .PROGRESSDEADLINEEXCEEDED ): ("progressDeadlineExceeded" , "red" , "black" ),
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+ ),
94126 }
95127
96- style = status_styles .get ((api_status , service_status ), ("unknown" , "black" , "white" ))
128+ style = status_styles .get (
129+ (api_status , service_status ), ("unknown" , "black" , "white" )
130+ )
97131 # Handle foreground and background colors
98132 return click .style (style [0 ], fg = style [1 ], bg = style [2 ])
99133
100134
101135@click .command (help = "List all deployments" )
102- @click .argument ("type" , type = click .Choice (list (depl_name_to_type_map .keys ())), required = False , default = None )
136+ @click .argument (
137+ "type" ,
138+ type = click .Choice (list (depl_name_to_type_map .keys ())),
139+ required = False ,
140+ default = None ,
141+ )
103142def ls (type ):
104143 with get_centml_client () as cclient :
105- depl_type = depl_name_to_type_map [type ] if type in depl_name_to_type_map else None
144+ depl_type = (
145+ depl_name_to_type_map [type ] if type in depl_name_to_type_map else None
146+ )
106147 deployments = cclient .get (depl_type )
107148 rows = []
108149 for d in deployments :
@@ -184,7 +225,10 @@ def get(type, id):
184225 elif depl_type == DeploymentType .COMPUTE_V2 :
185226 click .echo (
186227 tabulate (
187- [("Username" , "centml" ), ("SSH key" , _format_ssh_key (deployment .ssh_public_key ))],
228+ [
229+ ("Username" , "centml" ),
230+ ("SSH key" , _format_ssh_key (deployment .ssh_public_key )),
231+ ],
188232 tablefmt = "rounded_outline" ,
189233 disable_numparse = True ,
190234 )
@@ -196,24 +240,34 @@ def get(type, id):
196240 (
197241 "Parallelism" ,
198242 {
199- "tensor" : deployment .recipe .additional_properties .get ('tensor_parallel_size' , 'N/A' ),
200- "pipeline" : deployment .recipe .additional_properties .get ('pipeline_parallel_size' , 'N/A' ),
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+ ),
201249 },
202250 ),
203251 ("Replicas" , replica_info ),
204252 ("Max concurrency" , deployment .concurrency or "None" ),
205253 ]
206-
254+
207255 # Add V3-specific rollout information
208256 if depl_type == DeploymentType .CSERVE_V3 :
209257 rollout_info = {}
210- if hasattr (deployment , 'max_surge' ) and deployment .max_surge is not None :
211- rollout_info ['max_surge' ] = deployment .max_surge
212- if hasattr (deployment , 'max_unavailable' ) and deployment .max_unavailable is not None :
213- rollout_info ['max_unavailable' ] = deployment .max_unavailable
258+ if (
259+ hasattr (deployment , "max_surge" )
260+ and deployment .max_surge is not None
261+ ):
262+ rollout_info ["max_surge" ] = deployment .max_surge
263+ if (
264+ hasattr (deployment , "max_unavailable" )
265+ and deployment .max_unavailable is not None
266+ ):
267+ rollout_info ["max_unavailable" ] = deployment .max_unavailable
214268 if rollout_info :
215269 display_rows .append (("Rollout strategy" , rollout_info ))
216-
270+
217271 click .echo (
218272 tabulate (
219273 display_rows ,
0 commit comments