mcsmapi 0.1.1__py3-none-any.whl → 0.1.2__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/instance.py DELETED
@@ -1,424 +0,0 @@
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 DELETED
@@ -1,35 +0,0 @@
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 DELETED
@@ -1,83 +0,0 @@
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)
@@ -1,88 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: mcsmapi
3
- Version: 0.1.1
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
- ![Supported MCSManager Versions](https://img.shields.io/badge/Supported%20MCSManager%20Versions-10.2.1,10.1.0-blue)
18
- ![Python Version](https://img.shields.io/badge/Python%20Version-%3E%3D3.7-blue)
19
- ![PyPI Downloads](https://img.shields.io/pypi/dm/mcsmapi)
20
-
21
- English|[简体中文](README_zh-cn.md)
22
-
23
- ## Introduction
24
-
25
- `mcsmapi` 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`:
32
-
33
- ```bash
34
- pip install mcsmapi
35
- ```
36
-
37
- ## Usage method
38
-
39
- ### Example code
40
-
41
- Here are some examples of how to use `mcsmapi`:
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.
@@ -1,13 +0,0 @@
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.1.dist-info/LICENSE,sha256=kn0yZGn5uLIJtr2aAXy8pz_wJqal15ZGnynTU1fCnLQ,1063
10
- mcsmapi-0.1.1.dist-info/METADATA,sha256=SXCBVsVmcXMQE7LOtLDrBNg2NTxnkAHFqY_D8AQaK24,2446
11
- mcsmapi-0.1.1.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
12
- mcsmapi-0.1.1.dist-info/top_level.txt,sha256=8MUYHd1Or4cbSCd93IaqLA72w0weEuKieopVwIfVlWo,8
13
- mcsmapi-0.1.1.dist-info/RECORD,,