-
Notifications
You must be signed in to change notification settings - Fork 491
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NAS-132068 / 25.04 / Convert cloud_backup to new api style (#15024)
* convert to new api * add defaults
- Loading branch information
1 parent
7d85d22
commit ec6e6b2
Showing
8 changed files
with
216 additions
and
78 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
174 changes: 174 additions & 0 deletions
174
src/middlewared/middlewared/api/v25_04_0/cloud_backup.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,174 @@ | ||
from datetime import datetime | ||
from typing import Literal | ||
|
||
from pydantic import Field, PositiveInt, Secret | ||
|
||
from middlewared.api.base import BaseModel, ForUpdateMetaclass, LongString, NonEmptyString | ||
from .cloud_sync import CloudCredentialEntry | ||
from .common import CronModel | ||
|
||
|
||
__all__ = [ | ||
"CloudBackupEntry", "CloudBackupTransferSettingChoicesArgs", "CloudBackupTransferSettingChoicesResult", | ||
"CloudBackupCreateArgs", "CloudBackupCreateResult", "CloudBackupUpdateArgs", "CloudBackupUpdateResult", | ||
"CloudBackupDeleteArgs", "CloudBackupDeleteResult", "CloudBackupRestoreArgs", "CloudBackupRestoreResult", | ||
"CloudBackupListSnapshotsArgs", "CloudBackupListSnapshotsResult", "CloudBackupListSnapshotDirectoryArgs", | ||
"CloudBackupListSnapshotDirectoryResult", "CloudBackupDeleteSnapshotArgs", "CloudBackupDeleteSnapshotResult", | ||
"CloudBackupSyncArgs", "CloudBackupSyncResult", "CloudBackupAbortArgs", "CloudBackupAbortResult", | ||
] | ||
|
||
|
||
class CloudBackupCron(CronModel): | ||
minute: str = "00" | ||
|
||
|
||
class CloudBackupCreate(BaseModel): | ||
description: str = "" | ||
path: str | ||
credentials: int | ||
attributes: dict | ||
schedule: CloudBackupCron | ||
pre_script: LongString = "" | ||
post_script: LongString = "" | ||
snapshot: bool = False | ||
include: list[NonEmptyString] | ||
exclude: list[NonEmptyString] | ||
args: LongString = "" | ||
enabled: bool = True | ||
|
||
password: Secret[NonEmptyString] | ||
keep_last: PositiveInt | ||
transfer_setting: Literal["DEFAULT", "PERFORMANCE", "FAST_STORAGE"] = "DEFAULT" | ||
|
||
|
||
class CloudBackupEntry(CloudBackupCreate): | ||
id: int | ||
credentials: CloudCredentialEntry | ||
job: dict | None | ||
locked: bool | ||
|
||
|
||
class CloudBackupUpdate(CloudBackupCreate, metaclass=ForUpdateMetaclass): | ||
pass | ||
|
||
|
||
class CloudBackupRestoreOptions(BaseModel): | ||
exclude: list[str] = [] | ||
include: list[str] = [] | ||
|
||
|
||
class CloudBackupSnapshot(BaseModel): | ||
id: str | ||
hostname: str | ||
time: datetime | ||
paths: list[str] | ||
|
||
class Config: | ||
extra = "allow" | ||
|
||
|
||
class CloudBackupSnapshotItem(BaseModel): | ||
name: str | ||
path: str | ||
type: Literal["dir", "file"] | ||
size: int | ||
mtime: datetime | ||
|
||
class Config: | ||
extra = "allow" | ||
|
||
|
||
class CloudBackupSyncOptions(BaseModel): | ||
dry_run: bool = False | ||
|
||
|
||
############### Args and Results ############### | ||
|
||
|
||
class CloudBackupTransferSettingChoicesArgs(BaseModel): | ||
pass | ||
|
||
|
||
class CloudBackupTransferSettingChoicesResult(BaseModel): | ||
result: list[Literal["DEFAULT", "PERFORMANCE", "FAST_STORAGE"]] | ||
|
||
|
||
class CloudBackupCreateArgs(BaseModel): | ||
cloud_backup: CloudBackupCreate | ||
|
||
|
||
class CloudBackupCreateResult(BaseModel): | ||
result: CloudBackupEntry | ||
|
||
|
||
class CloudBackupUpdateArgs(BaseModel): | ||
id_: int | ||
data: CloudBackupUpdate | ||
|
||
|
||
class CloudBackupUpdateResult(BaseModel): | ||
result: CloudBackupEntry | ||
|
||
|
||
class CloudBackupDeleteArgs(BaseModel): | ||
id_: int | ||
|
||
|
||
class CloudBackupDeleteResult(BaseModel): | ||
result: Literal[True] | ||
|
||
|
||
class CloudBackupRestoreArgs(BaseModel): | ||
id_: int | ||
snapshot_id: str = Field(pattern=r"^[^-]") | ||
subfolder: str | ||
destination_path: str | ||
options: CloudBackupRestoreOptions | ||
|
||
|
||
class CloudBackupRestoreResult(BaseModel): | ||
result: None | ||
|
||
|
||
class CloudBackupListSnapshotsArgs(BaseModel): | ||
id_: int | ||
|
||
|
||
class CloudBackupListSnapshotsResult(BaseModel): | ||
result: list[CloudBackupSnapshot] | ||
|
||
|
||
class CloudBackupListSnapshotDirectoryArgs(BaseModel): | ||
id_: int | ||
snapshot_id: str = Field(pattern=r"^[^-]") | ||
path: str = Field(pattern=r"^[^-]") | ||
|
||
|
||
class CloudBackupListSnapshotDirectoryResult(BaseModel): | ||
result: list[CloudBackupSnapshotItem] | ||
|
||
|
||
class CloudBackupDeleteSnapshotArgs(BaseModel): | ||
id_: int | ||
snapshot_id: str = Field(pattern=r"^[^-]") | ||
|
||
|
||
class CloudBackupDeleteSnapshotResult(BaseModel): | ||
result: None | ||
|
||
|
||
class CloudBackupSyncArgs(BaseModel): | ||
id_: int | ||
options: CloudBackupSyncOptions = Field(default_factory=CloudBackupSyncOptions) | ||
|
||
|
||
class CloudBackupSyncResult(BaseModel): | ||
result: None | ||
|
||
|
||
class CloudBackupAbortArgs(BaseModel): | ||
id_: int | ||
|
||
|
||
class CloudBackupAbortResult(BaseModel): | ||
result: bool |
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
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.