-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-133124 / 25.04 / Convert iscsi.target.* to new api (#15223)
* Convert iscsi.target.* to new api * Correct network specification in tests
- Loading branch information
1 parent
e7ffb75
commit 5d1a781
Showing
5 changed files
with
153 additions
and
46 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
100 changes: 100 additions & 0 deletions
100
src/middlewared/middlewared/api/v25_04_0/iscsi_target.py
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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import re | ||
from typing import Literal | ||
|
||
from pydantic import AfterValidator, StringConstraints | ||
from typing_extensions import Annotated | ||
|
||
from middlewared.api.base import (BaseModel, Excluded, ForUpdateMetaclass, IscsiAuthType, NonEmptyString, | ||
excluded_field, match_validator) | ||
|
||
RE_TARGET_NAME = re.compile(r'^[-a-z0-9\.:]+$') | ||
|
||
__all__ = [ | ||
"IscsiTargetEntry", | ||
"IscsiTargetValidateNameArgs", | ||
"IscsiTargetValidateNameResult", | ||
"IscsiTargetCreateArgs", | ||
"IscsiTargetCreateResult", | ||
"IscsiTargetUpdateArgs", | ||
"IscsiTargetUpdateResult", | ||
"IscsiTargetDeleteArgs", | ||
"IscsiTargetDeleteResult", | ||
"IscsiTargetRemoveArgs", | ||
"IscsiTargetRemoveResult" | ||
] | ||
|
||
|
||
class IscsiGroup(BaseModel): | ||
portal: int | ||
initiator: int | None = None | ||
authmethod: IscsiAuthType = 'NONE' | ||
auth: int | None = None | ||
|
||
|
||
class IscsiTargetEntry(BaseModel): | ||
id: int | ||
name: Annotated[NonEmptyString, | ||
AfterValidator( | ||
match_validator( | ||
RE_TARGET_NAME, | ||
"Name can only contain lowercase alphanumeric charactersplus dot (.), dash (-), and colon (:)", | ||
) | ||
), | ||
StringConstraints(max_length=120)] | ||
alias: str | None = None | ||
mode: Literal['ISCSI', 'FC', 'BOTH'] = 'ISCSI' | ||
groups: list[IscsiGroup] = [] | ||
auth_networks: list[str] = [] # IPvAnyNetwork: "Object of type IPv4Network is not JSON serializable", etc | ||
rel_tgt_id: int | ||
|
||
|
||
class IscsiTargetValidateNameArgs(BaseModel): | ||
name: str | ||
existing_id: int | None = None | ||
|
||
|
||
class IscsiTargetValidateNameResult(BaseModel): | ||
result: str | None | ||
|
||
|
||
class IscsiTargetCreate(IscsiTargetEntry): | ||
id: Excluded = excluded_field() | ||
rel_tgt_id: Excluded = excluded_field() | ||
|
||
|
||
class IscsiTargetCreateArgs(BaseModel): | ||
iscsi_target_create: IscsiTargetCreate | ||
|
||
|
||
class IscsiTargetCreateResult(BaseModel): | ||
result: IscsiTargetEntry | ||
|
||
|
||
class IscsiTargetUpdate(IscsiTargetCreate, metaclass=ForUpdateMetaclass): | ||
pass | ||
|
||
|
||
class IscsiTargetUpdateArgs(BaseModel): | ||
id: int | ||
iscsi_target_update: IscsiTargetUpdate | ||
|
||
|
||
class IscsiTargetUpdateResult(BaseModel): | ||
result: IscsiTargetEntry | ||
|
||
|
||
class IscsiTargetDeleteArgs(BaseModel): | ||
id: int | ||
force: bool = False | ||
|
||
|
||
class IscsiTargetDeleteResult(BaseModel): | ||
result: Literal[True] | ||
|
||
|
||
class IscsiTargetRemoveArgs(BaseModel): | ||
name: str | ||
|
||
|
||
class IscsiTargetRemoveResult(BaseModel): | ||
result: None |
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
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
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