mcsmapi 0.1.6__py3-none-any.whl → 0.1.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,148 +1,166 @@
1
- from typing import List, Dict, Optional
1
+ from enum import IntEnum
2
2
  from pydantic import BaseModel
3
3
  from mcsmapi.models.file import FileList
4
4
  from mcsmapi.models.image import DockerConfig
5
5
 
6
6
 
7
+ class CRLFType(IntEnum):
8
+ """换行符"""
9
+
10
+ LF = 0
11
+ CR = 1
12
+ CRLF = 2
13
+
14
+
15
+ class Status(IntEnum):
16
+ """实例状态"""
17
+
18
+ BUSY = -1
19
+ STOP = 0
20
+ STOPPING = 1
21
+ STARTING = 2
22
+ RUNNING = 3
23
+
24
+
7
25
  class TerminalOption(BaseModel):
8
26
  """终端选项"""
9
27
 
10
- """是否启用颜色输出"""
11
28
  haveColor: bool = False
12
- """是否使用伪终端 (PTY)"""
29
+ """是否启用颜色输出"""
13
30
  pty: bool = True
31
+ """是否使用伪终端 (PTY)"""
14
32
 
15
33
 
16
34
  class EventTask(BaseModel):
17
35
  """事件任务"""
18
36
 
19
- """是否自动启动"""
20
37
  autoStart: bool = False
21
- """是否自动重启"""
38
+ """是否自动启动"""
22
39
  autoRestart: bool = True
23
- """是否忽略该任务"""
40
+ """是否自动重启"""
24
41
  ignore: bool = False
42
+ """是否忽略该任务"""
25
43
 
26
44
 
27
45
  class PingConfig(BaseModel):
28
- """服务器 Ping 配置"""
46
+ """服务器 Ping 配置(新版已弃用)"""
29
47
 
30
- """服务器 IP 地址"""
31
48
  ip: str = ""
32
- """服务器端口"""
49
+ """服务器 IP 地址"""
33
50
  port: int = 25565
34
- """Ping 类型 (1: 默认类型)"""
51
+ """服务器端口"""
35
52
  type: int = 1
53
+ """Ping 类型 (1: 默认类型)"""
36
54
 
37
55
 
38
56
  class InstanceConfig(BaseModel):
39
57
  """实例配置信息"""
40
58
 
41
- """实例名称"""
42
59
  nickname: str = "New Name"
43
- """启动命令"""
60
+ """实例名称"""
44
61
  startCommand: str = "cmd.exe"
45
- """停止命令"""
62
+ """启动命令"""
46
63
  stopCommand: str = "^C"
47
- """工作目录"""
64
+ """停止命令"""
48
65
  cwd: str = ""
66
+ """工作目录"""
67
+ ie: str = "utf8"
49
68
  """输入编码"""
50
- ie: str = "gbk"
69
+ oe: str = "utf8"
51
70
  """输出编码"""
52
- oe: str = "gbk"
53
- """创建时间 (Unix 时间戳)"""
54
71
  createDatetime: int = 0
55
- """最后修改时间 (Unix 时间戳)"""
72
+ """创建时间 (Unix 时间戳)"""
56
73
  lastDatetime: int = 0
57
- """实例类型 (universal, minecraft 等)"""
74
+ """最后修改时间 (Unix 时间戳)"""
58
75
  type: str = "universal"
76
+ """实例类型 (universal, minecraft 等)"""
77
+ tag: list[str] = []
59
78
  """实例标签"""
60
- tag: List[str] = []
61
- """实例结束时间 (可选)"""
62
- endTime: Optional[int] = None
79
+ endTime: int | None = None
80
+ """实例到期时间"""
81
+ fileCode: str = "utf8"
63
82
  """文件编码"""
64
- fileCode: str = "gbk"
65
- """进程类型 (如 docker, local)"""
66
83
  processType: str = "docker"
67
- """更新命令"""
84
+ """进程类型 (如 docker, local)"""
68
85
  updateCommand: str = "shutdown -s"
86
+ """更新命令"""
87
+ actionCommandList: list[str] = []
69
88
  """实例可执行的操作命令列表"""
70
- actionCommandList: List[str] = []
71
- """换行符 (0: LF, 1: CR, 2: CRLF)"""
72
- crlf: int = 2
73
- """Docker 相关配置"""
89
+ crlf: CRLFType = CRLFType.CRLF
90
+ """换行符"""
74
91
  docker: "DockerConfig" = DockerConfig()
75
- """是否启用 RCON 远程控制"""
92
+ """Docker 相关配置"""
76
93
  enableRcon: bool = True
77
- """RCON 连接密码"""
94
+ """是否启用 RCON 远程控制"""
78
95
  rconPassword: str = ""
79
- """RCON 端口"""
96
+ """RCON 连接密码"""
80
97
  rconPort: int = 2557
81
- """RCON IP 地址"""
98
+ """RCON 端口"""
82
99
  rconIp: str = ""
83
- """终端选项配置"""
100
+ """RCON IP 地址"""
84
101
  terminalOption: TerminalOption = TerminalOption()
85
- """事件任务配置"""
102
+ """终端选项配置"""
86
103
  eventTask: EventTask = EventTask()
87
- """服务器 Ping 监测配置"""
104
+ """事件任务配置"""
88
105
  pingConfig: PingConfig = PingConfig()
106
+ """服务器 Ping 监测配置"""
107
+ runAs: str = ""
108
+ """运行该实例的系统用户,为空则使用启动面板的系统用户"""
89
109
 
90
110
 
91
111
  class ProcessInfo(BaseModel):
92
112
  """进程信息"""
93
113
 
114
+ cpu: int
94
115
  """CPU 使用率 (单位: %)"""
95
- cpu: int = 0
116
+ memory: int
96
117
  """进程占用内存 (单位: KB)"""
97
- memory: int = 0
118
+ ppid: int
98
119
  """父进程 ID"""
99
- ppid: int = 0
120
+ pid: int
100
121
  """进程 ID"""
101
- pid: int = 0
122
+ ctime: int
102
123
  """进程创建时间 (Unix 时间戳)"""
103
- ctime: int = 0
124
+ elapsed: int
104
125
  """进程运行时长 (单位: 秒)"""
105
- elapsed: int = 0
126
+ timestamp: int
106
127
  """时间戳"""
107
- timestamp: int = 0
108
128
 
109
129
 
110
130
  class InstanceInfo(BaseModel):
111
- """实例运行状态信息( 这些选项在新版中已不再支持设置,但仍在API中返回)"""
131
+ """实例运行状态信息(这些选项在新版中已不再支持设置,但仍在API中返回)"""
112
132
 
113
- """当前玩家数量 (-1 表示未知)"""
114
- currentPlayers: int = -1
115
- """文件锁状态 (0: 无锁)"""
133
+ currentPlayers: int
134
+ """当前玩家数量"""
116
135
  fileLock: int = 0
117
- """最大允许玩家数 (-1 表示未知)"""
136
+ """文件锁状态 (0: 无锁)"""
118
137
  maxPlayers: int = -1
119
- """是否启用 FRP 远程服务"""
138
+ """最大允许玩家数 (-1 表示未知)"""
120
139
  openFrpStatus: bool = False
140
+ """是否启用 FRP 远程服务"""
141
+ playersChart: list[dict] = []
121
142
  """玩家数量变化图表数据"""
122
- playersChart: List[Dict] = []
123
- """服务器版本"""
124
143
  version: str = ""
144
+ """服务器版本"""
125
145
 
126
146
 
127
147
  class InstanceDetail(BaseModel):
128
148
  """实例详细信息"""
129
149
 
150
+ config: InstanceConfig
130
151
  """实例的配置信息"""
131
- config: InstanceConfig = InstanceConfig()
152
+ info: InstanceInfo
132
153
  """实例的运行状态信息"""
133
- info: InstanceInfo = InstanceInfo()
154
+ daemonId: str
134
155
  """所属的守护进程 (Daemon) ID"""
135
- daemonId: str = ""
156
+ instanceUuid: str
136
157
  """实例唯一标识符 (UUID)"""
137
- instanceUuid: str = ""
158
+ processInfo: ProcessInfo
138
159
  """实例的进程信息"""
139
- processInfo: ProcessInfo = ProcessInfo()
140
- """实例的存储空间大小(始终为`0`)"""
141
- space: int = 0 # 在 MCSM 代码中,此项始终为 0,意义不明
160
+ started: int
142
161
  """实例的启动次数"""
143
- started: int = 0
144
- """实例状态 (-1: 忙碌, 0: 停止, 1: 停止中, 2: 启动中, 3: 运行中)"""
145
- status: int = 0
162
+ status: Status
163
+ """实例状态"""
146
164
 
147
165
  def start(self) -> str | bool:
148
166
  """
@@ -153,7 +171,7 @@ class InstanceDetail(BaseModel):
153
171
  """
154
172
  from mcsmapi.apis.instance import Instance
155
173
 
156
- return Instance().start(self.daemonId, self.instanceUuid)
174
+ return Instance.start(self.daemonId, self.instanceUuid)
157
175
 
158
176
  def stop(self) -> str | bool:
159
177
  """
@@ -164,7 +182,7 @@ class InstanceDetail(BaseModel):
164
182
  """
165
183
  from mcsmapi.apis.instance import Instance
166
184
 
167
- return Instance().stop(self.daemonId, self.instanceUuid)
185
+ return Instance.stop(self.daemonId, self.instanceUuid)
168
186
 
169
187
  def restart(self) -> str | bool:
170
188
  """
@@ -175,7 +193,7 @@ class InstanceDetail(BaseModel):
175
193
  """
176
194
  from mcsmapi.apis.instance import Instance
177
195
 
178
- return Instance().restart(self.daemonId, self.instanceUuid)
196
+ return Instance.restart(self.daemonId, self.instanceUuid)
179
197
 
180
198
  def kill(self) -> str | bool:
181
199
  """
@@ -186,7 +204,7 @@ class InstanceDetail(BaseModel):
186
204
  """
187
205
  from mcsmapi.apis.instance import Instance
188
206
 
189
- return Instance().kill(self.daemonId, self.instanceUuid)
207
+ return Instance.kill(self.daemonId, self.instanceUuid)
190
208
 
191
209
  def delete(self, deleteFile=False) -> str:
192
210
  """
@@ -197,7 +215,7 @@ class InstanceDetail(BaseModel):
197
215
  """
198
216
  from mcsmapi.apis.instance import Instance
199
217
 
200
- return Instance().delete(self.daemonId, [self.instanceUuid], deleteFile)[0]
218
+ return Instance.delete(self.daemonId, [self.instanceUuid], deleteFile)[0]
201
219
 
202
220
  def update(self) -> bool:
203
221
  """
@@ -208,7 +226,7 @@ class InstanceDetail(BaseModel):
208
226
  """
209
227
  from mcsmapi.apis.instance import Instance
210
228
 
211
- return Instance().update(self.daemonId, self.instanceUuid)
229
+ return Instance.update(self.daemonId, self.instanceUuid)
212
230
 
213
231
  def updateConfig(self, config: dict) -> str | bool:
214
232
  """
@@ -222,14 +240,12 @@ class InstanceDetail(BaseModel):
222
240
  """
223
241
  from mcsmapi.apis.instance import Instance
224
242
 
225
- updated_config = self.config.dict()
243
+ updated_config = self.config.model_dump()
226
244
  updated_config.update(config)
227
245
 
228
- instance_config = InstanceConfig(**updated_config).dict()
246
+ instance_config = InstanceConfig(**updated_config).model_dump()
229
247
 
230
- return Instance().updateConfig(
231
- self.daemonId, self.instanceUuid, instance_config
232
- )
248
+ return Instance.updateConfig(self.daemonId, self.instanceUuid, instance_config)
233
249
 
234
250
  def reinstall(self, targetUrl: str, title: str = "", description: str = "") -> bool:
235
251
  """
@@ -245,7 +261,7 @@ class InstanceDetail(BaseModel):
245
261
  """
246
262
  from mcsmapi.apis.instance import Instance
247
263
 
248
- return Instance().reinstall(
264
+ return Instance.reinstall(
249
265
  self.daemonId, self.instanceUuid, targetUrl, title, description
250
266
  )
251
267
 
@@ -263,29 +279,29 @@ class InstanceDetail(BaseModel):
263
279
  """
264
280
  from mcsmapi.apis.file import File
265
281
 
266
- return File().show(self.daemonId, self.instanceUuid, target, page, page_size)
282
+ return File.show(self.daemonId, self.instanceUuid, target, page, page_size)
267
283
 
268
284
 
269
285
  class InstanceCreateResult(BaseModel):
270
286
  """实例创建结果"""
271
287
 
272
- """实例唯一标识符 (UUID)"""
273
288
  instanceUuid: str = ""
274
- """实例的配置信息"""
289
+ """实例唯一标识符 (UUID)"""
275
290
  config: InstanceConfig = InstanceConfig()
291
+ """实例的配置信息"""
276
292
 
277
293
 
278
294
  class InstanceSearchList(BaseModel):
279
295
  """实例搜索列表"""
280
296
 
281
- """每页的实例数量"""
282
297
  pageSize: int = 0
283
- """最大页数"""
298
+ """每页的实例数量"""
284
299
  maxPage: int = 0
300
+ """最大页数"""
301
+ data: list[InstanceDetail] = []
285
302
  """实例详细信息列表"""
286
- data: List[InstanceDetail] = []
287
- """所属的守护进程 (Daemon) ID"""
288
303
  daemonId: str = ""
304
+ """所属的守护进程 (Daemon) ID"""
289
305
 
290
306
  def __init__(self, **data: str):
291
307
  """实例化对象,并在每个实例中填充 daemonId"""
@@ -297,7 +313,7 @@ class InstanceSearchList(BaseModel):
297
313
  class UserInstancesList(BaseModel):
298
314
  """用户实例列表"""
299
315
 
300
- """实例唯一标识符 (UUID)"""
301
316
  instanceUuid: str = ""
302
- """所属的守护进程 (Daemon) ID"""
317
+ """实例唯一标识符 (UUID)"""
303
318
  daemonId: str = ""
319
+ """所属的守护进程 (Daemon) ID"""
@@ -1,112 +1,170 @@
1
- from typing import Dict, List, Optional
1
+ from enum import Enum
2
+ from typing import Literal
2
3
  from pydantic import BaseModel
4
+ from mcsmapi.models.common import CpuMemChart, InstanceInfo, ProcessInfo
3
5
  from mcsmapi.models.daemon import DaemonModel
4
6
 
5
7
 
6
8
  class SystemUser(BaseModel):
7
9
  """系统用户信息"""
8
10
 
9
- """用户 ID (UID)"""
10
11
  uid: int = 0
11
- """用户组 ID (GID)"""
12
+ """用户 ID (UID)"""
12
13
  gid: int = 0
13
- """用户名"""
14
+ """用户组 ID (GID)"""
14
15
  username: str = ""
15
- """用户主目录"""
16
+ """用户名"""
16
17
  homedir: str = ""
17
- """默认 Shell 解释器 (可选)"""
18
- shell: Optional[str] = None
18
+ """用户主目录"""
19
+ shell: str | None = None
20
+ """默认 Shell 解释器"""
19
21
 
20
22
 
21
23
  class SystemInfo(BaseModel):
22
24
  """系统信息"""
23
25
 
24
- """当前登录用户信息"""
25
26
  user: SystemUser = SystemUser()
26
- """系统当前时间 (Unix 时间戳)"""
27
+ """当前登录用户信息"""
27
28
  time: int = 0
28
- """系统总内存大小 (单位: 字节)"""
29
+ """系统当前时间 (Unix 时间戳)"""
29
30
  totalmem: int = 0
30
- """系统空闲内存大小 (单位: 字节)"""
31
+ """系统总内存大小 (单位: 字节)"""
31
32
  freemem: int = 0
32
- """操作系统类型"""
33
+ """系统空闲内存大小 (单位: 字节)"""
33
34
  type: str = ""
34
- """操作系统版本"""
35
+ """操作系统类型"""
35
36
  version: str = ""
36
- """系统节点名称"""
37
+ """操作系统版本"""
37
38
  node: str = ""
38
- """主机名"""
39
+ """系统节点名称"""
39
40
  hostname: str = ""
41
+ """主机名"""
42
+ loadavg: list[float] = []
40
43
  """系统负载平均值 (过去 1、5、15 分钟)"""
41
- loadavg: List[float] = []
42
- """操作系统平台"""
43
44
  platform: str = ""
44
- """系统发行版本信息"""
45
+ """操作系统平台"""
45
46
  release: str = ""
46
- """系统运行时间 (单位: 秒)"""
47
+ """系统发行版本信息"""
47
48
  uptime: float = 0
48
- """CPU 当前使用率 (单位: %)"""
49
+ """系统运行时间 (单位: )"""
49
50
  cpu: float = 0
51
+ """CPU 当前使用率 (单位: %)"""
50
52
 
51
53
 
52
54
  class RecordInfo(BaseModel):
53
55
  """安全记录信息"""
54
56
 
55
- """成功登录次数"""
56
57
  logined: int = 0
57
- """非法访问次数"""
58
+ """成功登录次数"""
58
59
  illegalAccess: int = 0
59
- """被封禁的 IP 数量"""
60
+ """非法访问次数"""
60
61
  banips: int = 0
61
- """登录失败次数"""
62
+ """被封禁的 IP 数量"""
62
63
  loginFailed: int = 0
64
+ """登录失败次数"""
63
65
 
64
66
 
65
67
  class ChartInfo(BaseModel):
66
68
  """图表数据信息"""
67
69
 
68
- """系统性能数据 (CPU/内存等)"""
69
- system: List[Dict[str, float]] = []
70
- """请求统计信息 (HTTP 请求数等)"""
71
- request: List[Dict[str, int]] = []
72
-
73
-
74
- class ProcessInfo(BaseModel):
75
- """进程信息"""
76
-
77
- """CPU 使用率 (单位: %)"""
78
- cpu: int = 0
79
- """进程占用内存 (单位: KB)"""
80
- memory: int = 0
81
- """进程当前工作目录"""
82
- cwd: str = ""
70
+ system: list[CpuMemChart]
71
+ """系统统计信息"""
72
+ request: list[InstanceInfo]
73
+ """实例统计信息"""
83
74
 
84
75
 
85
76
  class RemoteCountInfo(BaseModel):
86
77
  """远程守护进程统计信息"""
87
78
 
79
+ total: int
88
80
  """远程守护进程总数"""
89
- total: int = 0
81
+ available: int
90
82
  """可用的远程守护进程数量"""
91
- available: int = 0
92
83
 
93
84
 
94
85
  class OverviewModel(BaseModel):
95
86
  """系统概览信息"""
96
87
 
88
+ version: str
97
89
  """系统当前版本"""
98
- version: str = ""
90
+ specifiedDaemonVersion: str
99
91
  """指定的守护进程 (Daemon) 版本"""
100
- specifiedDaemonVersion: str = ""
92
+ system: SystemInfo
101
93
  """系统信息"""
102
- system: SystemInfo = SystemInfo()
94
+ record: RecordInfo
103
95
  """安全访问记录"""
104
- record: RecordInfo = RecordInfo()
96
+ process: ProcessInfo
105
97
  """进程状态信息"""
106
- process: ProcessInfo = ProcessInfo()
98
+ chart: ChartInfo
107
99
  """系统与请求统计图表数据"""
108
- chart: ChartInfo = ChartInfo()
100
+ remoteCount: RemoteCountInfo
109
101
  """远程守护进程统计信息"""
110
- remoteCount: RemoteCountInfo = RemoteCountInfo()
102
+ remote: list[DaemonModel]
111
103
  """远程守护进程详细信息"""
112
- remote: List["DaemonModel"] = []
104
+
105
+
106
+ class LogType(Enum):
107
+ """操作类型"""
108
+
109
+ # 系统相关
110
+ SYSTEM_CONFIG_CHANGE = "system_config_change"
111
+
112
+ # 用户相关
113
+ USER_LOGIN = "user_login"
114
+ USER_CONFIG_CHANGE = "user_config_change"
115
+ USER_DELETE = "user_delete"
116
+ USER_CREATE = "user_create"
117
+
118
+ # 守护进程相关
119
+ DAEMON_CONFIG_CHANGE = "daemon_config_change"
120
+ DAEMON_REMOVE = "daemon_remove"
121
+ DAEMON_CREATE = "daemon_create"
122
+
123
+ # 实例任务相关
124
+ INSTANCE_TASK_DELETE = "instance_task_delete"
125
+ INSTANCE_TASK_CREATE = "instance_task_create"
126
+
127
+ # 实例文件相关
128
+ INSTANCE_FILE_DELETE = "instance_file_delete"
129
+ INSTANCE_FILE_DOWNLOAD = "instance_file_download"
130
+ INSTANCE_FILE_UPDATE = "instance_file_update"
131
+ INSTANCE_FILE_UPLOAD = "instance_file_upload"
132
+
133
+ # 实例操作相关
134
+ INSTANCE_DELETE = "instance_delete"
135
+ INSTANCE_CREATE = "instance_create"
136
+ INSTANCE_CONFIG_CHANGE = "instance_config_change"
137
+ INSTANCE_KILL = "instance_kill"
138
+ INSTANCE_UPDATE = "instance_update"
139
+ INSTANCE_RESTART = "instance_restart"
140
+ INSTANCE_STOP = "instance_stop"
141
+ INSTANCE_START = "instance_start"
142
+
143
+
144
+ class LogDetail(BaseModel):
145
+ """操作日志详情"""
146
+
147
+ operation_id: str
148
+ """操作者uuid"""
149
+ operator_name: str | None = None
150
+ """操作者用户名"""
151
+ operation_time: str
152
+ """操作时间戳"""
153
+ operator_ip: str
154
+ """操作者ip"""
155
+ operation_level: Literal["info", "warning", "error", "unknown"]
156
+ """日志等级"""
157
+ type: LogType
158
+ """操作类型"""
159
+ instance_name: str | None = None
160
+ """实例名称(仅实例事件存在)"""
161
+ instance_id: str | None = None
162
+ """实例ID(仅实例事件存在)"""
163
+ daemon_id: str | None = None
164
+ """守护进程ID(仅实例事件和守护进程事件存在)"""
165
+ login_result: bool | None = None
166
+ """登录结果(仅登录事件存在)"""
167
+ file: str | None = None
168
+ """文件名(仅文件操作事件存在)"""
169
+ task_name: str | None = None
170
+ """任务名称(仅任务操作事件存在)"""