mcsmapi 0.1.2__tar.gz → 0.1.3__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.
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/PKG-INFO +1 -1
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi/__init__.py +2 -2
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi/models/daemon.py +1 -1
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi/models/overview.py +1 -1
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi/request.py +31 -28
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi.egg-info/PKG-INFO +1 -1
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/pyproject.toml +1 -1
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/test/test_overview_model.py +2 -2
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/LICENSE +0 -0
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/README.md +0 -0
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi/apis/daemon.py +0 -0
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi/apis/file.py +0 -0
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi/apis/image.py +0 -0
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi/apis/instance.py +0 -0
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi/apis/overview.py +0 -0
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi/apis/user.py +0 -0
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi/exceptions.py +0 -0
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi/models/file.py +0 -0
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi/models/image.py +0 -0
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi/models/instance.py +0 -0
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi/models/user.py +0 -0
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi/pool.py +0 -0
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi.egg-info/SOURCES.txt +0 -0
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi.egg-info/dependency_links.txt +0 -0
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi.egg-info/requires.txt +0 -0
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/mcsmapi.egg-info/top_level.txt +0 -0
- {mcsmapi-0.1.2 → mcsmapi-0.1.3}/setup.cfg +0 -0
@@ -7,7 +7,7 @@ from .apis.image import Image
|
|
7
7
|
from .apis.daemon import Daemon
|
8
8
|
from .apis.instance import Instance
|
9
9
|
from .apis.overview import Overview
|
10
|
-
from .request import Request
|
10
|
+
from .request import Request
|
11
11
|
|
12
12
|
|
13
13
|
class MCSMAPI:
|
@@ -21,7 +21,7 @@ class MCSMAPI:
|
|
21
21
|
|
22
22
|
def login(self, username: str, password: str) -> "MCSMAPI":
|
23
23
|
Request.set_token(
|
24
|
-
send(
|
24
|
+
Request.send(
|
25
25
|
"POST",
|
26
26
|
f"{ApiPool.AUTH}/login",
|
27
27
|
data={"username": username, "password": password},
|
@@ -11,32 +11,34 @@ class Request:
|
|
11
11
|
apikey = None
|
12
12
|
token = None
|
13
13
|
|
14
|
-
@
|
15
|
-
def set_mcsm_url(url):
|
14
|
+
@classmethod
|
15
|
+
def set_mcsm_url(cls, url):
|
16
16
|
"""设置类级别的 mcsm_url"""
|
17
|
-
|
17
|
+
cls.mcsm_url = url
|
18
18
|
|
19
|
-
@
|
20
|
-
def set_timeout(timeout):
|
19
|
+
@classmethod
|
20
|
+
def set_timeout(cls, timeout):
|
21
21
|
"""设置类级别的 timeout"""
|
22
|
-
|
22
|
+
cls.timeout = timeout
|
23
23
|
|
24
|
-
@
|
25
|
-
def set_apikey(apikey):
|
24
|
+
@classmethod
|
25
|
+
def set_apikey(cls, apikey):
|
26
26
|
"""设置类级别的 apikey"""
|
27
|
-
|
27
|
+
cls.apikey = apikey
|
28
28
|
|
29
|
-
@
|
30
|
-
def set_token(token):
|
29
|
+
@classmethod
|
30
|
+
def set_token(cls, token):
|
31
31
|
"""设置类级别的 token"""
|
32
|
-
|
32
|
+
cls.token = token
|
33
33
|
|
34
|
-
|
34
|
+
@classmethod
|
35
|
+
def __init__(cls, mcsm_url=None, timeout=None):
|
35
36
|
"""初始化时使用类变量,或者使用传入的参数覆盖默认值"""
|
36
|
-
|
37
|
-
|
37
|
+
cls.mcsm_url = mcsm_url or cls.mcsm_url
|
38
|
+
cls.timeout = timeout or cls.timeout
|
38
39
|
|
39
|
-
|
40
|
+
@classmethod
|
41
|
+
def send(cls, method: str, endpoint: Any, params=None, data=None) -> Any:
|
40
42
|
"""发送 HTTP 请求"""
|
41
43
|
if params is None:
|
42
44
|
params = {}
|
@@ -45,20 +47,20 @@ class Request:
|
|
45
47
|
if not isinstance(endpoint, str):
|
46
48
|
endpoint = str(endpoint)
|
47
49
|
|
48
|
-
url = urllib.parse.urljoin(
|
49
|
-
if
|
50
|
-
params["apikey"] =
|
51
|
-
data["apikey"] =
|
52
|
-
if
|
53
|
-
params["token"] =
|
54
|
-
data["token"] =
|
50
|
+
url = urllib.parse.urljoin(cls.mcsm_url, endpoint)
|
51
|
+
if cls.apikey is not None:
|
52
|
+
params["apikey"] = cls.apikey
|
53
|
+
data["apikey"] = cls.apikey
|
54
|
+
if cls.token is not None:
|
55
|
+
params["token"] = cls.token
|
56
|
+
data["token"] = cls.token
|
55
57
|
|
56
|
-
response =
|
58
|
+
response = cls.session.request(
|
57
59
|
method.upper(),
|
58
60
|
url,
|
59
61
|
params=params,
|
60
62
|
data=data,
|
61
|
-
timeout=
|
63
|
+
timeout=cls.timeout,
|
62
64
|
)
|
63
65
|
try:
|
64
66
|
response.raise_for_status()
|
@@ -68,15 +70,16 @@ class Request:
|
|
68
70
|
response.status_code, response.json().get("data", response.text)
|
69
71
|
) from e
|
70
72
|
|
71
|
-
|
73
|
+
@classmethod
|
74
|
+
async def upload(cls, url: str, file: bytes) -> bool:
|
72
75
|
"""上传文件"""
|
73
76
|
|
74
|
-
response =
|
77
|
+
response = cls.session.request(
|
75
78
|
"POST",
|
76
79
|
url,
|
77
80
|
headers={"Content-Type": "multipart/form-data"},
|
78
81
|
files={"file": file},
|
79
|
-
timeout=
|
82
|
+
timeout=cls.timeout,
|
80
83
|
)
|
81
84
|
try:
|
82
85
|
response.raise_for_status()
|
@@ -32,7 +32,7 @@ class TestOverviewModel(unittest.TestCase):
|
|
32
32
|
"loadavg": [0, 0, 0],
|
33
33
|
"platform": "win32",
|
34
34
|
"release": "10.0.22631",
|
35
|
-
"uptime": 905020,
|
35
|
+
"uptime": 905020.0,
|
36
36
|
"cpu": 0.11684482123110951,
|
37
37
|
},
|
38
38
|
"chart": {
|
@@ -67,7 +67,7 @@ class TestOverviewModel(unittest.TestCase):
|
|
67
67
|
"cpuMemChart": [{"cpu": 0, "mem": 13}],
|
68
68
|
"uuid": "957c6bddf379445c82bac5edf7684bbc",
|
69
69
|
"ip": "s1.example.com",
|
70
|
-
"port":
|
70
|
+
"port": 24444,
|
71
71
|
"prefix": "",
|
72
72
|
"available": True,
|
73
73
|
"remarks": "CN-ZJ-DEV-01",
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|