Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(BA-501): Add draft vFolder handler Interface of manager #3493

Merged
merged 4 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/3493.enhance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add skeleton vFolder handler Interface of manager
65 changes: 63 additions & 2 deletions python.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
// "prometheus-client~=0.21.1",
// "psutil~=6.0",
// "pycryptodome>=3.20.0",
// "pydantic~=2.9.2",
// "pydantic[email]~=2.9.2",
// "pyhumps~=3.8.0",
// "pyroscope-io~=0.8.8",
// "pytest-aiohttp~=1.0.5",
Expand Down Expand Up @@ -1530,6 +1530,46 @@
"requires_python": "<3.13,>=3.7",
"version": "0.5.14"
},
{
"artifacts": [
{
"algorithm": "sha256",
"hash": "b4c34b7d10b51bcc3a5071e7b8dee77939f1e878477eeecc965e9835f63c6c86",
"url": "https://files.pythonhosted.org/packages/68/1b/e0a87d256e40e8c888847551b20a017a6b98139178505dc7ffb96f04e954/dnspython-2.7.0-py3-none-any.whl"
},
{
"algorithm": "sha256",
"hash": "ce9c432eda0dc91cf618a5cedf1a4e142651196bbcd2c80e89ed5a907e5cfaf1",
"url": "https://files.pythonhosted.org/packages/b5/4a/263763cb2ba3816dd94b08ad3a33d5fdae34ecb856678773cc40a3605829/dnspython-2.7.0.tar.gz"
}
],
"project_name": "dnspython",
"requires_dists": [
"aioquic>=1.0.0; extra == \"doq\"",
"black>=23.1.0; extra == \"dev\"",
"coverage>=7.0; extra == \"dev\"",
"cryptography>=43; extra == \"dnssec\"",
"flake8>=7; extra == \"dev\"",
"h2>=4.1.0; extra == \"doh\"",
"httpcore>=1.0.0; extra == \"doh\"",
"httpx>=0.26.0; extra == \"doh\"",
"hypercorn>=0.16.0; extra == \"dev\"",
"idna>=3.7; extra == \"idna\"",
"mypy>=1.8; extra == \"dev\"",
"pylint>=3; extra == \"dev\"",
"pytest-cov>=4.1.0; extra == \"dev\"",
"pytest>=7.4; extra == \"dev\"",
"quart-trio>=0.11.0; extra == \"dev\"",
"sphinx-rtd-theme>=2.0.0; extra == \"dev\"",
"sphinx>=7.2.0; extra == \"dev\"",
"trio>=0.23; extra == \"trio\"",
"twine>=4.0.0; extra == \"dev\"",
"wheel>=0.42.0; extra == \"dev\"",
"wmi>=1.5.1; extra == \"wmi\""
],
"requires_python": ">=3.9",
"version": "2.7.0"
},
{
"artifacts": [
{
Expand All @@ -1551,6 +1591,27 @@
"requires_python": ">=3.8",
"version": "1.6.6"
},
{
"artifacts": [
{
"algorithm": "sha256",
"hash": "561977c2d73ce3611850a06fa56b414621e0c8faa9d66f2611407d87465da631",
"url": "https://files.pythonhosted.org/packages/d7/ee/bf0adb559ad3c786f12bcbc9296b3f5675f529199bef03e2df281fa1fadb/email_validator-2.2.0-py3-none-any.whl"
},
{
"algorithm": "sha256",
"hash": "cb690f344c617a714f22e66ae771445a1ceb46821152df8e165c5f9a364582b7",
"url": "https://files.pythonhosted.org/packages/48/ce/13508a1ec3f8bb981ae4ca79ea40384becc868bfae97fd1c942bb3a001b1/email_validator-2.2.0.tar.gz"
}
],
"project_name": "email-validator",
"requires_dists": [
"dnspython>=2.0.0",
"idna>=2.0.0"
],
"requires_python": ">=3.8",
"version": "2.2.0"
},
{
"artifacts": [
{
Expand Down Expand Up @@ -5155,7 +5216,7 @@
"prometheus-client~=0.21.1",
"psutil~=6.0",
"pycryptodome>=3.20.0",
"pydantic~=2.9.2",
"pydantic[email]~=2.9.2",
"pyhumps~=3.8.0",
"pyroscope-io~=0.8.8",
"pytest-aiohttp~=1.0.5",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ python-json-logger~=3.2.0
pyzmq~=26.2
PyJWT~=2.0
PyYAML~=6.0
pydantic~=2.9.2
pydantic[email]~=2.9.2
packaging>=24.1
hiredis>=3.0.0
redis[hiredis]==4.5.5
Expand Down
1 change: 1 addition & 0 deletions src/ai/backend/common/dto/manager/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python_sources(name="src")
34 changes: 34 additions & 0 deletions src/ai/backend/common/dto/manager/context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import uuid
from typing import Any, Mapping, Self

from aiohttp import web

from ai.backend.common.api_handlers import MiddlewareParam


class UserIdentityCtx(MiddlewareParam):
user_uuid: uuid.UUID
user_role: str
user_email: str
domain_name: str

@classmethod
def from_request(cls, request: web.Request) -> Self:
return cls(
user_uuid=request["user"]["uuid"],
user_role=request["user"]["role"],
user_email=request["user"]["email"],
domain_name=request["user"]["domain_name"],
)


class KeypairCtx(MiddlewareParam):
access_key: str
resource_policy: Mapping[str, Any]

@classmethod
def from_request(cls, request: web.Request) -> Self:
return cls(
access_key=request["keypair"]["access_key"],
resource_policy=request["keypair"]["resource_policy"],
)
54 changes: 54 additions & 0 deletions src/ai/backend/common/dto/manager/field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import enum
from typing import Optional

from pydantic import BaseModel

from ai.backend.common.types import VFolderUsageMode


class VFolderPermissionField(enum.StrEnum):
READ_ONLY = "ro"
READ_WRITE = "rw"
RW_DELETE = "wd"
OWNER_PERM = "wd"


class VFolderOperationStatusField(enum.StrEnum):
READY = "ready"
PERFORMING = "performing"
CLONING = "cloning"
MOUNTED = "mounted"
ERROR = "error"

DELETE_PENDING = "delete-pending"
DELETE_ONGOING = "delete-ongoing"
DELETE_COMPLETE = "delete-complete"
DELETE_ERROR = "delete-error"


class VFolderOwnershipTypeField(enum.StrEnum):
USER = "user"
GROUP = "group"


class VFolderItemField(BaseModel):
id: str
name: str
quota_scope_id: str
host: str
usage_mode: VFolderUsageMode
created_at: str
permission: VFolderPermissionField
max_size: int
creator: str
ownership_type: VFolderOwnershipTypeField
user: Optional[str]
group: Optional[str]
cloneable: bool
status: VFolderOperationStatusField
is_owner: bool
user_email: str
group_name: str
type: str # legacy
max_files: int
cur_size: int
7 changes: 7 additions & 0 deletions src/ai/backend/common/dto/manager/path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import uuid

from pydantic import AliasChoices, BaseModel, Field


class VFolderIDPath(BaseModel):
vfolder_id: uuid.UUID = Field(validation_alias=AliasChoices("vfolder_id", "vfolderId", "id"))
10 changes: 10 additions & 0 deletions src/ai/backend/common/dto/manager/query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import uuid
from typing import Optional

from pydantic import AliasChoices, BaseModel, Field


class ListGroupQuery(BaseModel):
group_id: Optional[uuid.UUID] = Field(
default=None, validation_alias=AliasChoices("group_id", "groupId")
)
37 changes: 37 additions & 0 deletions src/ai/backend/common/dto/manager/request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import uuid
from typing import Optional

from pydantic import AliasChoices, BaseModel, Field

from ai.backend.common import typed_validators as tv
from ai.backend.common.dto.manager.dto import VFolderPermissionDTO
from ai.backend.common.types import VFolderUsageMode


class VFolderCreateReq(BaseModel):
name: tv.VFolderName = Field(
description="Name of the vfolder",
)
folder_host: Optional[str] = Field(
validation_alias=AliasChoices("host", "folder_host"),
default=None,
)
usage_mode: VFolderUsageMode = Field(default=VFolderUsageMode.GENERAL)
permission: VFolderPermissionDTO = Field(default=VFolderPermissionDTO.READ_WRITE)
unmanaged_path: Optional[str] = Field(
validation_alias=AliasChoices("unmanaged_path", "unmanagedPath"),
default=None,
)
group_id: Optional[uuid.UUID] = Field(
validation_alias=AliasChoices("group", "groupId", "group_id"),
default=None,
)
cloneable: bool = Field(
default=False,
)


class RenameVFolderReq(BaseModel):
new_name: tv.VFolderName = Field(
description="Name of the vfolder",
)
12 changes: 12 additions & 0 deletions src/ai/backend/common/dto/manager/response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from pydantic import Field

from ai.backend.common.api_handlers import BaseResponseModel
from ai.backend.common.dto.manager.field import VFolderItemField


class VFolderCreateResponse(BaseResponseModel):
item: VFolderItemField


class VFolderListResponse(BaseResponseModel):
items: list[VFolderItemField] = Field(default_factory=list)
1 change: 1 addition & 0 deletions src/ai/backend/manager/api/vfolders/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python_sources(name="src")
Empty file.
Loading
Loading