mcsmapi 0.1.1__tar.gz → 0.1.2__tar.gz

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.
Files changed (40) hide show
  1. mcsmapi-0.1.2/PKG-INFO +83 -0
  2. mcsmapi-0.1.2/README.md +70 -0
  3. mcsmapi-0.1.2/mcsmapi/__init__.py +54 -0
  4. mcsmapi-0.1.2/mcsmapi/apis/daemon.py +70 -0
  5. mcsmapi-0.1.2/mcsmapi/apis/file.py +318 -0
  6. mcsmapi-0.1.2/mcsmapi/apis/image.py +102 -0
  7. mcsmapi-0.1.2/mcsmapi/apis/instance.py +300 -0
  8. mcsmapi-0.1.2/mcsmapi/apis/overview.py +17 -0
  9. mcsmapi-0.1.2/mcsmapi/apis/user.py +82 -0
  10. mcsmapi-0.1.2/mcsmapi/exceptions.py +5 -0
  11. mcsmapi-0.1.2/mcsmapi/models/daemon.py +134 -0
  12. mcsmapi-0.1.2/mcsmapi/models/file.py +108 -0
  13. mcsmapi-0.1.2/mcsmapi/models/image.py +112 -0
  14. mcsmapi-0.1.2/mcsmapi/models/instance.py +204 -0
  15. mcsmapi-0.1.2/mcsmapi/models/overview.py +63 -0
  16. mcsmapi-0.1.2/mcsmapi/models/user.py +76 -0
  17. mcsmapi-0.1.2/mcsmapi/pool.py +14 -0
  18. mcsmapi-0.1.2/mcsmapi/request.py +91 -0
  19. mcsmapi-0.1.2/mcsmapi.egg-info/PKG-INFO +83 -0
  20. mcsmapi-0.1.2/mcsmapi.egg-info/SOURCES.txt +25 -0
  21. {mcsmapi-0.1.1 → mcsmapi-0.1.2}/mcsmapi.egg-info/requires.txt +1 -1
  22. mcsmapi-0.1.2/pyproject.toml +22 -0
  23. mcsmapi-0.1.2/test/test_overview_model.py +97 -0
  24. mcsmapi-0.1.1/PKG-INFO +0 -88
  25. mcsmapi-0.1.1/README.md +0 -74
  26. mcsmapi-0.1.1/mcsmapi/__init__.py +0 -8
  27. mcsmapi-0.1.1/mcsmapi/common.py +0 -34
  28. mcsmapi-0.1.1/mcsmapi/daemon.py +0 -86
  29. mcsmapi-0.1.1/mcsmapi/file.py +0 -326
  30. mcsmapi-0.1.1/mcsmapi/image.py +0 -104
  31. mcsmapi-0.1.1/mcsmapi/instance.py +0 -424
  32. mcsmapi-0.1.1/mcsmapi/overview.py +0 -35
  33. mcsmapi-0.1.1/mcsmapi/users.py +0 -83
  34. mcsmapi-0.1.1/mcsmapi.egg-info/PKG-INFO +0 -88
  35. mcsmapi-0.1.1/mcsmapi.egg-info/SOURCES.txt +0 -16
  36. mcsmapi-0.1.1/setup.py +0 -21
  37. {mcsmapi-0.1.1 → mcsmapi-0.1.2}/LICENSE +0 -0
  38. {mcsmapi-0.1.1 → mcsmapi-0.1.2}/mcsmapi.egg-info/dependency_links.txt +0 -0
  39. {mcsmapi-0.1.1 → mcsmapi-0.1.2}/mcsmapi.egg-info/top_level.txt +0 -0
  40. {mcsmapi-0.1.1 → mcsmapi-0.1.2}/setup.cfg +0 -0
mcsmapi-0.1.2/PKG-INFO ADDED
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 2.2
2
+ Name: mcsmapi
3
+ Version: 0.1.2
4
+ Summary: Shortcut the pypi package of MCSM./快捷操作MCSM的pypi包
5
+ Author-email: molanp <molanpp@outlook.com>
6
+ Project-URL: Source, https://github.com/molanp/mcsmapi
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: License :: OSI Approved :: MIT License
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: requests
12
+ Requires-Dist: pydantic
13
+
14
+ # MCSM API
15
+
16
+ ![Supported MCSManager Versions](https://img.shields.io/badge/Supported%20MCSManager%20Versions-10.x-blue)
17
+ ![Python Version](https://img.shields.io/badge/Python%20Version-%3E%3D3.7-blue)
18
+ ![PyPI Downloads](https://img.shields.io/pypi/dm/mcsmapi)
19
+
20
+ English|[Chinese Simplified](README_zh-cn.md)
21
+
22
+ > [!important]
23
+ > We need your help, the documentation for this project has not been written yet, if you are willing, please submit pr to help us write the documentation.
24
+
25
+ ## Introduction
26
+
27
+ `mcsmapi` is a PyPI package based on [MCSManager](https://github.com/MCSManager/MCSManager), designed to simplify interactions with the MCSM API.
28
+
29
+ With this library, you can more easily access and operate the various features provided by MCSM.
30
+
31
+ ## Installation
32
+
33
+ You can install `mcsmapi` using `pip`:
34
+
35
+ ```bash
36
+ pip install mcsmapi
37
+ ```
38
+
39
+ ## Supported Features
40
+
41
+ - [x] Dashboard data ([Overview](doc/en/Overview.md))
42
+ - [x] User management ([User](doc/en/User.md))
43
+ - [x] Instance management (`Instance`)
44
+ - [x] Daemon management (`Daemon`)
45
+ - [x] File management (`File`)
46
+ - [x] Image management (`Image`)
47
+
48
+ ## Supported MCSM Versions
49
+
50
+ | MCSM Version | Support Status |
51
+ | :---: | :---: |
52
+ | 10.x | ✅ |
53
+
54
+ ### Quick Example
55
+
56
+ ```python
57
+ from mcsmapi import MCSMAPI
58
+
59
+ # Initialize
60
+ mcsm = MCSMAPI("https://example.com")
61
+
62
+ # Log in with username and password (API permissions depend on the account permissions)
63
+ mcsm.login("username", "password")
64
+
65
+ # Log in with API key (API permissions depend on the API key permissions)
66
+ mcsm.login_with_apikey("apikey")
67
+
68
+ # Get dashboard data
69
+ overview = mcsm.overview()
70
+
71
+ # Get MCSM version
72
+ mcsm_version = mcsm.overview().version
73
+ ```
74
+
75
+ ## Contributing
76
+
77
+ If you encounter any issues or have suggestions for improvements, feel free to submit an [Issue](https://github.com/molanp/mcsmapi/issues) or create a [Pull Request](https://github.com/molanp/mcsmapi/pulls).
78
+
79
+ ## License
80
+
81
+ `mcsmapi` is licensed under the [MIT License](https://opensource.org/licenses/MIT).
82
+
83
+ Please refer to the [LICENSE](LICENSE) file for more details.
@@ -0,0 +1,70 @@
1
+ # MCSM API
2
+
3
+ ![Supported MCSManager Versions](https://img.shields.io/badge/Supported%20MCSManager%20Versions-10.x-blue)
4
+ ![Python Version](https://img.shields.io/badge/Python%20Version-%3E%3D3.7-blue)
5
+ ![PyPI Downloads](https://img.shields.io/pypi/dm/mcsmapi)
6
+
7
+ English|[Chinese Simplified](README_zh-cn.md)
8
+
9
+ > [!important]
10
+ > We need your help, the documentation for this project has not been written yet, if you are willing, please submit pr to help us write the documentation.
11
+
12
+ ## Introduction
13
+
14
+ `mcsmapi` is a PyPI package based on [MCSManager](https://github.com/MCSManager/MCSManager), designed to simplify interactions with the MCSM API.
15
+
16
+ With this library, you can more easily access and operate the various features provided by MCSM.
17
+
18
+ ## Installation
19
+
20
+ You can install `mcsmapi` using `pip`:
21
+
22
+ ```bash
23
+ pip install mcsmapi
24
+ ```
25
+
26
+ ## Supported Features
27
+
28
+ - [x] Dashboard data ([Overview](doc/en/Overview.md))
29
+ - [x] User management ([User](doc/en/User.md))
30
+ - [x] Instance management (`Instance`)
31
+ - [x] Daemon management (`Daemon`)
32
+ - [x] File management (`File`)
33
+ - [x] Image management (`Image`)
34
+
35
+ ## Supported MCSM Versions
36
+
37
+ | MCSM Version | Support Status |
38
+ | :---: | :---: |
39
+ | 10.x | ✅ |
40
+
41
+ ### Quick Example
42
+
43
+ ```python
44
+ from mcsmapi import MCSMAPI
45
+
46
+ # Initialize
47
+ mcsm = MCSMAPI("https://example.com")
48
+
49
+ # Log in with username and password (API permissions depend on the account permissions)
50
+ mcsm.login("username", "password")
51
+
52
+ # Log in with API key (API permissions depend on the API key permissions)
53
+ mcsm.login_with_apikey("apikey")
54
+
55
+ # Get dashboard data
56
+ overview = mcsm.overview()
57
+
58
+ # Get MCSM version
59
+ mcsm_version = mcsm.overview().version
60
+ ```
61
+
62
+ ## Contributing
63
+
64
+ If you encounter any issues or have suggestions for improvements, feel free to submit an [Issue](https://github.com/molanp/mcsmapi/issues) or create a [Pull Request](https://github.com/molanp/mcsmapi/pulls).
65
+
66
+ ## License
67
+
68
+ `mcsmapi` is licensed under the [MIT License](https://opensource.org/licenses/MIT).
69
+
70
+ Please refer to the [LICENSE](LICENSE) file for more details.
@@ -0,0 +1,54 @@
1
+ import urllib.parse
2
+ from .models.overview import OverviewModel
3
+ from .pool import ApiPool
4
+ from .apis.file import File
5
+ from .apis.user import User
6
+ from .apis.image import Image
7
+ from .apis.daemon import Daemon
8
+ from .apis.instance import Instance
9
+ from .apis.overview import Overview
10
+ from .request import Request, send
11
+
12
+
13
+ class MCSMAPI:
14
+ def __init__(self, url: str, timeout: int = 5) -> None:
15
+ split_url = urllib.parse.urlsplit(url)
16
+ Request.set_mcsm_url(
17
+ urllib.parse.urljoin(f"{split_url.scheme}://{split_url.netloc}", "")
18
+ )
19
+ self.authentication = None
20
+ Request.set_timeout(timeout)
21
+
22
+ def login(self, username: str, password: str) -> "MCSMAPI":
23
+ Request.set_token(
24
+ send(
25
+ "POST",
26
+ f"{ApiPool.AUTH}/login",
27
+ data={"username": username, "password": password},
28
+ )
29
+ )
30
+ self.authentication = "account"
31
+ return self
32
+
33
+ def login_with_apikey(self, apikey: str):
34
+ Request.set_apikey(apikey)
35
+ self.authentication = "apikey"
36
+ return self
37
+
38
+ def overview(self) -> OverviewModel:
39
+ return Overview().init()
40
+
41
+ def instance(self) -> Instance:
42
+ return Instance()
43
+
44
+ def user(self) -> User:
45
+ return User()
46
+
47
+ def daemon(self) -> Daemon:
48
+ return Daemon()
49
+
50
+ def file(self) -> File:
51
+ return File()
52
+
53
+ def image(self) -> Image:
54
+ return Image()
@@ -0,0 +1,70 @@
1
+ from typing import Any
2
+ from ..pool import ApiPool
3
+ from ..request import send
4
+ from ..models.daemon import DaemonConfig
5
+
6
+
7
+ class Daemon:
8
+ def add(self, config: dict[str, Any]) -> str:
9
+ """
10
+ 新增一个节点。
11
+
12
+ 参数:
13
+ - config (dict): 节点的配置信息,以字典形式提供,缺失内容由DaemonConfig模型补全。
14
+
15
+ 返回:
16
+ - str: 新增节点的ID
17
+ """
18
+ return send(
19
+ "POST",
20
+ f"{ApiPool.SERVICE}/remote_service",
21
+ data=DaemonConfig(**config).dict(),
22
+ )
23
+
24
+ def delete(self, daemonId: str) -> bool:
25
+ """
26
+ 删除一个节点。
27
+
28
+ 参数:
29
+ - daemonId (str): 节点的唯一标识符。
30
+
31
+ 返回:
32
+ - bool: 删除成功后返回True
33
+ """
34
+ return send(
35
+ "DELETE", f"{ApiPool.SERVICE}/remote_service", params={"uuid": daemonId}
36
+ )
37
+
38
+ def link(self, daemonId: str) -> bool:
39
+ """
40
+ 连接一个节点。
41
+
42
+ 参数:
43
+ - daemonId (str): 节点的唯一标识符。
44
+
45
+ 返回:
46
+ - bool: 连接成功后返回True
47
+ """
48
+ return send(
49
+ "GET", f"{ApiPool.SERVICE}/link_remote_service", params={"uuid": daemonId}
50
+ )
51
+
52
+ def update(self, daemonId: str, config: dict[str, Any]) -> bool:
53
+ """
54
+ 更新一个节点的配置。
55
+
56
+ **不建议直接使用此函数,建议调用overview()后在remote属性内使用updateConfig方法按需更新**
57
+
58
+ 参数:
59
+ - daemonId (str): 节点的唯一标识符。
60
+ - config (dict): 节点的配置信息,以字典形式提供,缺失内容由DaemonConfig模型补全。
61
+
62
+ 返回:
63
+ - bool: 更新成功后返回True
64
+ """
65
+ return send(
66
+ "PUT",
67
+ f"{ApiPool.SERVICE}/remote_service",
68
+ params={"uuid": daemonId},
69
+ data=DaemonConfig(**config).dict(),
70
+ )
@@ -0,0 +1,318 @@
1
+ from ..pool import ApiPool
2
+ from ..request import Request, send, upload
3
+ from ..models.file import CommonConfig, FileList
4
+ import urllib.parse
5
+ import os
6
+
7
+
8
+ class File:
9
+ def show(
10
+ self,
11
+ daemonId: str,
12
+ uuid: str,
13
+ target: str = "",
14
+ page: int = 0,
15
+ page_size: int = 100,
16
+ ) -> FileList:
17
+ """
18
+ 获取文件列表
19
+
20
+ **参数:**
21
+ - daemonId (str): 守护进程的唯一标识符。
22
+ - uuid (str): 文件实例的唯一标识符。
23
+ - target (str, 可选): 用于文件过滤的目标路径。默认为空字符串,表示不按路径过滤。
24
+ - page (int, 可选): 指定分页的页码。默认为0。
25
+ - page_size (int, 可选): 指定每页的项目数量。默认为100。
26
+
27
+ **返回:**
28
+ - FileList: 包含文件列表信息和分页详情的FileList模型。
29
+ """
30
+ result = send(
31
+ "GET",
32
+ f"{ApiPool.FILE}/list",
33
+ params={
34
+ "daemonId": daemonId,
35
+ "uuid": uuid,
36
+ "target": target,
37
+ "page": page,
38
+ "page_size": page_size,
39
+ },
40
+ )
41
+ return FileList(**result, daemonId=daemonId, uuid=uuid)
42
+
43
+ def content(self, daemonId: str, uuid: str, target: str) -> str | bytes:
44
+ """
45
+ 获取文件内容
46
+
47
+ **参数:**
48
+ - daemonId (str): 守护进程的唯一标识符。
49
+ - uuid (str): 文件实例的唯一标识符。
50
+ - target (str): 文件的目标路径。
51
+
52
+ **返回:**
53
+ - str: 文件的内容信息。
54
+ """
55
+ return send(
56
+ "PUT",
57
+ f"{ApiPool.FILE}",
58
+ params={"daemonId": daemonId, "uuid": uuid},
59
+ data={"target": target},
60
+ )
61
+
62
+ def update(self, daemonId: str, uuid: str, target: str, text: str) -> bool:
63
+ """
64
+ 更新文件内容
65
+
66
+ **参数:**
67
+ - daemonId (str): 守护进程的唯一标识符。
68
+ - uuid (str): 文件实例的唯一标识符。
69
+ - target (str): 文件的目标路径。
70
+ - text (str): 新的文件内容。
71
+
72
+ **返回:**
73
+ - bool: 更新成功后返回True。
74
+ """
75
+ return send(
76
+ "PUT",
77
+ f"{ApiPool.FILE}",
78
+ params={"daemonId": daemonId, "uuid": uuid},
79
+ data={"target": target, "text": text},
80
+ )
81
+
82
+ def download(self, daemonId: str, uuid: str, file_name: str) -> str:
83
+ """
84
+ 下载文件
85
+
86
+ **参数:**
87
+ - daemonId (str): 守护进程的唯一标识符。
88
+ - uuid (str): 文件实例的唯一标识符。
89
+ - file_name (str): 要下载的文件名。路径+名字, 示例: /backup/world.zip
90
+
91
+ **返回:**
92
+ - str: 文件下载URL。
93
+ """
94
+
95
+ result = send(
96
+ "POST",
97
+ f"{ApiPool.FILE}/download",
98
+ params={"daemonId": daemonId, "uuid": uuid, "file_name": file_name},
99
+ )
100
+ result = CommonConfig(**result)
101
+ protocol = Request.mcsm_url.split("://")[0]
102
+ base_url = urllib.parse.urljoin(f"{protocol}://{result.addr}", "download")
103
+ return urllib.parse.urljoin(base_url, f"{result.password}/{file_name}")
104
+
105
+ async def upload(
106
+ self, daemonId: str, uuid: str, file: bytes, upload_dir: str
107
+ ) -> bool:
108
+ """
109
+ 上传文件
110
+
111
+ **参数:**
112
+ - daemonId (str): 守护进程的唯一标识符。
113
+ - uuid (str): 文件实例的唯一标识符。
114
+ - file (bytes): 要上传的文件内容。
115
+ - upload_dir (str): 文件上传到的目标路径。
116
+
117
+ **返回:**
118
+ - bool: 上传成功后返回True。
119
+ """
120
+ result = send(
121
+ "POST",
122
+ f"{ApiPool.FILE}/upload",
123
+ params={"daemonId": daemonId, "uuid": uuid, "upload_dir": upload_dir},
124
+ )
125
+ result = CommonConfig(**result)
126
+ protocol = Request.mcsm_url.split("://")[0]
127
+ base_url = urllib.parse.urljoin(f"{protocol}://{result.addr}", "upload")
128
+ final_url = urllib.parse.urljoin(base_url, result.password)
129
+ await upload(final_url, file)
130
+ return True
131
+
132
+ def copy(self, daemonId: str, uuid: str, copy_map: dict[str, str]) -> bool:
133
+ """
134
+ 复制多个文件夹或文件到指定位置。
135
+
136
+ **参数:**
137
+ - daemonId (str): 守护进程的唯一标识符。
138
+ - uuid (str): 文件实例的唯一标识符。
139
+ - copy_map (dict): 复制映射,格式为 {源路径: 目标路径}
140
+
141
+ **返回:**
142
+ - bool: 上传成功后返回True。
143
+ """
144
+ targets = [[source, target] for source, target in copy_map.items()]
145
+ return send(
146
+ "POST",
147
+ f"{ApiPool.FILE}/copy",
148
+ params={"daemonId": daemonId, "uuid": uuid},
149
+ data={"targets": targets},
150
+ )
151
+
152
+ def copyOne(self, daemonId: str, uuid: str, source: str, target: str) -> bool:
153
+ """
154
+ 复制单个文件或文件夹到指定位置。
155
+
156
+ **参数:**
157
+ - daemonId (str): 守护进程的唯一标识符。
158
+ - uuid (str): 实例的唯一标识符。
159
+ - source (str): 源文件或文件夹的路径。
160
+ - target (str): 目标文件或文件夹的路径。
161
+
162
+ **返回:**
163
+ - bool: 移动成功后返回True。
164
+ """
165
+ return self.copy(daemonId, uuid, {source: target})
166
+
167
+ def move(self, daemonId: str, uuid: str, copy_map: dict[str, str]) -> bool:
168
+ """
169
+ 移动多个文件或文件夹到指定位置。
170
+
171
+ 参数:
172
+ - daemonId (str): 守护进程的唯一标识符。
173
+ - uuid (str): 实例的唯一标识符。
174
+ - copy_map (dict): 移动映射,格式为 {源路径: 目标路径}
175
+
176
+ 返回:
177
+ - bool: 移动成功后返回True。
178
+ """
179
+ targets = [[source, target] for source, target in copy_map.items()]
180
+ return send(
181
+ "PUT",
182
+ f"{ApiPool.FILE}/move",
183
+ params={"daemonId": daemonId, "uuid": uuid},
184
+ data={"targets": targets},
185
+ )
186
+
187
+ def moveOne(self, daemonId: str, uuid: str, source: str, target: str) -> bool:
188
+ """
189
+ 从源路径移动单个文件或文件夹到目标路径。
190
+
191
+ 参数:
192
+ - daemonId (str): 守护进程的唯一标识符。
193
+ - uuid (str): 实例的唯一标识符。
194
+ - source (str): 源文件或文件夹的路径。
195
+ - target (str): 目标文件或文件夹的路径。
196
+
197
+ 返回:
198
+ - bool: 移动成功后返回True。
199
+ """
200
+ return self.move(daemonId, uuid, {source: target})
201
+
202
+ def rename(self, daemonId: str, uuid: str, source: str, new_name: str) -> bool:
203
+ """
204
+ 重命名单个文件或文件夹。
205
+
206
+ **参数:**
207
+ - daemonId (str): 守护进程的唯一标识符。
208
+ - uuid (str): 实例的唯一标识符。
209
+ - source (str): 源文件或文件夹的路径。
210
+ - new_name (str): 源文件或文件夹的新名字。
211
+
212
+ **返回:**
213
+ - bool: 重命名成功后返回True。
214
+ """
215
+ directory = os.path.dirname(source)
216
+ target = os.path.join(directory, new_name)
217
+ return self.moveOne(daemonId, uuid, source, target)
218
+
219
+ def zip(self, daemonId: str, uuid: str, source: str, targets: list[str]) -> bool:
220
+ """
221
+ 压缩多个文件或文件夹到指定位置。
222
+
223
+ **参数:**
224
+ - daemonId (str): 守护进程的唯一标识符。
225
+ - uuid (str): 实例的唯一标识符。
226
+ - source (str): 需要压缩到的 zip 文件路径。
227
+ - targets (list): 要压缩的目标文件或文件夹的路径。
228
+
229
+ **返回:**
230
+ - bool: 压缩成功后返回True。
231
+ """
232
+ return send(
233
+ "POST",
234
+ f"{ApiPool.FILE}/compress",
235
+ params={"daemonId": daemonId, "uuid": uuid},
236
+ data={"type": 1, "code": "utf-8", "source": source, "targets": targets},
237
+ )
238
+
239
+ def unzip(
240
+ self, daemonId: str, uuid: str, source: str, target: str, code: str = "utf-8"
241
+ ) -> bool:
242
+ """
243
+ 解压缩指定的zip文件到目标位置。
244
+
245
+ **参数:**
246
+ - daemonId (str): 守护进程的唯一标识符。
247
+ - uuid (str): 实例的唯一标识符。
248
+ - source (str): 需要解压的zip文件路径。
249
+ - target (str): 解压到的目标路径。
250
+ - code (str, optional): 压缩文件的编码方式,默认为"utf-8"。
251
+ 可选值: utf-8, gbk, big5
252
+
253
+ **返回:**
254
+ - bool: 解压成功后返回True。
255
+ """
256
+ return send(
257
+ "POST",
258
+ f"{ApiPool.FILE}/compress",
259
+ params={"daemonId": daemonId, "uuid": uuid},
260
+ data={"type": 2, "code": code, "source": source, "targets": target},
261
+ )
262
+
263
+ def delete(self, daemonId: str, uuid: str, targets: list[str]) -> bool:
264
+ """
265
+ 删除多个文件或文件夹。
266
+
267
+ **参数:**
268
+ - daemonId (str): 守护进程的唯一标识符。
269
+ - uuid (str): 实例的唯一标识符。
270
+ - targets (list): 要删除的文件或文件夹的路径。
271
+
272
+ **返回:**
273
+ - bool: 删除成功后返回True。
274
+ """
275
+ return send(
276
+ "DELETE",
277
+ ApiPool.FILE,
278
+ params={"daemonId": daemonId, "uuid": uuid},
279
+ data={"targets": targets},
280
+ )
281
+
282
+ def createFile(self, daemonId: str, uuid: str, target: str) -> bool:
283
+ """
284
+ 创建文件。
285
+
286
+ **参数:**
287
+ - daemonId (str): 守护进程的唯一标识符。
288
+ - uuid (str): 实例的唯一标识符。
289
+ - target (str): 目标文件的路径,包含文件名。
290
+
291
+ **返回:**
292
+ - bool: 创建成功后返回True。
293
+ """
294
+ return send(
295
+ "POST",
296
+ f"{ApiPool.FILE}/touch",
297
+ params={"daemonId": daemonId, "uuid": uuid},
298
+ data={"target": target},
299
+ )
300
+
301
+ def createFloder(self, daemonId: str, uuid: str, target: str) -> bool:
302
+ """
303
+ 创建文件夹
304
+
305
+ **参数:**
306
+ - daemonId (str): 守护进程的唯一标识符。
307
+ - uuid (str): 实例的唯一标识符。
308
+ - target (str): 目标文件夹的路径。
309
+
310
+ **返回:**
311
+ - bool: 创建成功后返回True。
312
+ """
313
+ return send(
314
+ "POST",
315
+ f"{ApiPool.FILE}/mkdir",
316
+ params={"daemonId": daemonId, "uuid": uuid},
317
+ data={"target": target},
318
+ )
@@ -0,0 +1,102 @@
1
+ from ..pool import ApiPool
2
+ from ..request import send
3
+ from ..models.image import DockerImageItem, DockerContainerItem, DockerNetworkItem
4
+
5
+
6
+ class Image:
7
+ def images(self, daemonId: str) -> list[DockerImageItem]:
8
+ """
9
+ 获取镜像列表
10
+
11
+ **参数:**
12
+ - daemonId (str): 守护进程的唯一标识符。
13
+
14
+ **返回:**
15
+ - list[ImageModel]: 包含镜像列表详情的 ImageModel 模型的列表。
16
+ """
17
+ result = send(
18
+ "GET",
19
+ f"{ApiPool.IMAGE}/image",
20
+ params={
21
+ "daemonId": daemonId,
22
+ },
23
+ )
24
+
25
+ return [DockerImageItem(**item) for item in result]
26
+
27
+ def containers(self, daemonId: str) -> list[DockerContainerItem]:
28
+ """
29
+ 获取容器列表
30
+
31
+ **参数:**
32
+ - daemonId (str): 守护进程的唯一标识符。
33
+
34
+ **返回:**
35
+ - list[DockerContainerItem]: 包含容器列表详情的 DockerContainerItem 模型的列表。
36
+ """
37
+ result = send(
38
+ "GET",
39
+ f"{ApiPool.IMAGE}/containers",
40
+ params={
41
+ "daemonId": daemonId,
42
+ },
43
+ )
44
+
45
+ return [DockerContainerItem(**item) for item in result]
46
+
47
+ def network(self, daemonId: str) -> list[DockerNetworkItem]:
48
+ """
49
+ 获取网络接口列表
50
+
51
+ **参数:**
52
+ - daemonId (str): 守护进程的唯一标识符。
53
+
54
+ **返回:**
55
+ - list[DockerNetworkItem]: 包含网络接口列表详情的 DockerNetworkItem 模型的列表。
56
+ """
57
+ result = send(
58
+ "GET",
59
+ f"{ApiPool.IMAGE}/network",
60
+ params={
61
+ "daemonId": daemonId,
62
+ },
63
+ )
64
+ return [DockerNetworkItem(**item) for item in result]
65
+
66
+ def add(self, daemonId: str, dockerFile: str, name: str, tag: str) -> bool:
67
+ """
68
+ 新增一个镜像
69
+
70
+ **参数:**
71
+ - daemonId (str): 守护进程的唯一标识符。
72
+ - dockerFile (str): DockerFile Config
73
+ - name (str): 镜像名称。
74
+ - tag (str): 镜像版本。
75
+
76
+ **返回:**
77
+ - bool: 新增镜像成功后返回True。
78
+ """
79
+ return send(
80
+ "POST",
81
+ f"{ApiPool.IMAGE}/image",
82
+ params={"daemonId": daemonId},
83
+ data={"dockerFile": dockerFile, "name": name, "tag": tag},
84
+ )
85
+
86
+ def progress(self, daemonId: str) -> dict[str, int]:
87
+ """
88
+ 获取镜像构建进度
89
+
90
+ ## **由于文档此部分内容不详,未使用模型**
91
+
92
+ **参数:**
93
+ - daemonId (str): 守护进程的唯一标识符。
94
+
95
+ **返回:**
96
+ - dict[str, int]: 包含构建进度信息的字典。
97
+ """
98
+ return send(
99
+ "GET",
100
+ f"{ApiPool.IMAGE}/progress",
101
+ params={"daemonId": daemonId},
102
+ )