Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f3e96e4

Browse files
authoredMar 3, 2023
filter bundles and endpoints by name in CLI (#84)
1 parent 733ad19 commit f3e96e4

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed
 

‎launch/cli/bundles.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import re
2+
from typing import Optional
3+
14
import click
25
from rich.syntax import Syntax
36
from rich.table import Column, Table
@@ -15,8 +18,9 @@ def bundles(ctx: click.Context):
1518

1619

1720
@bundles.command("list")
21+
@click.option("--name", "-n", help="Regex to use to filter by name", default=None)
1822
@click.pass_context
19-
def list_bundles(ctx: click.Context):
23+
def list_bundles(ctx: click.Context, name: Optional[str]):
2024
"""
2125
List all of your Bundles
2226
"""
@@ -31,13 +35,15 @@ def list_bundles(ctx: click.Context):
3135
title_justify="left",
3236
)
3337
with spinner("Fetching bundles"):
34-
for model_bundle in client.list_model_bundles():
35-
table.add_row(
36-
model_bundle.id,
37-
model_bundle.name,
38-
model_bundle.location,
39-
model_bundle.packaging_type,
40-
)
38+
model_bundles = client.list_model_bundles()
39+
for model_bundle in model_bundles:
40+
if name is None or re.match(name, model_bundle.name):
41+
table.add_row(
42+
model_bundle.id,
43+
model_bundle.name,
44+
model_bundle.location,
45+
model_bundle.packaging_type,
46+
)
4147
pretty_print(table)
4248

4349

‎launch/cli/endpoints.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import re
12
from pprint import pformat
2-
from typing import NamedTuple
3+
from typing import NamedTuple, Optional
34

45
import click
56
import 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

Comments
 (0)