Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Commit

Permalink
feat: Update the image alias cmd/func API to follow manager API updat…
Browse files Browse the repository at this point in the history
…es (#211)
  • Loading branch information
fregataa committed Mar 31, 2022
1 parent 5b9c208 commit 3702ab6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions changes/211.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow specifying the architecture when setting image aliases
5 changes: 3 additions & 2 deletions src/ai/backend/client/cli/admin/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ async def rescan_images_impl(registry: str) -> None:
@image.command()
@click.argument('alias', type=str)
@click.argument('target', type=str)
def alias(alias, target):
@click.option('--arch', type=str, default=None, help='Set an explicit architecture.')
def alias(alias, target, arch):
"""Add an image alias."""
with Session() as session:
try:
result = session.Image.alias_image(alias, target)
result = session.Image.alias_image(alias, target, arch)
except Exception as e:
print_error(e)
sys.exit(1)
Expand Down
11 changes: 9 additions & 2 deletions src/ai/backend/client/func/image.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Sequence
from typing import Optional, Sequence

from ai.backend.client.output.fields import image_fields
from ai.backend.client.output.types import FieldSpec
Expand Down Expand Up @@ -66,7 +66,12 @@ async def rescan_images(cls, registry: str):

@api_function
@classmethod
async def alias_image(cls, alias: str, target: str) -> dict:
async def alias_image(
cls,
alias: str,
target: str,
arch: Optional[str] = None,
) -> dict:
q = 'mutation($alias: String!, $target: String!) {' \
' alias_image(alias: $alias, target: $target) {' \
' ok msg' \
Expand All @@ -76,6 +81,8 @@ async def alias_image(cls, alias: str, target: str) -> dict:
'alias': alias,
'target': target,
}
if arch:
variables = {'architecture': arch, **variables}
data = await api_session.get().Admin._query(q, variables)
return data['alias_image']

Expand Down

0 comments on commit 3702ab6

Please sign in to comment.