gitscope
https://dev.kronoz.win/r/marzneshin.git
app/models/node.py · v0.3.2
Source
1 a47eb4c Dawsh 2y ago from enum import Enum
2 a47eb4c Dawsh 2y ago
3 a47eb4c Dawsh 2y ago from pydantic import ConfigDict, BaseModel, Field
4 a47eb4c Dawsh 2y ago
5 a47eb4c Dawsh 2y ago
6 a47eb4c Dawsh 2y ago class NodeStatus(str, Enum):
7 12b255b Dawsh 2y ago healthy = "healthy"
8 12b255b Dawsh 2y ago unhealthy = "unhealthy"
9 a47eb4c Dawsh 2y ago disabled = "disabled"
10 a47eb4c Dawsh 2y ago
11 a47eb4c Dawsh 2y ago
12 f6a32ea Dawsh 2y ago class NodeConnectionBackend(str, Enum):
13 f6a32ea Dawsh 2y ago grpcio = "grpcio"
14 f6a32ea Dawsh 2y ago grpclib = "grpclib"
15 f6a32ea Dawsh 2y ago
16 f6a32ea Dawsh 2y ago
17 a47eb4c Dawsh 2y ago class NodeSettings(BaseModel):
18 a47eb4c Dawsh 2y ago min_node_version: str = "v0.2.0"
19 a47eb4c Dawsh 2y ago certificate: str
20 a47eb4c Dawsh 2y ago
21 a47eb4c Dawsh 2y ago
22 db68a58 Dawsh 2y ago class Node(BaseModel):
23 db68a58 Dawsh 2y ago id: int | None = Field(None)
24 a47eb4c Dawsh 2y ago name: str
25 a47eb4c Dawsh 2y ago address: str
26 49457ba Dawsh 2y ago port: int = 53042
27 01cdf2e Dawsh 2y ago connection_backend: NodeConnectionBackend = Field(
28 01cdf2e Dawsh 2y ago default=NodeConnectionBackend.grpclib
29 01cdf2e Dawsh 2y ago )
30 12b255b Dawsh 2y ago usage_coefficient: float = Field(ge=0, default=1.0)
31 a47eb4c Dawsh 2y ago model_config = ConfigDict(from_attributes=True)
32 a47eb4c Dawsh 2y ago
33 12b255b Dawsh 2y ago
34 a47eb4c Dawsh 2y ago class NodeCreate(Node):
35 01cdf2e Dawsh 2y ago model_config = ConfigDict(
36 01cdf2e Dawsh 2y ago json_schema_extra={
37 01cdf2e Dawsh 2y ago "example": {
38 01cdf2e Dawsh 2y ago "name": "DE node",
39 01cdf2e Dawsh 2y ago "address": "192.168.1.1",
40 db68a58 Dawsh 2y ago "port": 53042,
41 01cdf2e Dawsh 2y ago "usage_coefficient": 1,
42 01cdf2e Dawsh 2y ago }
43 a47eb4c Dawsh 2y ago }
44 01cdf2e Dawsh 2y ago )
45 a47eb4c Dawsh 2y ago
46 a47eb4c Dawsh 2y ago
47 a47eb4c Dawsh 2y ago class NodeModify(Node):
48 db68a58 Dawsh 2y ago name: str | None = Field(None)
49 db68a58 Dawsh 2y ago address: str | None = Field(None)
50 db68a58 Dawsh 2y ago port: int | None = Field(None)
51 db68a58 Dawsh 2y ago connection_backend: NodeConnectionBackend | None = Field(None)
52 db68a58 Dawsh 2y ago status: NodeStatus | None = Field(None)
53 db68a58 Dawsh 2y ago usage_coefficient: float | None = Field(None, ge=0)
54 01cdf2e Dawsh 2y ago model_config = ConfigDict(
55 01cdf2e Dawsh 2y ago json_schema_extra={
56 01cdf2e Dawsh 2y ago "example": {
57 01cdf2e Dawsh 2y ago "name": "DE node",
58 01cdf2e Dawsh 2y ago "address": "192.168.1.1",
59 db68a58 Dawsh 2y ago "port": 53042,
60 01cdf2e Dawsh 2y ago "status": "disabled",
61 01cdf2e Dawsh 2y ago "usage_coefficient": 1.0,
62 01cdf2e Dawsh 2y ago }
63 a47eb4c Dawsh 2y ago }
64 01cdf2e Dawsh 2y ago )
65 a47eb4c Dawsh 2y ago
66 a47eb4c Dawsh 2y ago
67 a47eb4c Dawsh 2y ago class NodeResponse(Node):
68 db68a58 Dawsh 2y ago xray_version: str | None = None
69 a47eb4c Dawsh 2y ago status: NodeStatus
70 db68a58 Dawsh 2y ago message: str | None = None
71 a47eb4c Dawsh 2y ago model_config = ConfigDict(from_attributes=True)
72 db68a58 Dawsh 2y ago inbound_ids: list[int] | None = None
73 a47eb4c Dawsh 2y ago
74 a47eb4c Dawsh 2y ago
75 a47eb4c Dawsh 2y ago class NodeUsageResponse(BaseModel):
76 db68a58 Dawsh 2y ago node_id: int | None = None
77 a47eb4c Dawsh 2y ago node_name: str
78 a47eb4c Dawsh 2y ago uplink: int
79 a47eb4c Dawsh 2y ago downlink: int
80 a47eb4c Dawsh 2y ago
81 a47eb4c Dawsh 2y ago
82 a47eb4c Dawsh 2y ago class NodesUsageResponse(BaseModel):
83 db68a58 Dawsh 2y ago usages: list[NodeUsageResponse]