Skip to content

Commit

Permalink
chore: fix by comments
Browse files Browse the repository at this point in the history
  • Loading branch information
xianml committed Sep 6, 2024
1 parent 2f31605 commit 64d4d13
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 81 deletions.
99 changes: 50 additions & 49 deletions src/bentoml_cli/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
def raise_deployment_config_error(err: BentoMLException, action: str) -> t.NoReturn:
if err.error_code == HTTPStatus.UNAUTHORIZED:
raise BentoMLException(
f"{err}\n* BentoCloud API token is required for authorization. Run `bentoml cloud login` command to login first"
f"{err}\n* BentoCloud API token is required for authorization. Run `bentoml cloud login` command to login"
) from None
raise BentoMLException(
f"Failed to {action} deployment due to invalid configuration: {err}"
Expand Down Expand Up @@ -609,31 +609,32 @@ def list_command( # type: ignore
"""List existing deployments on BentoCloud."""
try:
d_list = Deployment.list(cluster=cluster, search=search)
res: list[dict[str, t.Any]] = [d.to_dict() for d in d_list]
if output == "table":
table = Table(box=None, expand=True)
table.add_column("Deployment", overflow="fold")
table.add_column("created_at", overflow="fold")
table.add_column("Bento", overflow="fold")
table.add_column("Status", overflow="fold")
table.add_column("Region", overflow="fold")
for info in d_list:
table.add_row(
info.name,
info.created_at,
info.get_bento(refetch=False),
info.get_status(refetch=False).status,
info.cluster,
)
console.print(table)
elif output == "json":
info = json.dumps(res, indent=2, default=str)
console.print_json(info)
else:
info = yaml.dump(res, indent=2, sort_keys=False)
console.print(Syntax(info, "yaml", background_color="default"))
except BentoMLException as e:
raise_deployment_config_error(e, "list")
res: list[dict[str, t.Any]] = [d.to_dict() for d in d_list]
if output == "table":
table = Table(box=None, expand=True)
table.add_column("Deployment", overflow="fold")
table.add_column("created_at", overflow="fold")
table.add_column("Bento", overflow="fold")
table.add_column("Status", overflow="fold")
table.add_column("Region", overflow="fold")
for info in d_list:
table.add_row(
info.name,
info.created_at,
info.get_bento(refetch=False),
info.get_status(refetch=False).status,
info.cluster,
)
console.print(table)
elif output == "json":
info = json.dumps(res, indent=2, default=str)
console.print_json(info)
else:
info = yaml.dump(res, indent=2, sort_keys=False)
console.print(Syntax(info, "yaml", background_color="default"))



@deployment_command.command()
Expand All @@ -652,33 +653,33 @@ def list_instance_types( # type: ignore
"""List existing instance types in cluster on BentoCloud."""
try:
d_list = Deployment.list_instance_types(cluster=cluster)
res: list[dict[str, t.Any]] = [d.to_dict() for d in d_list]
if output == "table":
table = Table(box=None, expand=True)
table.add_column("Name", overflow="fold")
table.add_column("Price", overflow="fold")
table.add_column("CPU", overflow="fold")
table.add_column("Memory", overflow="fold")
table.add_column("GPU", overflow="fold")
table.add_column("GPU Type", overflow="fold")
for info in d_list:
table.add_row(
info.name,
info.price,
info.cpu,
info.memory,
info.gpu,
info.gpu_type,
)
console.print(table)
elif output == "json":
info = json.dumps(res, indent=2, default=str)
console.print_json(info)
else:
info = yaml.dump(res, indent=2, sort_keys=False)
console.print(Syntax(info, "yaml", background_color="default"))
except BentoMLException as e:
raise_deployment_config_error(e, "list_instance_types")
res: list[dict[str, t.Any]] = [d.to_dict() for d in d_list]
if output == "table":
table = Table(box=None, expand=True)
table.add_column("Name", overflow="fold")
table.add_column("Price", overflow="fold")
table.add_column("CPU", overflow="fold")
table.add_column("Memory", overflow="fold")
table.add_column("GPU", overflow="fold")
table.add_column("GPU Type", overflow="fold")
for info in d_list:
table.add_row(
info.name,
info.price,
info.cpu,
info.memory,
info.gpu,
info.gpu_type,
)
console.print(table)
elif output == "json":
info = json.dumps(res, indent=2, default=str)
console.print_json(info)
else:
info = yaml.dump(res, indent=2, sort_keys=False)
console.print(Syntax(info, "yaml", background_color="default"))


def create_deployment(
Expand Down
64 changes: 32 additions & 32 deletions src/bentoml_cli/secret.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,39 +45,39 @@ def list(
"""List all secrets on BentoCloud."""
try:
secrets = Secret.list(search=search)
if output == "table":
table = Table(box=None, expand=True)
table.add_column("Secret", overflow="fold")
table.add_column("Created_At", overflow="fold")
table.add_column("Mount_As", overflow="fold")
table.add_column("Keys", overflow="fold")
table.add_column("Path", overflow="fold")

for secret in secrets:
keys = [item.key for item in secret.content.items]
mountAs = secret.content.type
if mountAs == "env":
mountAs = "Environment Variable"
elif mountAs == "mountfile":
mountAs = "File"
table.add_row(
secret.name,
secret.created_at.strftime("%Y-%m-%d %H:%M:%S"),
mountAs,
", ".join(keys),
secret.content.path if secret.content.path else "-",
)
console.print(table)
elif output == "json":
res: t.List[dict[str, t.Any]] = [s.to_dict() for s in secrets]
info = json.dumps(res, indent=2, default=str)
console.print(info)
elif output == "yaml":
res: t.List[dict[str, t.Any]] = [s.to_dict() for s in secrets]
info = yaml.dump(res, indent=2, sort_keys=False)
console.print(Syntax(info, "yaml", background_color="default"))
except BentoMLException as e:
raise_secret_error(e, "list")
if output == "table":
table = Table(box=None, expand=True)
table.add_column("Secret", overflow="fold")
table.add_column("Created_At", overflow="fold")
table.add_column("Mount_As", overflow="fold")
table.add_column("Keys", overflow="fold")
table.add_column("Path", overflow="fold")

for secret in secrets:
keys = [item.key for item in secret.content.items]
mountAs = secret.content.type
if mountAs == "env":
mountAs = "Environment Variable"
elif mountAs == "mountfile":
mountAs = "File"
table.add_row(
secret.name,
secret.created_at.strftime("%Y-%m-%d %H:%M:%S"),
mountAs,
", ".join(keys),
secret.content.path if secret.content.path else "-",
)
console.print(table)
elif output == "json":
res: t.List[dict[str, t.Any]] = [s.to_dict() for s in secrets]
info = json.dumps(res, indent=2, default=str)
console.print(info)
elif output == "yaml":
res: t.List[dict[str, t.Any]] = [s.to_dict() for s in secrets]
info = yaml.dump(res, indent=2, sort_keys=False)
console.print(Syntax(info, "yaml", background_color="default"))


def parse_kvs_argument_callback(
Expand Down Expand Up @@ -140,7 +140,7 @@ def parse_from_file_argument_callback(
def raise_secret_error(err: BentoMLException, action: str) -> t.NoReturn:
if err.error_code == HTTPStatus.UNAUTHORIZED:
raise BentoMLException(
f"{err}\n* BentoCloud API token is required for authorization. Run `bentoml cloud login` command to login first"
f"{err}\n* BentoCloud API token is required for authorization. Run `bentoml cloud login` command to login"
) from None
raise BentoMLException(f"Failed to {action} secret due to: {err}")

Expand Down

0 comments on commit 64d4d13

Please sign in to comment.