1
+ import re
1
2
from pprint import pformat
2
- from typing import NamedTuple
3
+ from typing import NamedTuple , Optional
3
4
4
5
import click
5
6
import questionary as q
@@ -34,6 +35,7 @@ class EndpointRow(NamedTuple):
34
35
35
36
@click .pass_context
36
37
@endpoints .command ("list" )
38
+ @click .option ("--name" , "-n" , help = "Regex to use to filter by name" , default = None )
37
39
@click .option ("-o" , "--orderby" , required = False , type = click .Choice (EndpointRow ._fields ), help = "How to order the table" )
38
40
@click .option (
39
41
"-d" ,
@@ -45,7 +47,7 @@ class EndpointRow(NamedTuple):
45
47
help = "Whether to sort in descending order" ,
46
48
)
47
49
@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 ):
49
51
"""List all of your Endpoints"""
50
52
client = init_client (ctx )
51
53
@@ -69,20 +71,21 @@ def list_endpoints(ctx: click.Context, orderby, descending):
69
71
model_endpoints = client .list_model_endpoints ()
70
72
endpoint_rows = []
71
73
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 )
86
89
87
90
if orderby is not None :
88
91
endpoint_rows = sorted (endpoint_rows , key = lambda x : getattr (x , orderby ), reverse = descending )
0 commit comments