-
Notifications
You must be signed in to change notification settings - Fork 499
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert UPS plugin to use pydantic models
- Loading branch information
Showing
3 changed files
with
75 additions
and
42 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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
from typing import Literal | ||
|
||
from pydantic import Field | ||
|
||
from middlewared.api.base import ( | ||
BaseModel, Excluded, excluded_field, ForUpdateMetaclass, NonEmptyString, LongString, | ||
single_argument_args, | ||
) | ||
|
||
|
||
__all__ = [ | ||
'UPSEntry', 'UPSPortChoicesArgs', 'UPSPortChoicesResult', 'UPSDriverChoicesArgs', | ||
'UPSDriverChoicesResult', 'UPSUpdateArgs', 'UPSUpdateResult', | ||
] | ||
|
||
|
||
class UPSEntry(BaseModel): | ||
powerdown: bool | ||
rmonitor: bool | ||
id: int | ||
nocommwarntime: int | None | ||
remoteport: int = Field(ge=1, le=65535) | ||
shutdowntimer: int | ||
hostsync: int = Field(ge=0) | ||
description: str | ||
driver: str | ||
extrausers: LongString | ||
identifier: NonEmptyString | ||
mode: Literal['MASTER', 'SLAVE'] | ||
monpwd: str | ||
monuser: NonEmptyString | ||
options: LongString | ||
optionsupsd: LongString | ||
port: str | ||
remotehost: str | ||
shutdown: Literal['LOWBATT', 'BATT'] | ||
shutdowncmd: str | None | ||
complete_identifier: str | ||
|
||
|
||
@single_argument_args('ups_update') | ||
class UPSUpdateArgs(UPSEntry, metaclass=ForUpdateMetaclass): | ||
id: Excluded = excluded_field() | ||
complete_identifier: Excluded = excluded_field() | ||
monpwd: NonEmptyString | ||
|
||
|
||
class UPSUpdateResult(BaseModel): | ||
result: UPSEntry | ||
|
||
|
||
class UPSPortChoicesArgs(BaseModel): | ||
pass | ||
|
||
|
||
class UPSPortChoicesResult(BaseModel): | ||
result: list[str] | ||
|
||
|
||
class UPSDriverChoicesArgs(BaseModel): | ||
pass | ||
|
||
|
||
class UPSDriverChoicesResult(BaseModel): | ||
result: dict[str, 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