1+ import re
12from pprint import pformat
2- from typing import NamedTuple
3+ from typing import NamedTuple , Optional
34
45import click
56import questionary as q
@@ -34,6 +35,7 @@ class EndpointRow(NamedTuple):
3435
3536@click .pass_context
3637@endpoints .command ("list" )
38+ @click .option ("--name" , "-n" , help = "Regex to use to filter by name" , default = None )
3739@click .option ("-o" , "--orderby" , required = False , type = click .Choice (EndpointRow ._fields ), help = "How to order the table" )
3840@click .option (
3941 "-d" ,
@@ -45,7 +47,7 @@ class EndpointRow(NamedTuple):
4547 help = "Whether to sort in descending order" ,
4648)
4749@click .pass_context
48- def list_endpoints (ctx : click .Context , orderby , descending ):
50+ def list_endpoints (ctx : click .Context , name : Optional [ str ], orderby , descending : bool ):
4951 """List all of your Endpoints"""
5052 client = init_client (ctx )
5153
@@ -69,20 +71,21 @@ def list_endpoints(ctx: click.Context, orderby, descending):
6971 model_endpoints = client .list_model_endpoints ()
7072 endpoint_rows = []
7173 for servable_endpoint in model_endpoints :
72- row = EndpointRow (
73- servable_endpoint .model_endpoint .id ,
74- servable_endpoint .model_endpoint .name ,
75- servable_endpoint .model_endpoint .bundle_name ,
76- servable_endpoint .model_endpoint .status ,
77- servable_endpoint .model_endpoint .endpoint_type ,
78- str ((servable_endpoint .model_endpoint .deployment_state or {}).get ("min_workers" , "" )),
79- str ((servable_endpoint .model_endpoint .deployment_state or {}).get ("max_workers" , "" )),
80- str ((servable_endpoint .model_endpoint .deployment_state or {}).get ("available_workers" , "" )),
81- str ((servable_endpoint .model_endpoint .deployment_state or {}).get ("unavailable_workers" , "" )),
82- str ((servable_endpoint .model_endpoint .resource_state or {}).get ("gpus" , "0" )),
83- servable_endpoint .model_endpoint .metadata or "{}" ,
84- )
85- endpoint_rows .append (row )
74+ if name is None or re .match (name , servable_endpoint .model_endpoint .name ):
75+ row = EndpointRow (
76+ servable_endpoint .model_endpoint .id ,
77+ servable_endpoint .model_endpoint .name ,
78+ servable_endpoint .model_endpoint .bundle_name ,
79+ servable_endpoint .model_endpoint .status ,
80+ servable_endpoint .model_endpoint .endpoint_type ,
81+ str ((servable_endpoint .model_endpoint .deployment_state or {}).get ("min_workers" , "" )),
82+ str ((servable_endpoint .model_endpoint .deployment_state or {}).get ("max_workers" , "" )),
83+ str ((servable_endpoint .model_endpoint .deployment_state or {}).get ("available_workers" , "" )),
84+ str ((servable_endpoint .model_endpoint .deployment_state or {}).get ("unavailable_workers" , "" )),
85+ str ((servable_endpoint .model_endpoint .resource_state or {}).get ("gpus" , "0" )),
86+ servable_endpoint .model_endpoint .metadata or "{}" ,
87+ )
88+ endpoint_rows .append (row )
8689
8790 if orderby is not None :
8891 endpoint_rows = sorted (endpoint_rows , key = lambda x : getattr (x , orderby ), reverse = descending )
0 commit comments