mcsmapi 0.1.7__py3-none-any.whl → 0.1.8b2__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.
mcsmapi/apis/instance.py CHANGED
@@ -1,4 +1,4 @@
1
- from typing import Any
1
+ from typing import Any, Literal
2
2
  from mcsmapi.pool import ApiPool
3
3
  from mcsmapi.request import send
4
4
  from mcsmapi.models.instance import (
@@ -6,6 +6,7 @@ from mcsmapi.models.instance import (
6
6
  InstanceDetail,
7
7
  InstanceCreateResult,
8
8
  InstanceConfig,
9
+ batchOperationDetail,
9
10
  )
10
11
 
11
12
 
@@ -16,22 +17,20 @@ class Instance:
16
17
  page: int = 1,
17
18
  page_size: int = 20,
18
19
  instance_name: str = "",
19
- status: str = "",
20
+ status: Literal[-1, 0, 1, 2, 3, ""] = "",
20
21
  tag: list[str] | None = None,
21
22
  ) -> InstanceSearchList:
22
23
  """
23
24
  根据指定的参数搜索实例信息
24
25
 
25
- **参数:**
26
- - daemonId (str): 守护进程的唯一标识符
27
- - page (int): 页码,用于指示返回数据的页数。默认为1,表示返回第一页数据
28
- - page_size (int): 每页大小,用于指定每页包含的数据条数。默认为20,表示每页包含20条数据
29
- - instance_name (str): 实例的名称。默认为空字符串,表示不进行实例名称过滤
30
- - status (str): 实例的状态。默认为空字符串,表示不进行状态过滤
31
- - tag (list[str] | None): 实例的标签列表。默认为None,表示不进行标签过滤
26
+ :params daemonId: 节点的UUID
27
+ :params page: 页码,用于指示返回数据的页数
28
+ :params page_size: 每页大小,用于指定每页包含的数据条数
29
+ :params instance_name: 用于过滤的实例名称
30
+ :params status: 用于过滤的实例状态
31
+ :params tag: 用于过滤的实例标签列表
32
32
 
33
- **返回:**
34
- - InstanceSearchList: 包含搜索结果的模型。该模型包含了符合搜索条件的实例信息列表,以及总数据条数、总页数等分页信息。
33
+ :returns: 包含搜索结果的模型
35
34
  """
36
35
  if tag is None:
37
36
  tag = []
@@ -54,75 +53,67 @@ class Instance:
54
53
  """
55
54
  获取指定实例的详细信息
56
55
 
57
- **参数:**
58
- - daemonId (str): 守护进程的唯一标识符
59
- - uuid (str): 实例的唯一标识符
56
+ :params daemonId: 节点的UUID
57
+ :params uuid: 实例的UUID
60
58
 
61
- **返回:**
62
- - InstanceDetail: 包含实例详细信息的模型。
59
+ :returns: 包含实例详细信息的模型
63
60
  """
64
61
  result = send(
65
62
  "GET",
66
63
  ApiPool.INSTANCE,
67
64
  params={"uuid": uuid, "daemonId": daemonId},
68
65
  )
69
- return InstanceDetail(**result)
66
+ return InstanceDetail(**result, daemonId=daemonId)
70
67
 
71
68
  @staticmethod
72
69
  def create(daemonId: str, config: dict[str, Any]) -> InstanceCreateResult:
73
70
  """
74
- 创建一个实例。
71
+ 创建一个实例
75
72
 
76
- **参数:**
77
- - daemonId (str): 守护进程的唯一标识符,用于关联新创建的实例。
78
- - config (dict[str, Any]): 实例的配置信息,以字典形式提供,缺失内容由InstanceConfig模型补全。
73
+ :params daemonId: 节点的UUID,用于关联新创建的实例
74
+ :params config: 实例的配置信息,以字典形式提供,缺失内容由InstanceConfig模型补全
79
75
 
80
- **返回:**
81
- - InstanceCreateResult: 一个包含新创建实例信息的结果对象,内容由InstanceCreateResult模型定义。
76
+ :returns: 一个包含新创建实例信息的结果对象,内容由InstanceCreateResult模型定义
82
77
  """
83
78
  result = send(
84
79
  "POST",
85
80
  ApiPool.INSTANCE,
86
81
  params={"daemonId": daemonId},
87
- data=InstanceConfig(**config).dict(),
82
+ data=InstanceConfig(**config).model_dump(),
88
83
  )
89
84
  return InstanceCreateResult(**result)
90
85
 
91
86
  @staticmethod
92
- def updateConfig(daemonId: str, uuid: str, config: dict) -> str | bool:
87
+ def updateConfig(daemonId: str, uuid: str, config: dict[str, Any]) -> str:
93
88
  """
94
- 更新实例配置。
89
+ 更新实例配置
95
90
 
96
- **不建议直接使用此函数,建议调用search后在data属性内使用updateConfig方法按需更新**
91
+ **不建议直接使用此函数,建议调用search后使用实例对象的updateConfig方法按需更新**
97
92
 
98
- **参数:**
99
- - daemonId (str): 守护进程的标识符。
100
- - uuid (str): 实例的唯一标识符。
101
- - config (dict): 新的实例配置,以字典形式提供,缺失内容由InstanceConfig模型补全。
93
+ :params daemonId: 节点的标识符
94
+ :params uuid: 实例的UUID
95
+ :params config: 新的实例配置,以字典形式提供,缺失内容由InstanceConfig模型补全
102
96
 
103
- **返回:**
104
- - str|bool: 更新成功后返回更新的实例UUID,如果未找到该字段,则默认返回True。
97
+ :returns: 被更新配置的实例UUID
105
98
  """
106
99
  result = send(
107
100
  "PUT",
108
101
  ApiPool.INSTANCE,
109
102
  params={"uuid": uuid, "daemonId": daemonId},
110
- data=InstanceConfig(**config).dict(),
103
+ data=InstanceConfig(**config).model_dump(),
111
104
  )
112
- return result.get("uuid", True)
105
+ return result["instanceUuid"]
113
106
 
114
107
  @staticmethod
115
108
  def delete(daemonId: str, uuids: list[str], deleteFile: bool = False) -> list[str]:
116
109
  """
117
- 删除实例。
110
+ 删除实例
118
111
 
119
- **参数:**
120
- - daemonId (str): 守护进程的标识符。
121
- - uuids (list): 要删除的实例UUID列表。
122
- - deleteFile (bool, optional): 是否删除关联的文件,默认为False。
112
+ :params daemonId: 节点的UUID
113
+ :params uuids: 要删除的实例UUID列表
114
+ :params deleteFile: 是否删除关联的文件
123
115
 
124
- **返回:**
125
- - list[str]: 删除操作后返回的UUID列表。
116
+ :returns: 被删除的实例UUID列表
126
117
  """
127
118
  return send(
128
119
  "DELETE",
@@ -132,109 +123,97 @@ class Instance:
132
123
  )
133
124
 
134
125
  @staticmethod
135
- def start(daemonId: str, uuid: str) -> str | bool:
126
+ def start(daemonId: str, uuid: str) -> str:
136
127
  """
137
- 启动实例。
128
+ 启动实例
138
129
 
139
- **参数:**
140
- - daemonId (str): 守护进程的ID,用于标识特定的守护进程。
141
- - uuid (str): 实例的唯一标识符,用于指定需要启动的实例。
130
+ :params daemonId: 节点的UUID
131
+ :params uuid: 实例的UUID
142
132
 
143
- **返回:**
144
- - str|bool: 返回结果中的 "instanceUuid" 字段值,如果未找到该字段,则默认返回True。
133
+ :returns: 被启动的实例的UUID
145
134
  """
146
135
  result = send(
147
136
  "GET",
148
137
  f"{ApiPool.PROTECTED_INSTANCE}/open",
149
138
  params={"daemonId": daemonId, "uuid": uuid},
150
139
  )
151
- return result.get("instanceUuid", True)
140
+ return result["instanceUuid"]
152
141
 
153
142
  @staticmethod
154
- def stop(daemonId: str, uuid: str) -> str | bool:
143
+ def stop(daemonId: str, uuid: str) -> str:
155
144
  """
156
- 关闭实例。
145
+ 关闭实例
157
146
 
158
- **参数:**
159
- - daemonId (str): 守护进程的ID,用于标识特定的守护进程。
160
- - uuid (str): 实例的唯一标识符,用于指定需要关闭的实例。
147
+ :params daemonId: 节点的UUID
148
+ :params uuid: 实例的UUID
161
149
 
162
- **返回:**
163
- - str|bool: 返回结果中的 "instanceUuid" 字段值,如果未找到该字段,则默认返回True。
150
+ :returns: 被关闭的实例的UUID
164
151
  """
165
152
  result = send(
166
153
  "GET",
167
154
  f"{ApiPool.PROTECTED_INSTANCE}/stop",
168
155
  params={"daemonId": daemonId, "uuid": uuid},
169
156
  )
170
- return result.get("instanceUuid", True)
157
+ return result["instanceUuid"]
171
158
 
172
159
  @staticmethod
173
- def restart(daemonId: str, uuid: str) -> str | bool:
160
+ def restart(daemonId: str, uuid: str) -> str:
174
161
  """
175
- 重启实例。
162
+ 重启实例
176
163
 
177
- **参数:**
178
- - daemonId (str): 守护进程的ID,用于标识特定的守护进程。
179
- - uuid (str): 实例的唯一标识符,用于指定需要重启的实例。
164
+ :params daemonId: 节点的UUID
165
+ :params uuid: 实例的UUID
180
166
 
181
- **返回:**
182
- - str|bool: 返回结果中的 "instanceUuid" 字段值,如果未找到该字段,则默认返回True。
167
+ :returns: 被重启的实例的UUID
183
168
  """
184
169
  result = send(
185
170
  "GET",
186
171
  f"{ApiPool.PROTECTED_INSTANCE}/restart",
187
172
  params={"daemonId": daemonId, "uuid": uuid},
188
173
  )
189
- return result.get("instanceUuid", True)
174
+ return result["instanceUuid"]
190
175
 
191
176
  @staticmethod
192
- def kill(daemonId: str, uuid: str) -> str | bool:
177
+ def kill(daemonId: str, uuid: str) -> str:
193
178
  """
194
- 强制关闭实例。
179
+ 强制关闭实例
195
180
 
196
- **参数:**
197
- - daemonId (str): 守护进程的ID,用于标识特定的守护进程。
198
- - uuid (str): 实例的唯一标识符,用于指定需要强制关闭的实例。
181
+ :params daemonId: 节点的UUID
182
+ :params uuid: 实例的UUID
199
183
 
200
- **返回:**
201
- - str|bool: 返回结果中的 "instanceUuid" 字段值,如果未找到该字段,则默认返回True。
184
+ :returns: 被强制关闭的实例的UUID
202
185
  """
203
186
  result = send(
204
187
  "GET",
205
188
  f"{ApiPool.PROTECTED_INSTANCE}/kill",
206
189
  params={"daemonId": daemonId, "uuid": uuid},
207
190
  )
208
- return result.get("instanceUuid", True)
191
+ return result["instanceUuid"]
209
192
 
210
193
  @staticmethod
211
- def batchOperation(instances: list[dict[str, str]], operation: str) -> bool:
194
+ def batchOperation(
195
+ instances: list[batchOperationDetail],
196
+ operation: Literal["start", "stop", "restart", "kill"],
197
+ ) -> bool:
212
198
  """
213
- 对多个实例进行批量操作。
199
+ 对多个实例进行批量操作
214
200
 
215
- **参数:**
216
- - instances (list[dict[str,str]]): 包含多个实例信息的列表,每个实例信息为一个字典,包含 "uuid" 和 "daemonId" 字段。
217
- - operation (str): 要执行的操作,可以是 "start", "stop", "restart", 或 "kill"。
201
+ :params instances: 包含多个实例信息的列表
202
+ :params operation: 要执行的操作
218
203
 
219
- **返回:**
220
- - list[dict[str,str]]:包含每个实例操作结果的列表,每个结果为一个字典,包含 "uuid" 和 "result" 字段。
204
+ :returns: 操作成功返回True
221
205
  """
222
- if operation in {"start", "stop", "restart", "kill"}:
223
- return send("POST", f"{ApiPool.INSTANCE}/multi_{operation}", data=instances)
224
- else:
225
- raise ValueError("operation must be one of start, stop, restart, kill")
206
+ return send("POST", f"{ApiPool.INSTANCE}/multi_{operation}", data=instances)
226
207
 
227
208
  @staticmethod
228
209
  def update(daemonId: str, uuid: str) -> bool:
229
210
  """
230
- 升级实例。
211
+ 更新实例
231
212
 
232
- **参数:**
233
- - daemonId (str): 守护进程的ID,用于标识特定的守护进程。
234
- - uuid (str): 实例的唯一标识符,用于指定需要升级的实例。
213
+ :params daemonId: 节点的UUID
214
+ :params uuid: 实例的UUID
235
215
 
236
- **返回:**
237
- - bool: 返回操作结果,成功时返回True。
216
+ :returns: 操作成功返回True
238
217
  """
239
218
  return send(
240
219
  "POST",
@@ -245,35 +224,29 @@ class Instance:
245
224
  @staticmethod
246
225
  def command(daemonId: str, uuid: str, command: str) -> str:
247
226
  """
248
- 向实例发送命令。
227
+ 向实例发送命令
249
228
 
250
- **参数:**
251
- - daemonId (str): 守护进程的ID,用于标识特定的守护进程。
252
- - uuid (str): 实例的唯一标识符,用于指定需要发送命令的实例。
253
- - command (str): 要发送的命令。
229
+ :params daemonId: 节点的UUID
230
+ :params uuid: 实例的UUID
231
+ :params command: 要发送的命令
254
232
 
255
- **返回:**
256
- - str|bool: 返回结果中的 "instanceUuid" 字段值,如果未找到该字段,则默认返回True。
233
+ :returns: 被操作的实例的UUID
257
234
  """
258
235
  result = send(
259
236
  "GET",
260
237
  f"{ApiPool.PROTECTED_INSTANCE}/command",
261
238
  params={"daemonId": daemonId, "uuid": uuid, "command": command},
262
239
  )
263
- return result.get("instanceUuid", True)
240
+ return result["instanceUuid"]
264
241
 
265
242
  @staticmethod
266
- def get_output(daemonId: str, uuid: str, size: int | str = "") -> str:
243
+ def get_output(daemonId: str, uuid: str, size: int | None = None) -> str:
267
244
  """
268
- 获取实例输出。
269
-
270
- **参数:**
271
- - daemonId (str): 守护进程的ID,用于标识特定的守护进程。
272
- - uuid (str): 实例的唯一标识符,用于指定需要获取输出的实例。
273
- - size (int, optional): 获取的日志大小: 1KB ~ 2048KB,如果未设置,则返回所有日志
245
+ 获取实例输出
274
246
 
275
- **返回:**
276
- - str: 返回结果中的 "instanceUuid" 字段值,如果未找到该字段,则默认返回True。
247
+ :params daemonId: 节点的UUID
248
+ :params uuid: 实例的UUID
249
+ :params size: 获取的输出大小: 1KB ~ 2048KB,如果未设置,则返回所有日志
277
250
  """
278
251
  return send(
279
252
  "GET",
@@ -290,17 +263,15 @@ class Instance:
290
263
  description: str = "",
291
264
  ) -> bool:
292
265
  """
293
- 重装实例。
266
+ 重装实例
294
267
 
295
- **参数:**
296
- - daemonId (str): 守护进程的ID,用于标识特定的守护进程。
297
- - uuid (str): 实例的唯一标识符。
298
- - targetUrl (str): 重装文件的目标URL。
299
- - title (str): 重装文件的标题。
300
- - description (str, optional): 重装文件的描述,默认为空字符串。
268
+ :params daemonId: 节点的UUID
269
+ :params uuid: 实例的UUID
270
+ :params targetUrl: 重装文件的目标URL
271
+ :params title: 重装文件的标题
272
+ :params description: 重装文件的描述
301
273
 
302
- **返回:**
303
- - bool: 返回操作结果,成功时返回True。
274
+ :returns: 操作成功返回True
304
275
  """
305
276
  return send(
306
277
  "POST",
mcsmapi/apis/overview.py CHANGED
@@ -11,7 +11,7 @@ class Overview:
11
11
  """
12
12
  result = send("GET", ApiPool.OVERVIEW)
13
13
  return OverviewModel(**result)
14
-
14
+
15
15
  @staticmethod
16
16
  def logs():
17
17
  """
mcsmapi/apis/user.py CHANGED
@@ -1,25 +1,26 @@
1
- from typing import Any
1
+ from typing import Any, Literal
2
2
  from mcsmapi.pool import ApiPool
3
3
  from mcsmapi.request import send
4
- from mcsmapi.models.user import SearchUserModel, UserConfig
4
+ from mcsmapi.models.user import SearchUserModel, UserConfig, UserCreateResult
5
5
 
6
6
 
7
7
  class User:
8
8
  @staticmethod
9
9
  def search(
10
- username: str = "", page: int = 1, page_size: int = 20, role: str = ""
10
+ username: str = "",
11
+ page: int = 1,
12
+ page_size: int = 20,
13
+ role: Literal[-1, 1, 10, ""] = "",
11
14
  ) -> SearchUserModel:
12
- """根据用户名和角色搜索用户信息
15
+ """
16
+ 根据用户名和角色搜索用户信息
13
17
 
14
- **参数:**
15
- - username (str): 要搜索的用户名。默认为空字符串,表示不进行用户名过滤
16
- - page (int): 页码,用于指示返回数据的页数。默认为1,表示返回第一页数据
17
- - page_size (int): 每页大小,用于指定每页包含的数据条数。默认为20,表示每页包含20条数据
18
- - role (str): 用户权限。默认为空字符串,表示不进行权限过滤
19
- 可用的值为 1=用户, 10=管理员, -1=被封禁的用户
18
+ :params uername: 要搜索的用户名,为空则列出全部用户
19
+ :params page: 页码,用于指示返回数据的第几页
20
+ :params page_size: 每页数据条数
21
+ :params role: 用于过滤的用户权限
20
22
 
21
- **返回:**
22
- - SearchUserModel: 包含搜索结果的模型。该模型包含了符合搜索条件的用户信息列表,以及总数据条数、总页数等分页信息。
23
+ :returns: 包含搜索结果的模型
23
24
  """
24
25
  result = send(
25
26
  "GET",
@@ -34,37 +35,34 @@ class User:
34
35
  return SearchUserModel(**result)
35
36
 
36
37
  @staticmethod
37
- def create(username: str, password: str, permission: int = 1) -> str | bool:
38
+ def create(username: str, password: str, permission: int = 1) -> UserCreateResult:
38
39
  """
39
- 创建新用户的方法
40
+ 创建新用户
40
41
 
41
- **参数:**
42
- - username (str): 用户名,字符串类型
43
- - password (str): 密码,字符串类型
44
- - permission (int): 权限等级,整数类型,默认值为1
42
+ :params username: 用户名
43
+ :params password: 密码
44
+ :params permission: 权限等级
45
45
 
46
- **返回:**
47
- - str|bool: 创建成功后返回用户的UUID,如果未找到该字段,则默认返回True。
46
+ :returns: 包含创建结果的模型
48
47
  """
49
- return send(
48
+ result = send(
50
49
  "POST",
51
50
  ApiPool.AUTH,
52
51
  data={"username": username, "password": password, "permission": permission},
53
- ).get("uuid", True)
52
+ )
53
+ return UserCreateResult(**result)
54
54
 
55
55
  @staticmethod
56
56
  def update(uuid: str, config: dict[str, Any]) -> bool:
57
57
  """
58
- 更新用户信息的方法
58
+ 更新用户信息
59
59
 
60
- **不建议直接使用此函数,建议调用search后使用update方法按需更新**
60
+ **不建议直接使用此函数,建议调用search后使用用户对象的update方法按需更新**
61
61
 
62
- **参数:**
63
- - uuid (str): 用户的唯一标识符UUID
64
- - config (dict[str, Any]): 新的用户信息,以字典形式提供,缺失内容由UserConfig模型补全。
62
+ :params uuid: 用户的UUID
63
+ :params config: 新的用户信息,以字典形式提供,缺失内容由 UserConfig 模型提供默认值
65
64
 
66
- **返回:**
67
- - bool: 成功时返回True
65
+ :returns: 成功时返回True
68
66
  """
69
67
  return send(
70
68
  "PUT",
@@ -75,12 +73,10 @@ class User:
75
73
  @staticmethod
76
74
  def delete(uuids: list[str]) -> bool:
77
75
  """
78
- 删除用户的方法
76
+ 删除用户
79
77
 
80
- **参数:**
81
- - uuids (list[str]): 包含要删除的用户UUID的列表。
78
+ :params uuids: 包含要删除的用户UUID的列表
82
79
 
83
- **返回:**
84
- - bool: 成功时返回True
80
+ :returns: 成功时返回True
85
81
  """
86
82
  return send("DELETE", ApiPool.AUTH, data=uuids)
mcsmapi/models/common.py CHANGED
@@ -2,7 +2,7 @@ from pydantic import BaseModel
2
2
 
3
3
 
4
4
  class CpuMemChart(BaseModel):
5
- """节点资源使用率信息"""
5
+ """资源使用率信息"""
6
6
 
7
7
  cpu: float
8
8
  """cpu使用率"""
@@ -11,17 +11,17 @@ class CpuMemChart(BaseModel):
11
11
 
12
12
 
13
13
  class ProcessInfo(BaseModel):
14
- """节点进程详细信息"""
14
+ """进程详细信息"""
15
15
 
16
16
  cpu: int
17
- """远程节点使用的cpu资源(单位: byte)"""
17
+ """CPU 使用率(百分比)"""
18
18
  memory: int
19
- """远程节点使用的内存资源(单位: byte)"""
19
+ """内存使用量(MB)"""
20
20
  cwd: str
21
- """远程节点的工作路径"""
21
+ """工作路径"""
22
22
 
23
23
 
24
- class InstanceInfo(BaseModel):
24
+ class InstanceStat(BaseModel):
25
25
  """实例统计信息"""
26
26
 
27
27
  running: int