mcsmapi 0.1.0__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/__init__.py +8 -0
- mcsmapi/common.py +34 -0
- mcsmapi/daemon.py +86 -0
- mcsmapi/file.py +326 -0
- mcsmapi/image.py +104 -0
- mcsmapi/instance.py +424 -0
- mcsmapi/overview.py +35 -0
- mcsmapi/users.py +83 -0
- mcsmapi-0.1.0.dist-info/LICENSE +21 -0
- mcsmapi-0.1.0.dist-info/METADATA +88 -0
- mcsmapi-0.1.0.dist-info/RECORD +13 -0
- mcsmapi-0.1.0.dist-info/WHEEL +5 -0
- mcsmapi-0.1.0.dist-info/top_level.txt +1 -0
mcsmapi/__init__.py
ADDED
mcsmapi/common.py
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
import requests
|
2
|
+
|
3
|
+
|
4
|
+
class ApiClient:
|
5
|
+
def __init__(self, url, apikey=None, timeout=None):
|
6
|
+
self.url = url
|
7
|
+
self.apikey = apikey
|
8
|
+
self.timeout = timeout
|
9
|
+
self.cookies = None
|
10
|
+
self.token = None
|
11
|
+
|
12
|
+
def send(self, method, endpoint, params={}, data=None):
|
13
|
+
url = f"{self.url}/api/{endpoint}"
|
14
|
+
|
15
|
+
if self.apikey is not None:
|
16
|
+
params['apikey'] = self.apikey
|
17
|
+
if self.token is not None:
|
18
|
+
params['token'] = self.token
|
19
|
+
|
20
|
+
response = requests.request(
|
21
|
+
method, url, params=params, json=data, cookies=self.cookies, timeout=self.timeout)
|
22
|
+
response.raise_for_status()
|
23
|
+
return response
|
24
|
+
|
25
|
+
|
26
|
+
def support_login(cls):
|
27
|
+
def login(self, username, password):
|
28
|
+
seq = self.client.send(
|
29
|
+
"POST", "auth/login", data={"username": username, "password": password})
|
30
|
+
self.client.cookies = seq.cookies
|
31
|
+
self.client.token = seq.json()["data"]
|
32
|
+
|
33
|
+
setattr(cls, 'login', login)
|
34
|
+
return cls
|
mcsmapi/daemon.py
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
from .common import support_login, ApiClient
|
2
|
+
import requests
|
3
|
+
|
4
|
+
|
5
|
+
@support_login
|
6
|
+
class Daemon:
|
7
|
+
def __init__(self, url: str, apikey: str = None):
|
8
|
+
"""
|
9
|
+
Initialize a new Daemon instance.
|
10
|
+
|
11
|
+
:param url: The URL of the daemon service.
|
12
|
+
:param apikey: Optional API key for authentication.
|
13
|
+
"""
|
14
|
+
self.client = ApiClient(url, apikey)
|
15
|
+
|
16
|
+
def getList(self) -> list:
|
17
|
+
"""
|
18
|
+
Get a list of remote services.
|
19
|
+
|
20
|
+
:return: A list of remote services.
|
21
|
+
"""
|
22
|
+
return self.client.send("GET", "overview").json()["data"]["remote"]
|
23
|
+
|
24
|
+
def add(self, ip: str, port: int, remarks: str, apiKey: str, prefix: str = "") -> requests.Response:
|
25
|
+
"""
|
26
|
+
Add a new remote service.
|
27
|
+
|
28
|
+
:param ip: IP address of the remote service.
|
29
|
+
:param port: Port number of the remote service.
|
30
|
+
:param remarks: Remarks or description of the remote service.
|
31
|
+
:param apiKey: API key for the remote service.
|
32
|
+
:param prefix: Optional prefix for the remote service.
|
33
|
+
:return: Response data from the server.
|
34
|
+
"""
|
35
|
+
return self.client.send(
|
36
|
+
"POST", "service/remote_service", data={
|
37
|
+
"ip": ip,
|
38
|
+
"port": port,
|
39
|
+
"prefix": prefix,
|
40
|
+
"remarks": remarks,
|
41
|
+
"apiKey": apiKey
|
42
|
+
})
|
43
|
+
|
44
|
+
def delete(self, uuid: str) -> requests.Response:
|
45
|
+
"""
|
46
|
+
Delete a remote service by its UUID.
|
47
|
+
|
48
|
+
:param uuid: UUID of the remote service to delete.
|
49
|
+
:return: Response data from the server.
|
50
|
+
"""
|
51
|
+
return self.client.send(
|
52
|
+
"DELETE", "service/remote_service", params={"uuid": uuid})
|
53
|
+
|
54
|
+
def tryConnect(self, uuid: str) -> requests.Response:
|
55
|
+
"""
|
56
|
+
Try to connect to a remote service by its UUID.
|
57
|
+
|
58
|
+
:param uuid: UUID of the remote service to connect to.
|
59
|
+
:return: Response data from the server.
|
60
|
+
"""
|
61
|
+
return self.client.send(
|
62
|
+
"GET", "service/link_remote_service", params={"uuid": uuid})
|
63
|
+
|
64
|
+
def updateDaemonConnectConfig(self, uuid: str, ip: str, port: int, remarks: str, apiKey: str, available: bool = False, prefix: str = "") -> requests.Response:
|
65
|
+
"""
|
66
|
+
Update the configuration of a remote service.
|
67
|
+
|
68
|
+
:param uuid: UUID of the remote service to update.
|
69
|
+
:param ip: New IP address of the remote service.
|
70
|
+
:param port: New port number of the remote service.
|
71
|
+
:param remarks: New remarks or description of the remote service.
|
72
|
+
:param apiKey: New API key for the remote service.
|
73
|
+
:param available: Whether the service is available.
|
74
|
+
:param prefix: Optional prefix for the remote service.
|
75
|
+
:return: Response data from the server.
|
76
|
+
"""
|
77
|
+
return self.client.send(
|
78
|
+
"PUT", "service/remote_service", data={
|
79
|
+
"uuid": uuid,
|
80
|
+
"ip": ip,
|
81
|
+
"port": port,
|
82
|
+
"prefix": prefix,
|
83
|
+
"available": available,
|
84
|
+
"remarks": remarks,
|
85
|
+
"apiKey": apiKey
|
86
|
+
})
|
mcsmapi/file.py
ADDED
@@ -0,0 +1,326 @@
|
|
1
|
+
from .common import support_login, ApiClient
|
2
|
+
import aiohttp
|
3
|
+
import requests
|
4
|
+
import os
|
5
|
+
|
6
|
+
|
7
|
+
@support_login
|
8
|
+
class File:
|
9
|
+
def __init__(self, url: str, apikey: str = None):
|
10
|
+
"""
|
11
|
+
Initialize a new File instance.
|
12
|
+
|
13
|
+
:param url: The URL of the file service.
|
14
|
+
:param apikey: Optional API key for authentication.
|
15
|
+
"""
|
16
|
+
self.client = ApiClient(url, apikey)
|
17
|
+
|
18
|
+
def getList(self, daemonId: str, instanceUuid: str, target: str, page: int = 1, page_size: int = 10) -> requests.Response:
|
19
|
+
"""
|
20
|
+
Get a list of files.
|
21
|
+
|
22
|
+
:param daemonId: ID of the daemon.
|
23
|
+
:param instanceUuid: UUID of the instance.
|
24
|
+
:param target: Target directory path.
|
25
|
+
:param page: Page number (default is 1).
|
26
|
+
:param page_size: Number of items per page (default is 10).
|
27
|
+
:return: Response data from the server.
|
28
|
+
"""
|
29
|
+
return self.client.send("GET", "files/list", params={
|
30
|
+
"daemonId": daemonId,
|
31
|
+
"uuid": instanceUuid,
|
32
|
+
"target": target,
|
33
|
+
"page": page,
|
34
|
+
"page_size": page_size
|
35
|
+
})
|
36
|
+
|
37
|
+
def getContents(self, daemonId: str, instanceUuid: str, target: str) -> requests.Response:
|
38
|
+
"""
|
39
|
+
Get the contents of a file.
|
40
|
+
|
41
|
+
:param daemonId: ID of the daemon.
|
42
|
+
:param instanceUuid: UUID of the instance.
|
43
|
+
:param target: Path to the file.
|
44
|
+
:return: Response data from the server.
|
45
|
+
"""
|
46
|
+
return self.client.send("PUT", "files", params={
|
47
|
+
"daemonId": daemonId,
|
48
|
+
"uuid": instanceUuid
|
49
|
+
}, data={"target": target})
|
50
|
+
|
51
|
+
def update(self, daemonId: str, instanceUuid: str, target: str, text: str) -> requests.Response:
|
52
|
+
"""
|
53
|
+
Update the contents of a file.
|
54
|
+
|
55
|
+
:param daemonId: ID of the daemon.
|
56
|
+
:param instanceUuid: UUID of the instance.
|
57
|
+
:param target: Path to the file.
|
58
|
+
:param text: New content for the file.
|
59
|
+
:return: Response data from the server.
|
60
|
+
"""
|
61
|
+
return self.client.send("PUT", "files", params={
|
62
|
+
"daemonId": daemonId,
|
63
|
+
"uuid": instanceUuid
|
64
|
+
}, data={"target": target, "text": text})
|
65
|
+
|
66
|
+
def download(self, daemonId: str, instanceUuid: str, file_name: str, download_to_path: str) -> str:
|
67
|
+
"""
|
68
|
+
Download a file from the server.
|
69
|
+
|
70
|
+
:param daemonId: ID of the daemon.
|
71
|
+
:param instanceUuid: UUID of the instance.
|
72
|
+
:param file_name: Name of the file to download.
|
73
|
+
:param download_to_path: Local path where the file will be saved.
|
74
|
+
:return: Path to the downloaded file.
|
75
|
+
"""
|
76
|
+
seq = self.client.send("POST", "files/download", params={
|
77
|
+
"daemonId": daemonId,
|
78
|
+
"uuid": instanceUuid,
|
79
|
+
"file_name": file_name
|
80
|
+
}).json()
|
81
|
+
password = seq["password"]
|
82
|
+
addr = seq["addr"]
|
83
|
+
|
84
|
+
response = requests.get(
|
85
|
+
f"http://{addr}/download/{password}/{file_name}", stream=True)
|
86
|
+
if response.status_code == 200:
|
87
|
+
file_path = os.path.join(download_to_path, file_name)
|
88
|
+
with open(file_path, "wb") as f:
|
89
|
+
for chunk in response.iter_content(chunk_size=1024):
|
90
|
+
if chunk:
|
91
|
+
f.write(chunk)
|
92
|
+
return file_path
|
93
|
+
else:
|
94
|
+
raise Exception(
|
95
|
+
f"Failed to download file. Status code: {response.status_code}")
|
96
|
+
|
97
|
+
async def aiodownload(self, daemonId: str, instanceUuid: str, file_name: str, download_to_path: str) -> str:
|
98
|
+
"""
|
99
|
+
Asynchronously download a file from the server.
|
100
|
+
|
101
|
+
:param daemonId: ID of the daemon.
|
102
|
+
:param instanceUuid: UUID of the instance.
|
103
|
+
:param file_name: Name of the file to download.
|
104
|
+
:param download_to_path: Local path where the file will be saved.
|
105
|
+
:return: Path to the downloaded file.
|
106
|
+
"""
|
107
|
+
seq = self.client.send("POST", "files/download", params={
|
108
|
+
"daemonId": daemonId,
|
109
|
+
"uuid": instanceUuid,
|
110
|
+
"file_name": file_name
|
111
|
+
}).json()
|
112
|
+
password = seq["password"]
|
113
|
+
addr = seq["addr"]
|
114
|
+
|
115
|
+
async with aiohttp.ClientSession() as session:
|
116
|
+
async with session.get(f"http://{addr}/download/{password}/{file_name}") as response:
|
117
|
+
if response.status == 200:
|
118
|
+
file_path = os.path.join(download_to_path, file_name)
|
119
|
+
async with open(file_path, "wb") as f:
|
120
|
+
await f.write(await response.read())
|
121
|
+
return file_path
|
122
|
+
else:
|
123
|
+
raise Exception(
|
124
|
+
f"Failed to download file. Status code: {response.status}")
|
125
|
+
|
126
|
+
def upload(self, daemonId: str, instanceUuid: str, upload_dir: str, file_data: bytes) -> bool:
|
127
|
+
"""
|
128
|
+
Upload a file to the server.
|
129
|
+
|
130
|
+
:param daemonId: ID of the daemon.
|
131
|
+
:param instanceUuid: UUID of the instance.
|
132
|
+
:param upload_dir: Directory on the server where the file will be uploaded.
|
133
|
+
:param file_data: Binary data of the file to upload.
|
134
|
+
:return: True if the upload was successful.
|
135
|
+
"""
|
136
|
+
seq = self.client.send("POST", "files/upload", params={
|
137
|
+
"daemonId": daemonId,
|
138
|
+
"uuid": instanceUuid,
|
139
|
+
"upload_dir": upload_dir
|
140
|
+
}).json()
|
141
|
+
password = seq["password"]
|
142
|
+
addr = seq["addr"]
|
143
|
+
|
144
|
+
response = requests.post(
|
145
|
+
f"http://{addr}/upload/{password}", files={"file": file_data})
|
146
|
+
|
147
|
+
if response.status_code == 200:
|
148
|
+
return True
|
149
|
+
else:
|
150
|
+
raise Exception(
|
151
|
+
f"Failed to upload file. Status code: {response.status_code}")
|
152
|
+
|
153
|
+
async def aioupload(self, daemonId: str, instanceUuid: str, upload_dir: str, file_data: bytes) -> bool:
|
154
|
+
"""
|
155
|
+
Asynchronously upload a file to the server.
|
156
|
+
|
157
|
+
:param daemonId: ID of the daemon.
|
158
|
+
:param instanceUuid: UUID of the instance.
|
159
|
+
:param upload_dir: Directory on the server where the file will be uploaded.
|
160
|
+
:param file_data: Binary data of the file to upload.
|
161
|
+
:return: True if the upload was successful.
|
162
|
+
"""
|
163
|
+
seq = self.client.send("POST", "files/upload", params={
|
164
|
+
"daemonId": daemonId,
|
165
|
+
"uuid": instanceUuid,
|
166
|
+
"upload_dir": upload_dir
|
167
|
+
}).json()
|
168
|
+
password = seq["password"]
|
169
|
+
addr = seq["addr"]
|
170
|
+
async with aiohttp.ClientSession() as session:
|
171
|
+
async with session.post(f"http://{addr}/upload/{password}", data={"file": file_data}) as response:
|
172
|
+
if response.status == 200:
|
173
|
+
return True
|
174
|
+
else:
|
175
|
+
raise Exception(
|
176
|
+
f"Failed to upload file. Status code: {response.status}")
|
177
|
+
|
178
|
+
def copy(self, daemonId: str, instanceUuid: str, source_list: list, target_list: list) -> requests.Response:
|
179
|
+
"""
|
180
|
+
Copy files from one location to another.
|
181
|
+
|
182
|
+
:param daemonId: ID of the daemon.
|
183
|
+
:param instanceUuid: UUID of the instance.
|
184
|
+
:param source_list: List of source file paths.
|
185
|
+
:param target_list: List of target file paths.
|
186
|
+
:return: Response data from the server.
|
187
|
+
"""
|
188
|
+
data = {
|
189
|
+
"targets": [
|
190
|
+
[source, target] for source, target in zip(source_list, target_list)
|
191
|
+
]
|
192
|
+
}
|
193
|
+
|
194
|
+
return self.client.send("POST", "files/copy", params={
|
195
|
+
"daemonId": daemonId,
|
196
|
+
"uuid": instanceUuid
|
197
|
+
}, data=data)
|
198
|
+
|
199
|
+
def moveOrRename(self, daemonId: str, instanceUuid: str, source_list: list, target_list: list) -> requests.Response:
|
200
|
+
"""
|
201
|
+
Move or rename files.
|
202
|
+
|
203
|
+
:param daemonId: ID of the daemon.
|
204
|
+
:param instanceUuid: UUID of the instance.
|
205
|
+
:param source_list: List of source file paths.
|
206
|
+
:param target_list: List of target file paths.
|
207
|
+
:return: Response data from the server.
|
208
|
+
"""
|
209
|
+
data = {
|
210
|
+
"targets": [
|
211
|
+
[source, target] for source, target in zip(source_list, target_list)
|
212
|
+
]
|
213
|
+
}
|
214
|
+
return self.client.send("PUT", "files/move", params={
|
215
|
+
"daemonId": daemonId,
|
216
|
+
"uuid": instanceUuid
|
217
|
+
}, data=data)
|
218
|
+
|
219
|
+
def zip(self, daemonId: str, instanceUuid: str, zip_file_path: str, targets: list) -> requests.Response:
|
220
|
+
"""
|
221
|
+
Compress files into a ZIP archive.
|
222
|
+
|
223
|
+
:param daemonId: ID of the daemon.
|
224
|
+
:param instanceUuid: UUID of the instance.
|
225
|
+
:param zip_file_path: Path to the resulting ZIP file.
|
226
|
+
:param targets: List of files to compress.
|
227
|
+
:return: Response data from the server.
|
228
|
+
"""
|
229
|
+
zip_file_path = os.path.join(zip_file_path)
|
230
|
+
|
231
|
+
return self.client.send("POST", "files/compress", params={
|
232
|
+
"daemonId": daemonId,
|
233
|
+
"uuid": instanceUuid
|
234
|
+
}, data={
|
235
|
+
"type": 1,
|
236
|
+
"code": "utf-8",
|
237
|
+
"source": zip_file_path,
|
238
|
+
"targets": targets
|
239
|
+
})
|
240
|
+
|
241
|
+
def unzip(self, daemonId: str, instanceUuid: str, zip_file_path: str, unzip_to: str, code: str = "utf-8") -> requests.Response:
|
242
|
+
"""
|
243
|
+
Decompresses a ZIP file.
|
244
|
+
|
245
|
+
Args:
|
246
|
+
daemonId (str): ID of the daemon.
|
247
|
+
instanceUuid (str): UUID of the instance.
|
248
|
+
zip_file_path (str): Path to the ZIP file.
|
249
|
+
unzip_to (str): Directory path to extract the files to.
|
250
|
+
code (str, optional): Encoding type. Defaults to "utf-8". Must be one of "utf-8", "gbk", or "big5".
|
251
|
+
|
252
|
+
Returns:
|
253
|
+
requests.Response: Response data from the server.
|
254
|
+
|
255
|
+
Raises:
|
256
|
+
ValueError: If the provided encoding type is not valid.
|
257
|
+
"""
|
258
|
+
if code not in ["utf-8", "gbk", "big5"]:
|
259
|
+
raise ValueError(
|
260
|
+
"code must be one of utf-8, gbk, big5")
|
261
|
+
return self.client.send("POST", "files/compress", params={
|
262
|
+
"daemonId": daemonId,
|
263
|
+
"uuid": instanceUuid
|
264
|
+
}, data={
|
265
|
+
"type": 2,
|
266
|
+
"code": code,
|
267
|
+
"source": zip_file_path,
|
268
|
+
"target": unzip_to
|
269
|
+
})
|
270
|
+
|
271
|
+
def delete(self, daemonId: str, instanceUuid: str, targets: list) -> requests.Response:
|
272
|
+
"""
|
273
|
+
Deletes files or directories.
|
274
|
+
|
275
|
+
Args:
|
276
|
+
daemonId (str): ID of the daemon.
|
277
|
+
instanceUuid (str): UUID of the instance.
|
278
|
+
targets (list): List of paths to the files or directories to delete.
|
279
|
+
|
280
|
+
Returns:
|
281
|
+
requests.Response: Response data from the server.
|
282
|
+
"""
|
283
|
+
return self.client.send("DELETE", "files", params={
|
284
|
+
"daemonId": daemonId,
|
285
|
+
"uuid": instanceUuid
|
286
|
+
}, data={
|
287
|
+
"targets": targets
|
288
|
+
})
|
289
|
+
|
290
|
+
def touch(self, daemonId: str, instanceUuid: str, target: str) -> requests.Response:
|
291
|
+
"""
|
292
|
+
Creates an empty file.
|
293
|
+
|
294
|
+
Args:
|
295
|
+
daemonId (str): ID of the daemon.
|
296
|
+
instanceUuid (str): UUID of the instance.
|
297
|
+
target (str): Path to the file to create.
|
298
|
+
|
299
|
+
Returns:
|
300
|
+
requests.Response: Response data from the server.
|
301
|
+
"""
|
302
|
+
return self.client.send("POST", "files/touch", params={
|
303
|
+
"daemonId": daemonId,
|
304
|
+
"uuid": instanceUuid
|
305
|
+
}, data={
|
306
|
+
"target": target
|
307
|
+
})
|
308
|
+
|
309
|
+
def createFolder(self, daemonId: str, instanceUuid: str, target: str) -> requests.Response:
|
310
|
+
"""
|
311
|
+
Creates a directory.
|
312
|
+
|
313
|
+
Args:
|
314
|
+
daemonId (str): ID of the daemon.
|
315
|
+
instanceUuid (str): UUID of the instance.
|
316
|
+
target (str): Path to the directory to create.
|
317
|
+
|
318
|
+
Returns:
|
319
|
+
requests.Response: Response data from the server.
|
320
|
+
"""
|
321
|
+
return self.client.send("POST", "files/mkdir", params={
|
322
|
+
"daemonId": daemonId,
|
323
|
+
"uuid": instanceUuid
|
324
|
+
}, data={
|
325
|
+
"target": target
|
326
|
+
})
|
mcsmapi/image.py
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
from .common import support_login, ApiClient
|
2
|
+
import requests
|
3
|
+
|
4
|
+
|
5
|
+
@support_login
|
6
|
+
class Image:
|
7
|
+
def __init__(self, url: str, apikey: str = None):
|
8
|
+
"""
|
9
|
+
Initializes a new Image instance.
|
10
|
+
|
11
|
+
Args:
|
12
|
+
url (str): The URL of the image service.
|
13
|
+
apikey (str, optional): Optional API key for authentication. Defaults to None.
|
14
|
+
"""
|
15
|
+
self.client = ApiClient(url, apikey)
|
16
|
+
|
17
|
+
def getImageList(self, daemonId: str) -> requests.Response:
|
18
|
+
"""
|
19
|
+
Retrieves a list of Docker images.
|
20
|
+
|
21
|
+
DockerImageList:
|
22
|
+
https://docs.docker.com/engine/api/v1.37/#tag/Image/operation/ImageList
|
23
|
+
|
24
|
+
Args:
|
25
|
+
daemonId (str): ID of the Docker daemon.
|
26
|
+
|
27
|
+
Returns:
|
28
|
+
dict: Response data containing the list of Docker images.
|
29
|
+
"""
|
30
|
+
|
31
|
+
return self.client.send("GET", "environment/image", params={
|
32
|
+
"daemonId": daemonId
|
33
|
+
})
|
34
|
+
|
35
|
+
def getContainerList(self, daemonId: str) -> requests.Response:
|
36
|
+
"""
|
37
|
+
Retrieves a list of Docker containers.
|
38
|
+
|
39
|
+
DockerContainerList:
|
40
|
+
https://docs.docker.com/engine/api/v1.37/#tag/Container/operation/ContainerList
|
41
|
+
|
42
|
+
Args:
|
43
|
+
daemonId (str): ID of the Docker daemon.
|
44
|
+
|
45
|
+
Returns:
|
46
|
+
dict: Response data containing the list of Docker containers.
|
47
|
+
"""
|
48
|
+
|
49
|
+
return self.client.send("GET", "environment/containers", params={
|
50
|
+
"daemonId": daemonId
|
51
|
+
})
|
52
|
+
|
53
|
+
def getNetworkModeList(self, daemonId: str) -> requests.Response:
|
54
|
+
"""
|
55
|
+
Retrieves a list of Docker network modes.
|
56
|
+
|
57
|
+
DockerNetworkModeList:
|
58
|
+
https://docs.docker.com/engine/api/v1.37/#tag/Network/operation/NetworkList
|
59
|
+
|
60
|
+
Args:
|
61
|
+
daemonId (str): ID of the Docker daemon.
|
62
|
+
|
63
|
+
Returns:
|
64
|
+
dict: Response data containing the list of Docker network modes.
|
65
|
+
"""
|
66
|
+
|
67
|
+
return self.client.send("GET", "environment/network", params={
|
68
|
+
"daemonId": daemonId
|
69
|
+
})
|
70
|
+
|
71
|
+
def createImage(self, daemonId: str, dockerFileConfig: dict, imageName: str, tag: str) -> requests.Response:
|
72
|
+
"""
|
73
|
+
Builds a Docker image from a Dockerfile configuration.
|
74
|
+
|
75
|
+
Args:
|
76
|
+
daemonId (str): ID of the Docker daemon.
|
77
|
+
dockerFileConfig (dict): Configuration for the Dockerfile.
|
78
|
+
imageName (str): Name of the Docker image.
|
79
|
+
tag (str): Tag for the Docker image.
|
80
|
+
|
81
|
+
Returns:
|
82
|
+
dict: Response data indicating the status of the build process.
|
83
|
+
"""
|
84
|
+
return self.client.send("POST", "environment/image", params={
|
85
|
+
"daemonId": daemonId
|
86
|
+
}, data={
|
87
|
+
"dockerFile": dockerFileConfig,
|
88
|
+
"imageName": imageName,
|
89
|
+
"tag": tag
|
90
|
+
})
|
91
|
+
|
92
|
+
def buildProgress(self, daemonId: str) -> requests.Response:
|
93
|
+
"""
|
94
|
+
Retrieves the progress of a Docker image build.
|
95
|
+
|
96
|
+
Args:
|
97
|
+
daemonId (str): ID of the Docker daemon.
|
98
|
+
|
99
|
+
Returns:
|
100
|
+
dict: Response data containing the build progress information.
|
101
|
+
"""
|
102
|
+
return self.client.send("GET", "environment/image/progress", params={
|
103
|
+
"daemonId": daemonId
|
104
|
+
})
|
mcsmapi/instance.py
ADDED
@@ -0,0 +1,424 @@
|
|
1
|
+
from .common import support_login, ApiClient
|
2
|
+
import requests
|
3
|
+
|
4
|
+
|
5
|
+
@support_login
|
6
|
+
class Instance:
|
7
|
+
def __init__(self, url: str, apikey: str = None):
|
8
|
+
"""
|
9
|
+
Initializes a new Instance object.
|
10
|
+
|
11
|
+
Args:
|
12
|
+
url (str): The URL of the service endpoint.
|
13
|
+
apikey (str, optional): Optional API key for authentication. Defaults to None.
|
14
|
+
"""
|
15
|
+
self.client = ApiClient(url, apikey)
|
16
|
+
|
17
|
+
def getList(self, daemonId: str, page: int = 1, page_size: int = 10, instance_name: str = "", status: str = "") -> requests.Response:
|
18
|
+
"""
|
19
|
+
Retrieves a list of instances.
|
20
|
+
|
21
|
+
Args:
|
22
|
+
daemonId (str): ID of the daemon.
|
23
|
+
page (int, optional): Page number for pagination. Defaults to 1.
|
24
|
+
page_size (int, optional): Number of items per page. Defaults to 10.
|
25
|
+
instance_name (str, optional): Filter by instance name. Defaults to "".
|
26
|
+
status (str, optional): Filter by instance status. Defaults to "".
|
27
|
+
|
28
|
+
Returns:
|
29
|
+
requests.Response: Response data containing the list of instances.
|
30
|
+
"""
|
31
|
+
return self.client.send("GET", "service/remote_service_instances", params={
|
32
|
+
"daemonId": daemonId, "page": page, "page_size": page_size,
|
33
|
+
"instance_name": instance_name, "status": status})
|
34
|
+
|
35
|
+
def detail(self, instanceUuid: str, daemonId: str) -> requests.Response:
|
36
|
+
"""
|
37
|
+
Retrieves details of a specific instance.
|
38
|
+
|
39
|
+
Args:
|
40
|
+
instanceUuid (str): UUID of the instance.
|
41
|
+
daemonId (str): ID of the daemon.
|
42
|
+
|
43
|
+
Returns:
|
44
|
+
requests.Response: Response data containing the details of the instance.
|
45
|
+
"""
|
46
|
+
return self.client.send("GET", "instance ", params={
|
47
|
+
"uuid": instanceUuid, "daemonId": daemonId})
|
48
|
+
|
49
|
+
def create(self, daemonId: str, InstanceConfig: requests.Response) -> requests.Response:
|
50
|
+
"""
|
51
|
+
Creates a new instance.
|
52
|
+
|
53
|
+
Args:
|
54
|
+
daemonId (str): ID of the daemon.
|
55
|
+
InstanceConfig (requests.Response): Configuration for the new instance.
|
56
|
+
|
57
|
+
Returns:
|
58
|
+
requests.Response: Response data indicating the creation status.
|
59
|
+
"""
|
60
|
+
return self.client.send("POST", "instance", params={
|
61
|
+
"daemonId": daemonId}, data=InstanceConfig)
|
62
|
+
|
63
|
+
def updateConfig(self, instanceUuid: str, daemonId: str, InstanceConfig: requests.Response) -> requests.Response:
|
64
|
+
"""
|
65
|
+
Updates the configuration of an existing instance.
|
66
|
+
|
67
|
+
Args:
|
68
|
+
instanceUuid (str): UUID of the instance.
|
69
|
+
daemonId (str): ID of the daemon.
|
70
|
+
InstanceConfig (requests.Response): Updated configuration for the instance.
|
71
|
+
|
72
|
+
Returns:
|
73
|
+
requests.Response: Response data indicating the update status.
|
74
|
+
"""
|
75
|
+
return self.client.send("POST", "instance", params={
|
76
|
+
"uuid": instanceUuid, "daemonId": daemonId}, data=InstanceConfig)
|
77
|
+
|
78
|
+
def delete(self, daemonId: str, instanceUuids: list, delete_file: bool = False) -> requests.Response:
|
79
|
+
"""
|
80
|
+
Deletes one or more instances.
|
81
|
+
|
82
|
+
Args:
|
83
|
+
daemonId (str): ID of the daemon.
|
84
|
+
instanceUuids (list): List of UUIDs of the instances to delete.
|
85
|
+
delete_file (bool, optional): Whether to delete associated files. Defaults to False.
|
86
|
+
|
87
|
+
Returns:
|
88
|
+
requests.Response: Response data indicating the deletion status.
|
89
|
+
"""
|
90
|
+
return self.client.send("DELETE", "instance", params={
|
91
|
+
"daemonId": daemonId}, data={"uuids": instanceUuids, "deleteFile": delete_file})
|
92
|
+
|
93
|
+
def start(self, instanceUuid: str, daemonId: str) -> requests.Response:
|
94
|
+
"""
|
95
|
+
Starts an instance.
|
96
|
+
|
97
|
+
Args:
|
98
|
+
instanceUuid (str): UUID of the instance.
|
99
|
+
daemonId (str): ID of the daemon.
|
100
|
+
|
101
|
+
Returns:
|
102
|
+
requests.Response: Response data indicating the start status.
|
103
|
+
"""
|
104
|
+
return self.client.send("GET", "protected_instance/open", params={
|
105
|
+
"uuid": instanceUuid, "daemonId": daemonId})
|
106
|
+
|
107
|
+
def stop(self, instanceUuid: str, daemonId: str) -> requests.Response:
|
108
|
+
"""
|
109
|
+
Stops an instance.
|
110
|
+
|
111
|
+
Args:
|
112
|
+
instanceUuid (str): UUID of the instance.
|
113
|
+
daemonId (str): ID of the daemon.
|
114
|
+
|
115
|
+
Returns:
|
116
|
+
requests.Response: Response data indicating the stop status.
|
117
|
+
"""
|
118
|
+
return self.client.send("GET", "protected_instance/stop", params={
|
119
|
+
"uuid": instanceUuid, "daemonId": daemonId})
|
120
|
+
|
121
|
+
def restart(self, instanceUuid: str, daemonId: str) -> requests.Response:
|
122
|
+
"""
|
123
|
+
Restarts an instance.
|
124
|
+
|
125
|
+
Args:
|
126
|
+
instanceUuid (str): UUID of the instance.
|
127
|
+
daemonId (str): ID of the daemon.
|
128
|
+
|
129
|
+
Returns:
|
130
|
+
requests.Response: Response data indicating the restart status.
|
131
|
+
"""
|
132
|
+
return self.client.send("GET", "protected_instance/restart", params={
|
133
|
+
"uuid": instanceUuid, "daemonId": daemonId})
|
134
|
+
|
135
|
+
def kill(self, instanceUuid: str, daemonId: str) -> requests.Response:
|
136
|
+
"""
|
137
|
+
Kills an instance.
|
138
|
+
|
139
|
+
Args:
|
140
|
+
instanceUuid (str): UUID of the instance.
|
141
|
+
daemonId (str): ID of the daemon.
|
142
|
+
|
143
|
+
Returns:
|
144
|
+
requests.Response: Response data indicating the kill status.
|
145
|
+
"""
|
146
|
+
return self.client.send("GET", "protected_instance/kill", params={
|
147
|
+
"uuid": instanceUuid, "daemonId": daemonId})
|
148
|
+
|
149
|
+
def batchOperation(self, daemonId: str, instanceUuid: str, operations: str) -> requests.Response:
|
150
|
+
"""
|
151
|
+
Performs a batch operation on instances.
|
152
|
+
|
153
|
+
Args:
|
154
|
+
daemonId (str): ID of the daemon.
|
155
|
+
instanceUuid (str): UUID of the instance.
|
156
|
+
operations (str): Operation to perform. Must be one of "start", "stop", "restart", "kill".
|
157
|
+
|
158
|
+
Returns:
|
159
|
+
requests.Response: Response data indicating the operation status.
|
160
|
+
|
161
|
+
Raises:
|
162
|
+
ValueError: If the operation is not one of the allowed values.
|
163
|
+
"""
|
164
|
+
if operations not in ["start", "stop", "restart", "kill"]:
|
165
|
+
raise ValueError(
|
166
|
+
"operations must be one of start, stop, restart, kill")
|
167
|
+
return self.client.send("POST", f"instance/multi_{operations}", params={
|
168
|
+
"daemonId": daemonId, "instanceUuid": instanceUuid})
|
169
|
+
|
170
|
+
def updateInstance(self, instanceUuid: str, daemonId: str, task_name: str) -> requests.Response:
|
171
|
+
"""
|
172
|
+
Updates an instance with a specified task.
|
173
|
+
|
174
|
+
Args:
|
175
|
+
instanceUuid (str): UUID of the instance.
|
176
|
+
daemonId (str): ID of the daemon.
|
177
|
+
task_name (str): Name of the task to execute.
|
178
|
+
|
179
|
+
Returns:
|
180
|
+
requests.Response: Response data indicating the update status.
|
181
|
+
"""
|
182
|
+
return self.client.send("GET", "protected_instance/asynchronous", params={
|
183
|
+
"uuid": instanceUuid, "daemonId": daemonId, "task_name": task_name})
|
184
|
+
|
185
|
+
def sendCommand(self, instanceUuid: str, daemonId: str, command: str) -> requests.Response:
|
186
|
+
"""
|
187
|
+
Sends a command to an instance.
|
188
|
+
|
189
|
+
Args:
|
190
|
+
instanceUuid (str): UUID of the instance.
|
191
|
+
daemonId (str): ID of the daemon.
|
192
|
+
command (str): Command to send.
|
193
|
+
|
194
|
+
Returns:
|
195
|
+
requests.Response: Response data indicating the command status.
|
196
|
+
"""
|
197
|
+
return self.client.send("POST", "protected_instance/command", params={
|
198
|
+
"uuid": instanceUuid, "daemonId": daemonId, "command": command})
|
199
|
+
|
200
|
+
def getOutput(self, instanceUuid: str, daemonId: str, size: int = None) -> requests.Response:
|
201
|
+
"""
|
202
|
+
Retrieves output log from an instance.
|
203
|
+
|
204
|
+
Args:
|
205
|
+
instanceUuid (str): UUID of the instance.
|
206
|
+
daemonId (str): ID of the daemon.
|
207
|
+
size (int, optional): Number of log lines to retrieve. Defaults to None.
|
208
|
+
|
209
|
+
Returns:
|
210
|
+
requests.Response: Response data containing the output log.
|
211
|
+
"""
|
212
|
+
params = {"uuid": instanceUuid, "daemonId": daemonId}
|
213
|
+
if size is not None:
|
214
|
+
params["size"] = size
|
215
|
+
return self.client.send(
|
216
|
+
"GET", "protected_instance/outputlog", params=params)
|
217
|
+
|
218
|
+
def reinstall(self, uuid: str, daemonId: str, targetUrl: str, title: str, description: str = "") -> requests.Response:
|
219
|
+
"""
|
220
|
+
Reinstalls an instance.
|
221
|
+
|
222
|
+
Args:
|
223
|
+
uuid (str): UUID of the instance.
|
224
|
+
daemonId (str): ID of the daemon.
|
225
|
+
targetUrl (str): Target URL for the installation.
|
226
|
+
title (str): Title of the instance.
|
227
|
+
description (str, optional): Description of the instance. Defaults to "".
|
228
|
+
|
229
|
+
Returns:
|
230
|
+
requests.Response: Response data indicating the reinstall status.
|
231
|
+
"""
|
232
|
+
return self.client.send("GET", "protected_instance/install_instance", params={
|
233
|
+
"uuid": uuid, "daemonId": daemonId}, data={"targetUrl": targetUrl, "title": title, "description": description})
|
234
|
+
|
235
|
+
def typeOfInstanceConfig(self, **kwargs) -> dict:
|
236
|
+
"""
|
237
|
+
Generates an instance configuration based on the provided arguments.
|
238
|
+
|
239
|
+
Args:
|
240
|
+
**kwargs: Keyword arguments representing the configuration parameters.
|
241
|
+
|
242
|
+
Returns:
|
243
|
+
dict: An instance configuration dictionary.
|
244
|
+
|
245
|
+
Raises:
|
246
|
+
ValueError: If any unsupported keys are provided.
|
247
|
+
|
248
|
+
Supported Keys:
|
249
|
+
- nickname (str): Nickname of the instance.
|
250
|
+
- startCommand (str): Start command for the instance.
|
251
|
+
- stopCommand (str): Stop command for the instance.
|
252
|
+
- cwd (str): Current working directory for the instance.
|
253
|
+
- ie (str): Input encoding.
|
254
|
+
- oe (str): Output encoding.
|
255
|
+
- createDatetime (str): Creation datetime.
|
256
|
+
- lastDatetime (str): Last updated datetime.
|
257
|
+
- type (str): Type of the instance.
|
258
|
+
- tag (list): Tags associated with the instance.
|
259
|
+
- endTime (str): End time of the instance.
|
260
|
+
- fileCode (str): File code.
|
261
|
+
- processType (str): Process type.
|
262
|
+
- updateCommand (str): Update command.
|
263
|
+
- actionCommandList (list): List of action commands.
|
264
|
+
- crlf (int): CRLF value.
|
265
|
+
- docker (dict): Docker configuration.
|
266
|
+
- enableRcon (bool): Enable RCON.
|
267
|
+
- rconPassword (str): RCON password.
|
268
|
+
- rconPort (int): RCON port.
|
269
|
+
- rconIp (str): RCON IP address.
|
270
|
+
- terminalOption (dict): Terminal options.
|
271
|
+
- eventTask (dict): Event task settings.
|
272
|
+
- pingConfig (dict): Ping configuration.
|
273
|
+
"""
|
274
|
+
default = {
|
275
|
+
"nickname": "New Name",
|
276
|
+
"startCommand": "cmd.exe",
|
277
|
+
"stopCommand": "^C",
|
278
|
+
"cwd": "/workspaces/my_server/",
|
279
|
+
"ie": "utf8",
|
280
|
+
"oe": "gbk",
|
281
|
+
"createDatetime": "2022/2/3",
|
282
|
+
"lastDatetime": "2022/2/3 16:02",
|
283
|
+
"type": "universal",
|
284
|
+
"tag": [],
|
285
|
+
"endTime": "2022/2/28",
|
286
|
+
"fileCode": "gbk",
|
287
|
+
"processType": "docker",
|
288
|
+
"updateCommand": "shutdown -s",
|
289
|
+
"actionCommandList": [],
|
290
|
+
"crlf": 2,
|
291
|
+
"docker": self.typeOfDockerConfig(),
|
292
|
+
|
293
|
+
"enableRcon": True,
|
294
|
+
"rconPassword": "123456",
|
295
|
+
"rconPort": 2557,
|
296
|
+
"rconIp": "192.168.1.233",
|
297
|
+
|
298
|
+
"terminalOption": {
|
299
|
+
"haveColor": False,
|
300
|
+
"pty": True,
|
301
|
+
},
|
302
|
+
"eventTask": {
|
303
|
+
"autoStart": False,
|
304
|
+
"autoRestart": True,
|
305
|
+
"ignore": False,
|
306
|
+
},
|
307
|
+
"pingConfig": {
|
308
|
+
"ip": "",
|
309
|
+
"port": 25565,
|
310
|
+
"type": 1,
|
311
|
+
}
|
312
|
+
}
|
313
|
+
|
314
|
+
supported_keys = set(default.keys())
|
315
|
+
unsupported_keys = set(kwargs.keys()) - supported_keys
|
316
|
+
|
317
|
+
if unsupported_keys:
|
318
|
+
raise ValueError(
|
319
|
+
f"Unsupported keys: {unsupported_keys}. Supported keys are: {supported_keys}")
|
320
|
+
|
321
|
+
config = default.copy()
|
322
|
+
config.update(kwargs)
|
323
|
+
|
324
|
+
return config
|
325
|
+
|
326
|
+
def typeOfDockerConfig(self, **kwargs) -> dict:
|
327
|
+
"""
|
328
|
+
Generates a Docker configuration based on the provided arguments.
|
329
|
+
|
330
|
+
Args:
|
331
|
+
**kwargs: Keyword arguments representing the configuration parameters.
|
332
|
+
|
333
|
+
Returns:
|
334
|
+
dict: A Docker configuration dictionary.
|
335
|
+
|
336
|
+
Raises:
|
337
|
+
ValueError: If any unsupported keys are provided.
|
338
|
+
|
339
|
+
Supported Keys:
|
340
|
+
- containerName (str): Container name.
|
341
|
+
- image (str): Docker image name.
|
342
|
+
- memory (int): Memory limit in MB.
|
343
|
+
- ports (list): Ports mapping.
|
344
|
+
- extraVolumes (list): Extra volumes.
|
345
|
+
- maxSpace (int): Maximum space.
|
346
|
+
- network (str): Network mode.
|
347
|
+
- io (int): IO limit.
|
348
|
+
- networkMode (str): Network mode.
|
349
|
+
- networkAliases (list): Network aliases.
|
350
|
+
- cpusetCpus (str): CPU set.
|
351
|
+
- cpuUsage (int): CPU usage.
|
352
|
+
- workingDir (str): Working directory.
|
353
|
+
- env (list): Environment variables.
|
354
|
+
"""
|
355
|
+
default = {
|
356
|
+
"containerName": "",
|
357
|
+
"image": "mcsm-ubuntu:22.04",
|
358
|
+
"memory": 1024,
|
359
|
+
"ports": ["25565:25565/tcp"],
|
360
|
+
"extraVolumes": [],
|
361
|
+
"maxSpace": None,
|
362
|
+
"network": None,
|
363
|
+
"io": None,
|
364
|
+
"networkMode": "bridge",
|
365
|
+
"networkAliases": [],
|
366
|
+
"cpusetCpus": "",
|
367
|
+
"cpuUsage": 100,
|
368
|
+
"workingDir": "",
|
369
|
+
"env": []
|
370
|
+
}
|
371
|
+
|
372
|
+
supported_keys = set(default.keys())
|
373
|
+
unsupported_keys = set(kwargs.keys()) - supported_keys
|
374
|
+
|
375
|
+
if unsupported_keys:
|
376
|
+
raise ValueError(
|
377
|
+
f"Unsupported keys: {unsupported_keys}. Supported keys are: {supported_keys}")
|
378
|
+
|
379
|
+
config = default.copy()
|
380
|
+
config.update(kwargs)
|
381
|
+
|
382
|
+
return config
|
383
|
+
|
384
|
+
# Unused functions
|
385
|
+
# ...
|
386
|
+
|
387
|
+
# Unused functions
|
388
|
+
# def typeOfInstanceDetail(self, **kwargs):
|
389
|
+
# default = {
|
390
|
+
# "config": self.typeOfInstanceConfig(),
|
391
|
+
# "info": {
|
392
|
+
# "currentPlayers": -1,
|
393
|
+
# "fileLock": 0,
|
394
|
+
# "maxPlayers": -1,
|
395
|
+
# "openFrpStatus": False,
|
396
|
+
# "playersChart": [],
|
397
|
+
# "version": "",
|
398
|
+
# },
|
399
|
+
# "instanceUuid": "50c73059001b436fa85c0d8221c157cf",
|
400
|
+
# "processInfo": {
|
401
|
+
# "cpu": 0,
|
402
|
+
# "memory": 0,
|
403
|
+
# "ppid": 0,
|
404
|
+
# "pid": 0,
|
405
|
+
# "ctime": 0,
|
406
|
+
# "elapsed": 0,
|
407
|
+
# "timestamp": 0
|
408
|
+
# },
|
409
|
+
# "space": 0,
|
410
|
+
# "started": 6,
|
411
|
+
# "status": 3,
|
412
|
+
# }
|
413
|
+
#
|
414
|
+
# supported_keys = set(default.keys())
|
415
|
+
# unsupported_keys = set(kwargs.keys()) - supported_keys
|
416
|
+
#
|
417
|
+
# if unsupported_keys:
|
418
|
+
# raise ValueError(
|
419
|
+
# f"Unsupported keys: {unsupported_keys}. Supported keys are: {supported_keys}")
|
420
|
+
#
|
421
|
+
# config = default.copy()
|
422
|
+
# config.update(kwargs)
|
423
|
+
#
|
424
|
+
# return config
|
mcsmapi/overview.py
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
from .common import support_login, ApiClient
|
2
|
+
import requests
|
3
|
+
|
4
|
+
|
5
|
+
@support_login
|
6
|
+
class Overview:
|
7
|
+
"""
|
8
|
+
Represents an overview client that interacts with an API endpoint.
|
9
|
+
|
10
|
+
Attributes:
|
11
|
+
client (ApiClient): The API client used for making requests.
|
12
|
+
|
13
|
+
Args:
|
14
|
+
url (str): The base URL of the API.
|
15
|
+
apikey (str, optional): The API key for authentication. Defaults to None.
|
16
|
+
"""
|
17
|
+
|
18
|
+
def __init__(self, url: str, apikey: str = None):
|
19
|
+
"""
|
20
|
+
Initializes a new instance of the Overview class.
|
21
|
+
|
22
|
+
Args:
|
23
|
+
url (str): The base URL of the API.
|
24
|
+
apikey (str, optional): The API key for authentication. Defaults to None.
|
25
|
+
"""
|
26
|
+
self.client = ApiClient(url, apikey)
|
27
|
+
|
28
|
+
def get_data(self) -> requests.Response:
|
29
|
+
"""
|
30
|
+
Retrieves overview data from the API.
|
31
|
+
|
32
|
+
Returns:
|
33
|
+
dict: The overview data as returned by the API.
|
34
|
+
"""
|
35
|
+
return self.client.send("GET", "overview")
|
mcsmapi/users.py
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
from .common import support_login, ApiClient
|
2
|
+
import requests
|
3
|
+
|
4
|
+
|
5
|
+
@support_login
|
6
|
+
class Users:
|
7
|
+
"""
|
8
|
+
Represents a users client that interacts with an API endpoint for user management.
|
9
|
+
|
10
|
+
Attributes:
|
11
|
+
client (ApiClient): The API client used for making requests.
|
12
|
+
|
13
|
+
Args:
|
14
|
+
url (str): The base URL of the API.
|
15
|
+
apikey (str, optional): The API key for authentication. Defaults to None.
|
16
|
+
"""
|
17
|
+
|
18
|
+
def __init__(self, url: str, apikey: str = None):
|
19
|
+
"""
|
20
|
+
Initializes a new instance of the Users class.
|
21
|
+
|
22
|
+
Args:
|
23
|
+
url (str): The base URL of the API.
|
24
|
+
apikey (str, optional): The API key for authentication. Defaults to None.
|
25
|
+
"""
|
26
|
+
self.client = ApiClient(url, apikey)
|
27
|
+
|
28
|
+
def get_list(self, username: str = "", page: int = 1, page_size: int = 10, role: str = "") -> requests.Response:
|
29
|
+
"""
|
30
|
+
Retrieves a list of users from the API.
|
31
|
+
|
32
|
+
Args:
|
33
|
+
username (str, optional): The username to search for. Defaults to "".
|
34
|
+
page (int, optional): The page number for pagination. Defaults to 1.
|
35
|
+
page_size (int, optional): The number of items per page. Defaults to 10.
|
36
|
+
role (str, optional): The role to filter by. Defaults to "".
|
37
|
+
|
38
|
+
Returns:
|
39
|
+
dict: The list of users as returned by the API.
|
40
|
+
"""
|
41
|
+
return self.client.send("GET", "auth/search", params={
|
42
|
+
"userName": username, "page": page, "page_size": page_size, "role": role})
|
43
|
+
|
44
|
+
def create(self, username: str, password: str, permission: int = 1) -> requests.Response:
|
45
|
+
"""
|
46
|
+
Creates a new user.
|
47
|
+
|
48
|
+
Args:
|
49
|
+
username (str): The username for the new user.
|
50
|
+
password (str): The password for the new user.
|
51
|
+
permission (int, optional): The permission level for the new user. Defaults to 1.
|
52
|
+
|
53
|
+
Returns:
|
54
|
+
dict: The response from the API after creating the user.
|
55
|
+
"""
|
56
|
+
return self.client.send("POST", "auth", data={
|
57
|
+
"username": username, "password": password, "permission": permission})
|
58
|
+
|
59
|
+
def update(self, uuid: str, config: dict = {}) -> requests.Response:
|
60
|
+
"""
|
61
|
+
Updates an existing user.
|
62
|
+
|
63
|
+
Args:
|
64
|
+
uuid (str): The UUID of the user to update.
|
65
|
+
config (dict, optional): The configuration updates for the user. Defaults to {}.
|
66
|
+
|
67
|
+
Returns:
|
68
|
+
dict: The response from the API after updating the user.
|
69
|
+
"""
|
70
|
+
return self.client.send("PUT", "auth", data={
|
71
|
+
"uuid": uuid, "config": config})
|
72
|
+
|
73
|
+
def delete(self, uuids: list = []) -> requests.Response:
|
74
|
+
"""
|
75
|
+
Deletes one or more users.
|
76
|
+
|
77
|
+
Args:
|
78
|
+
uuids (list, optional): A list of UUIDs of the users to delete. Defaults to [].
|
79
|
+
|
80
|
+
Returns:
|
81
|
+
dict: The response from the API after deleting the users.
|
82
|
+
"""
|
83
|
+
return self.client.send("DELETE", "auth", data=uuids)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 molanp
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,88 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: mcsmapi
|
3
|
+
Version: 0.1.0
|
4
|
+
Summary: A Pypi package based on MCSManager, designed to simplify interaction with MCSM API.
|
5
|
+
Home-page: https://github.com/molanp/mcsmapi
|
6
|
+
Author: molanp
|
7
|
+
Author-email: luotian233@foxmail.com
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
10
|
+
Description-Content-Type: text/markdown
|
11
|
+
License-File: LICENSE
|
12
|
+
Requires-Dist: requests
|
13
|
+
Requires-Dist: aiohttp
|
14
|
+
|
15
|
+
# MCSM API Client
|
16
|
+
|
17
|
+

|
18
|
+

|
19
|
+

|
20
|
+
|
21
|
+
English|[简体中文](README_zh-cn.md)
|
22
|
+
|
23
|
+
## Introduction
|
24
|
+
|
25
|
+
`mcsmapi-client` is a Pypi package based on [MCSManager](https://github.com/MCSManager/MCSManager), designed to simplify interaction with MCSM API.
|
26
|
+
|
27
|
+
Through this library, you can easily access and operate various functions provided by MCSM.
|
28
|
+
|
29
|
+
## Installation
|
30
|
+
|
31
|
+
You can use `pip` to install `mcsmapi-client`:
|
32
|
+
|
33
|
+
```bash
|
34
|
+
pip install mcsmapi_client
|
35
|
+
```
|
36
|
+
|
37
|
+
## Usage method
|
38
|
+
|
39
|
+
### Example code
|
40
|
+
|
41
|
+
Here are some examples of how to use `mcsmapi-client`:
|
42
|
+
|
43
|
+
```python
|
44
|
+
from mcsmapi import overview
|
45
|
+
|
46
|
+
# if you have a apikey, you can use this method
|
47
|
+
client = Overview(url=" https://example.com/",apikey="your_api_key")
|
48
|
+
|
49
|
+
# if you do not have a apikey, you can use this method
|
50
|
+
client = Overview(url=" https://example.com/")
|
51
|
+
# login
|
52
|
+
client.login(username="your_username",password="your_password")
|
53
|
+
|
54
|
+
# Get dashboard data
|
55
|
+
response = client.getData()
|
56
|
+
print(response.json())
|
57
|
+
```
|
58
|
+
|
59
|
+
### Supported functions
|
60
|
+
|
61
|
+
- [x] Login (`(func) login`)
|
62
|
+
- [x] Dashboard Data (`(cls) Overview`)
|
63
|
+
- [x] User Management (`(cls) Users`)
|
64
|
+
- [x] Instance Management (`(cls) Instance`)
|
65
|
+
- [x] Daemon Management (`(cls) Daemon`)
|
66
|
+
- [x] File Management (`(cls) File`)
|
67
|
+
- [x] Image Management (`(cls) Image`)
|
68
|
+
|
69
|
+
## Supported MCSM versions
|
70
|
+
|
71
|
+
The current version of MCSMAPI client supports the following MCSM versions:
|
72
|
+
|
73
|
+
- 10.2.1
|
74
|
+
- 10.1.0
|
75
|
+
|
76
|
+
## Compatible Python versions
|
77
|
+
|
78
|
+
- Python version 3.7 and above.
|
79
|
+
|
80
|
+
## Contribution
|
81
|
+
|
82
|
+
If you find any issues or have improvement suggestions, please feel free to submit [Issue](https://github.com/molanp/mcsmapi-client/issues) or create a [Pull Request](https://github.com/molanp/mcsmapi-client/pulls).
|
83
|
+
|
84
|
+
## License
|
85
|
+
|
86
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
87
|
+
|
88
|
+
Please refer to [LICENSE](LICENSE) File for more information.
|
@@ -0,0 +1,13 @@
|
|
1
|
+
mcsmapi/__init__.py,sha256=ZZYFSPzhioM6uQOejbcrxs3phmCXT16YZF2-CZGZldk,204
|
2
|
+
mcsmapi/common.py,sha256=rsa0lsKd2pEMvrVWTKa-pn03CQH89hlGEFm_OHmntaM,1003
|
3
|
+
mcsmapi/daemon.py,sha256=ghkyy3aihFL4vr3qXd-LQWgujfkjEhwlfiGhU54IdXM,3100
|
4
|
+
mcsmapi/file.py,sha256=dmd_G9zeujDs471Miw4VL0mfumcckDL-pnfHyuGfe4I,11968
|
5
|
+
mcsmapi/image.py,sha256=aqgR5UZCqc-tfL-HXQk-KFTqkhXk75ordYf_F-Q23pY,3202
|
6
|
+
mcsmapi/instance.py,sha256=jNGwtDJ-L636ouB2HkDwazXF5BtjkjK48lIg_KL3LRs,15296
|
7
|
+
mcsmapi/overview.py,sha256=vzJFzE5DEmbhqSXqPk_X7kuR8mSQGEQPjuYy45BgRBE,980
|
8
|
+
mcsmapi/users.py,sha256=BQT3dG8IVmstzJHCArv7Hfvpzw0HDj2JQ3AmvtvwVb8,2958
|
9
|
+
mcsmapi-0.1.0.dist-info/LICENSE,sha256=kn0yZGn5uLIJtr2aAXy8pz_wJqal15ZGnynTU1fCnLQ,1063
|
10
|
+
mcsmapi-0.1.0.dist-info/METADATA,sha256=gdqO5nYXYdx6bTDlFr3bXUuGTYCNVDUKon0sIvSZoG0,2481
|
11
|
+
mcsmapi-0.1.0.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
|
12
|
+
mcsmapi-0.1.0.dist-info/top_level.txt,sha256=8MUYHd1Or4cbSCd93IaqLA72w0weEuKieopVwIfVlWo,8
|
13
|
+
mcsmapi-0.1.0.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
mcsmapi
|