-
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-132813 / 25.04 / Convert
pool.snapshottask
to new API (#15164)
* convert to new api * validators must return to be used in new api * Revert "validators must return to be used in new api" This reverts commit c49f50d. * address @themylogin and small refactor * don't use old Time validator * fix import
- Loading branch information
1 parent
1a4ae07
commit 8af0dc7
Showing
12 changed files
with
189 additions
and
87 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
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,5 +1,5 @@ | ||
from .base import * # noqa | ||
from .fc import * # noqa | ||
from .filesystem import * # noqa | ||
from .iscsi import * # noqa | ||
from .string import * # noqa | ||
from .user import * # noqa | ||
from .filesystem import * # noqa |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from datetime import time | ||
import re | ||
|
||
|
||
def match_validator(pattern: re.Pattern, explanation: str | None = None): | ||
def validator(value: str): | ||
assert (value is None or pattern.match(value)), (explanation or f"Value does not match {pattern!r} pattern") | ||
return value | ||
|
||
return validator | ||
|
||
|
||
def time_validator(value: str): | ||
try: | ||
hours, minutes = value.split(':') | ||
except ValueError: | ||
raise ValueError('Time should be in 24 hour format like "18:00"') | ||
else: | ||
try: | ||
time(int(hours), int(minutes)) | ||
except TypeError: | ||
raise ValueError('Time should be in 24 hour format like "18:00"') | ||
return value |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
120 changes: 120 additions & 0 deletions
120
src/middlewared/middlewared/api/v25_04_0/pool_snapshottask.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,120 @@ | ||
from typing import Any, Literal | ||
|
||
from pydantic import Field | ||
|
||
from middlewared.api.base import BaseModel, ForUpdateMetaclass, TimeString, SnapshotNameSchema | ||
from .common import CronModel | ||
|
||
|
||
__all__ = [ | ||
"PoolSnapshotTaskEntry", "PoolSnapshotTaskCreateArgs", "PoolSnapshotTaskCreateResult", | ||
"PoolSnapshotTaskUpdateArgs", "PoolSnapshotTaskUpdateResult", "PoolSnapshotTaskDeleteArgs", | ||
"PoolSnapshotTaskDeleteResult", "PoolSnapshotTaskMaxCountArgs", "PoolSnapshotTaskMaxCountResult", | ||
"PoolSnapshotTaskMaxTotalCountArgs", "PoolSnapshotTaskMaxTotalCountResult", "PoolSnapshotTaskRunArgs", | ||
"PoolSnapshotTaskRunResult", "PoolSnapshotTaskUpdateWillChangeRetentionForArgs", | ||
"PoolSnapshotTaskUpdateWillChangeRetentionForResult", "PoolSnapshotTaskDeleteWillChangeRetentionForArgs", | ||
"PoolSnapshotTaskDeleteWillChangeRetentionForResult" | ||
] | ||
|
||
|
||
class PoolSnapshotTaskCron(CronModel): | ||
minute: str = "00" | ||
begin: TimeString = "00:00" | ||
end: TimeString = "23:59" | ||
|
||
|
||
class PoolSnapshotTaskCreate(BaseModel): | ||
dataset: str | ||
recursive: bool = False | ||
lifetime_value: int = 2 | ||
lifetime_unit: Literal["HOUR", "DAY", "WEEK", "MONTH", "YEAR"] = "WEEK" | ||
enabled: bool = True | ||
exclude: list[str] = [] | ||
naming_schema: SnapshotNameSchema = "auto-%Y-%m-%d_%H-%M" | ||
allow_empty: bool = True | ||
schedule: PoolSnapshotTaskCron = Field(default_factory=PoolSnapshotTaskCron) | ||
|
||
|
||
class PoolSnapshotTaskUpdate(PoolSnapshotTaskCreate, metaclass=ForUpdateMetaclass): | ||
fixate_removal_date: bool | ||
|
||
|
||
class PoolSnapshotTaskUpdateWillChangeRetentionFor(PoolSnapshotTaskCreate, metaclass=ForUpdateMetaclass): | ||
pass | ||
|
||
|
||
class PoolSnapshotTaskDeleteOptions(BaseModel): | ||
fixate_removal_date: bool = False | ||
|
||
|
||
class PoolSnapshotTaskEntry(PoolSnapshotTaskCreate): | ||
id: int | ||
vmware_sync: bool | ||
state: Any | ||
|
||
|
||
class PoolSnapshotTaskCreateArgs(BaseModel): | ||
data: PoolSnapshotTaskCreate | ||
|
||
|
||
class PoolSnapshotTaskCreateResult(BaseModel): | ||
result: PoolSnapshotTaskEntry | ||
|
||
|
||
class PoolSnapshotTaskUpdateArgs(BaseModel): | ||
id: int | ||
data: PoolSnapshotTaskUpdate | ||
|
||
|
||
class PoolSnapshotTaskUpdateResult(BaseModel): | ||
result: PoolSnapshotTaskEntry | ||
|
||
|
||
class PoolSnapshotTaskDeleteArgs(BaseModel): | ||
id: int | ||
options: PoolSnapshotTaskDeleteOptions = Field(default_factory=PoolSnapshotTaskDeleteOptions) | ||
|
||
|
||
class PoolSnapshotTaskDeleteResult(BaseModel): | ||
result: Literal[True] | ||
|
||
|
||
class PoolSnapshotTaskMaxCountArgs(BaseModel): | ||
pass | ||
|
||
|
||
class PoolSnapshotTaskMaxCountResult(BaseModel): | ||
result: int | ||
|
||
|
||
class PoolSnapshotTaskMaxTotalCountArgs(BaseModel): | ||
pass | ||
|
||
|
||
class PoolSnapshotTaskMaxTotalCountResult(BaseModel): | ||
result: int | ||
|
||
|
||
class PoolSnapshotTaskRunArgs(BaseModel): | ||
id: int | ||
|
||
|
||
class PoolSnapshotTaskRunResult(BaseModel): | ||
result: None | ||
|
||
|
||
class PoolSnapshotTaskUpdateWillChangeRetentionForArgs(BaseModel): | ||
id: int | ||
data: PoolSnapshotTaskUpdateWillChangeRetentionFor | ||
|
||
|
||
class PoolSnapshotTaskUpdateWillChangeRetentionForResult(BaseModel): | ||
result: dict[str, list[str]] | ||
|
||
|
||
class PoolSnapshotTaskDeleteWillChangeRetentionForArgs(BaseModel): | ||
id: int | ||
|
||
|
||
class PoolSnapshotTaskDeleteWillChangeRetentionForResult(BaseModel): | ||
result: dict[str, list[str]] |
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
2 changes: 0 additions & 2 deletions
2
src/middlewared/middlewared/plugins/snapshot_/removal_date.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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import hashlib | ||
|
||
from middlewared.service import Service, job, private | ||
|
||
|
||
|
Oops, something went wrong.