-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Revamp ContainerRegistryNode API
- Loading branch information
1 parent
40147f2
commit adc707a
Showing
6 changed files
with
262 additions
and
326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,33 @@ | ||
from __future__ import annotations | ||
|
||
import textwrap | ||
from ai.backend.client.request import Request | ||
|
||
from ..session import api_session | ||
from .base import BaseFunction, api_function | ||
|
||
__all__ = ("ContainerRegistry",) | ||
|
||
|
||
class ContainerRegistry(BaseFunction): | ||
""" | ||
Provides a shortcut of :func:`Admin.query() | ||
<ai.backend.client.admin.Admin.query>` that fetches, modifies various container registry | ||
information. | ||
.. note:: | ||
All methods in this function class require your API access key to | ||
have the *admin* privilege. | ||
Provides functions to manage container registries. | ||
""" | ||
|
||
@api_function | ||
@classmethod | ||
async def associate_group(cls, registry_id: str, group_id: str) -> dict: | ||
# TODO: Implement params type | ||
async def patch_container_registry(cls, registry_id: str, params) -> None: | ||
""" | ||
Associate container_registry with group. | ||
Updates the container registry information, and return the container registry. | ||
:param registry_id: ID of the container registry. | ||
:param group_id: ID of the group. | ||
""" | ||
query = textwrap.dedent( | ||
"""\ | ||
mutation($registry_id: String!, $group_id: String!) { | ||
associate_container_registry_with_group( | ||
registry_id: $registry_id, group_id: $group_id) { | ||
ok msg | ||
} | ||
} | ||
""" | ||
) | ||
variables = {"registry_id": registry_id, "group_id": group_id} | ||
data = await api_session.get().Admin._query(query, variables) | ||
return data["associate_container_registry_with_group"] | ||
|
||
@api_function | ||
@classmethod | ||
async def disassociate_group(cls, registry_id: str, group_id: str) -> dict: | ||
:param params: Parameters to update the container registry. | ||
""" | ||
Disassociate container_registry with group. | ||
|
||
:param registry_id: ID of the container registry. | ||
:param group_id: ID of the group. | ||
""" | ||
query = textwrap.dedent( | ||
"""\ | ||
mutation($registry_id: String!, $group_id: String!) { | ||
disassociate_container_registry_with_group( | ||
registry_id: $registry_id, group_id: $group_id) { | ||
ok msg | ||
} | ||
} | ||
""" | ||
request = Request( | ||
"PATCH", | ||
f"/container-registries/{registry_id}", | ||
) | ||
variables = {"registry_id": registry_id, "group_id": group_id} | ||
data = await api_session.get().Admin._query(query, variables) | ||
return data["disassociate_container_registry_with_group"] | ||
request.set_json(params) | ||
|
||
async with request.fetch() as resp: | ||
await resp.read() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.