compshare-cli 0.5.2__py3-none-any.whl → 0.5.3__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.
- compshare_cli/__init__.py +1 -1
- compshare_cli/actions.py +0 -1
- compshare_cli/api.py +0 -7
- compshare_cli/commands/instance.py +72 -0
- compshare_cli/i18n.py +7 -8
- compshare_cli/mcp_server.py +1 -0
- compshare_cli/sdk.py +46 -15
- {compshare_cli-0.5.2.dist-info → compshare_cli-0.5.3.dist-info}/METADATA +1 -1
- {compshare_cli-0.5.2.dist-info → compshare_cli-0.5.3.dist-info}/RECORD +13 -13
- {compshare_cli-0.5.2.dist-info → compshare_cli-0.5.3.dist-info}/WHEEL +0 -0
- {compshare_cli-0.5.2.dist-info → compshare_cli-0.5.3.dist-info}/entry_points.txt +0 -0
- {compshare_cli-0.5.2.dist-info → compshare_cli-0.5.3.dist-info}/licenses/LICENSE +0 -0
- {compshare_cli-0.5.2.dist-info → compshare_cli-0.5.3.dist-info}/top_level.txt +0 -0
compshare_cli/__init__.py
CHANGED
compshare_cli/actions.py
CHANGED
compshare_cli/api.py
CHANGED
|
@@ -236,13 +236,6 @@ def error_hint(action: str, code: int) -> Optional[str]:
|
|
|
236
236
|
hints = {
|
|
237
237
|
("DeleteCompshareDisk", 8434): "The disk is still detaching. Wait a moment and retry.",
|
|
238
238
|
("AttachUS3", 8433): "Confirm that US3 is enabled for the selected region and account.",
|
|
239
|
-
("GetCompShareInstanceMonitor", 210): (
|
|
240
|
-
"This production endpoint currently rejects instance IDs; "
|
|
241
|
-
"use the console for monitoring."
|
|
242
|
-
),
|
|
243
|
-
("GetCompShareInstanceMonitor", 230): (
|
|
244
|
-
"This production endpoint is currently incompatible; use the console for monitoring."
|
|
245
|
-
),
|
|
246
239
|
}
|
|
247
240
|
return tr(hints[(action, code)]) if (action, code) in hints else None
|
|
248
241
|
|
|
@@ -107,6 +107,15 @@ JOB_COLUMNS = (
|
|
|
107
107
|
("CreatedTime", "CREATED"),
|
|
108
108
|
)
|
|
109
109
|
|
|
110
|
+
MONITOR_METRIC_LABELS = {
|
|
111
|
+
"uhost_cpu_used": "CPU",
|
|
112
|
+
"cloudwatch_memory_usage": "MEMORY",
|
|
113
|
+
"cloudwatch_sys_disk_used_per": "SYSTEM DISK",
|
|
114
|
+
"cloudwatch_data_disk_used_per": "DATA DISKS",
|
|
115
|
+
"cloudwatch_gpu_memory_usage": "VRAM",
|
|
116
|
+
"cloudwatch_gpu_util": "GPU",
|
|
117
|
+
}
|
|
118
|
+
|
|
110
119
|
INSTANCE_SHOW_SECTION_KEYS = {
|
|
111
120
|
"ip": ("IPSet",),
|
|
112
121
|
"softwares": ("Softwares",),
|
|
@@ -185,6 +194,27 @@ def _instance_rows(response: Dict[str, Any]) -> Iterable[Dict[str, Any]]:
|
|
|
185
194
|
yield row
|
|
186
195
|
|
|
187
196
|
|
|
197
|
+
def _monitor_rows(response: Dict[str, Any]) -> Iterable[Dict[str, Any]]:
|
|
198
|
+
data = response.get("Data") or {}
|
|
199
|
+
for host in [*(data.get("List") or []), *(data.get("PodList") or [])]:
|
|
200
|
+
for metric in host.get("Metrics") or []:
|
|
201
|
+
metric_key = metric.get("MetricKey") or ""
|
|
202
|
+
for result in metric.get("Results") or [{}]:
|
|
203
|
+
latest = max(
|
|
204
|
+
result.get("Values") or [],
|
|
205
|
+
key=lambda point: point.get("Timestamp") or 0,
|
|
206
|
+
default={},
|
|
207
|
+
)
|
|
208
|
+
tags = result.get("TagMap") or {}
|
|
209
|
+
yield {
|
|
210
|
+
"UHostId": result.get("ResourceId") or host.get("UHostId") or host.get("PodId"),
|
|
211
|
+
"MetricKey": tr(MONITOR_METRIC_LABELS.get(metric_key, metric_key)),
|
|
212
|
+
"Value": latest.get("Value"),
|
|
213
|
+
"Timestamp": latest.get("Timestamp"),
|
|
214
|
+
"Device": tags.get("gpu_bus_id") or tags.get("mount") or tags.get("disk"),
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
|
|
188
218
|
def _memory_display(value: Any) -> Any:
|
|
189
219
|
return f"{value // 1024}GiB" if isinstance(value, int) else value
|
|
190
220
|
|
|
@@ -2186,6 +2216,48 @@ def refund(ctx: typer.Context, instances: List[str] = typer.Argument(...)) -> No
|
|
|
2186
2216
|
)
|
|
2187
2217
|
|
|
2188
2218
|
|
|
2219
|
+
@app.command("monitor", help="Get instance monitoring data.")
|
|
2220
|
+
def monitor(
|
|
2221
|
+
ctx: typer.Context, instances: List[str] = typer.Argument(..., help="Instance IDs.")
|
|
2222
|
+
) -> None:
|
|
2223
|
+
state = runtime(ctx)
|
|
2224
|
+
requested = list(dict.fromkeys(instances))
|
|
2225
|
+
locations, missing = _locate_instances(state, requested)
|
|
2226
|
+
if missing:
|
|
2227
|
+
raise UsageError(tr("Instance {instance} was not found.", instance=missing[0]))
|
|
2228
|
+
groups: Dict[Tuple[str, str], List[str]] = {}
|
|
2229
|
+
for identifier in requested:
|
|
2230
|
+
region, zone, _ = locations[identifier]
|
|
2231
|
+
groups.setdefault((region, zone), []).append(identifier)
|
|
2232
|
+
response: Dict[str, Any] = {"Data": {"List": [], "PodList": []}}
|
|
2233
|
+
for (region, zone), ids in groups.items():
|
|
2234
|
+
for offset in range(0, len(ids), 10):
|
|
2235
|
+
current = call(
|
|
2236
|
+
state,
|
|
2237
|
+
"GetCompShareInstanceMonitor",
|
|
2238
|
+
{"Region": region, "Zone": zone, "UHostIds": ids[offset : offset + 10]},
|
|
2239
|
+
)
|
|
2240
|
+
data = current.get("Data") or {}
|
|
2241
|
+
for key in ("List", "PodList"):
|
|
2242
|
+
response["Data"][key].extend(data.get(key) or [])
|
|
2243
|
+
rows = list(_monitor_rows(response))
|
|
2244
|
+
renderer = Renderer(state.json_output, state.show_sensitive)
|
|
2245
|
+
if not state.json_output and not rows:
|
|
2246
|
+
renderer.console.print(tr("No monitoring data returned for the selected instances."))
|
|
2247
|
+
return
|
|
2248
|
+
renderer.data(
|
|
2249
|
+
response,
|
|
2250
|
+
rows=rows,
|
|
2251
|
+
columns=(
|
|
2252
|
+
("UHostId", "INSTANCE"),
|
|
2253
|
+
("MetricKey", "METRIC"),
|
|
2254
|
+
("Value", "VALUE (%)"),
|
|
2255
|
+
("Timestamp", "TIME"),
|
|
2256
|
+
("Device", "DEVICE"),
|
|
2257
|
+
),
|
|
2258
|
+
)
|
|
2259
|
+
|
|
2260
|
+
|
|
2189
2261
|
@app.command("charge", help="Change an instance billing type.")
|
|
2190
2262
|
def charge(
|
|
2191
2263
|
ctx: typer.Context,
|
compshare_cli/i18n.py
CHANGED
|
@@ -359,8 +359,10 @@ ZH_TRANSLATIONS: Dict[str, str] = {
|
|
|
359
359
|
"Query current instance pricing.": "查询实例当前计费价格。",
|
|
360
360
|
"Query instance refund amounts.": "查询实例退款金额。",
|
|
361
361
|
"Get instance monitoring data.": "获取实例监控数据。",
|
|
362
|
-
"
|
|
363
|
-
|
|
362
|
+
"Monitoring requires UHostIds to be an array of strings.": (
|
|
363
|
+
"监控请求的 UHostIds 必须为字符串数组。"
|
|
364
|
+
),
|
|
365
|
+
"No monitoring data returned for the selected instances.": "所选实例暂无监控数据。",
|
|
364
366
|
"Change an instance billing type.": "变更实例计费方式。",
|
|
365
367
|
"Check network accelerator status.": "检查网络加速状态。",
|
|
366
368
|
"List models in the model repository.": "列出模型仓库中的模型。",
|
|
@@ -681,6 +683,9 @@ ZH_TRANSLATIONS: Dict[str, str] = {
|
|
|
681
683
|
"SOURCE": "来源",
|
|
682
684
|
"VERSION": "版本",
|
|
683
685
|
"TAGS": "标签",
|
|
686
|
+
"METRIC": "指标",
|
|
687
|
+
"VALUE (%)": "使用率(%)",
|
|
688
|
+
"TIME": "采样时间",
|
|
684
689
|
"ACCOUNT ID": "账户 ID",
|
|
685
690
|
"ACCOUNT": "账户",
|
|
686
691
|
"DISK ID": "云盘 ID",
|
|
@@ -892,12 +897,6 @@ ZH_TRANSLATIONS: Dict[str, str] = {
|
|
|
892
897
|
"Confirm that US3 is enabled for the selected region and account.": (
|
|
893
898
|
"请确认所选地域和账户已开通 US3。"
|
|
894
899
|
),
|
|
895
|
-
"This production endpoint currently rejects instance IDs; use the console for monitoring.": (
|
|
896
|
-
"生产环境的该接口当前会拒绝实例 ID,请暂时在控制台查看监控。"
|
|
897
|
-
),
|
|
898
|
-
"This production endpoint is currently incompatible; use the console for monitoring.": (
|
|
899
|
-
"生产环境的该接口当前不兼容,请暂时在控制台查看监控。"
|
|
900
|
-
),
|
|
901
900
|
"This production endpoint currently rejects its action; use instance show or the console.": (
|
|
902
901
|
"生产环境的该接口当前拒绝请求,请使用 instance show 或控制台。"
|
|
903
902
|
),
|
compshare_cli/mcp_server.py
CHANGED
compshare_cli/sdk.py
CHANGED
|
@@ -5,9 +5,11 @@ from typing import Any, Dict, Optional, Tuple
|
|
|
5
5
|
|
|
6
6
|
from ucloud.client import Client
|
|
7
7
|
from ucloud.core import exc as ucloud_exc
|
|
8
|
-
from ucloud.core.transport import SSLOption
|
|
8
|
+
from ucloud.core.transport import Response, SSLOption
|
|
9
9
|
|
|
10
10
|
from compshare_cli.config import Profile
|
|
11
|
+
from compshare_cli.errors import UsageError
|
|
12
|
+
from compshare_cli.i18n import tr
|
|
11
13
|
|
|
12
14
|
|
|
13
15
|
class CompShareSDK:
|
|
@@ -34,17 +36,40 @@ class CompShareSDK:
|
|
|
34
36
|
self._service = Client(config, logger=logger).ucompshare()
|
|
35
37
|
|
|
36
38
|
def invoke(self, action: str, params: Dict[str, Any]) -> Dict[str, Any]:
|
|
39
|
+
if action == "GetCompShareInstanceMonitor":
|
|
40
|
+
return self._json_response(action, self._send_request(action, params))
|
|
37
41
|
return self._service.invoke(action, dict(params))
|
|
38
42
|
|
|
39
43
|
def download(self, action: str, params: Dict[str, Any]) -> Tuple[bytes, Dict[str, str]]:
|
|
40
44
|
"""Invoke an authenticated action whose success response is a file stream."""
|
|
45
|
+
response = self._send_request(action, params)
|
|
46
|
+
if "json" in str(response.headers.get("Content-Type", "")).lower():
|
|
47
|
+
self._json_response(action, response)
|
|
48
|
+
return response.content, {str(key): str(value) for key, value in response.headers.items()}
|
|
49
|
+
|
|
50
|
+
def _send_request(self, action: str, params: Dict[str, Any]) -> Response:
|
|
41
51
|
args = dict(params)
|
|
42
52
|
args["Action"] = action
|
|
43
53
|
for handler in self._service.middleware.request_handlers:
|
|
44
54
|
args = handler(args)
|
|
55
|
+
monitoring = action == "GetCompShareInstanceMonitor"
|
|
56
|
+
instance_ids = args.get("UHostIds")
|
|
57
|
+
if monitoring and instance_ids is not None:
|
|
58
|
+
if not isinstance(instance_ids, list) or any(
|
|
59
|
+
not isinstance(identifier, str) for identifier in instance_ids
|
|
60
|
+
):
|
|
61
|
+
raise UsageError(tr("Monitoring requires UHostIds to be an array of strings."))
|
|
62
|
+
# This endpoint signs native JSON arrays by concatenating their elements.
|
|
63
|
+
args["UHostIds"] = "".join(instance_ids)
|
|
45
64
|
request = self._service._build_http_request(args)
|
|
65
|
+
if monitoring:
|
|
66
|
+
request.json = dict(request.data)
|
|
67
|
+
if instance_ids is not None:
|
|
68
|
+
request.json["UHostIds"] = list(instance_ids)
|
|
69
|
+
request.data = None
|
|
70
|
+
request.headers["Content-Type"] = "application/json"
|
|
46
71
|
try:
|
|
47
|
-
|
|
72
|
+
return self._service.transport.send(
|
|
48
73
|
request,
|
|
49
74
|
ssl_option=SSLOption(
|
|
50
75
|
self._service.config.ssl_verify,
|
|
@@ -60,17 +85,23 @@ class CompShareSDK:
|
|
|
60
85
|
handler(error)
|
|
61
86
|
raise
|
|
62
87
|
|
|
63
|
-
|
|
64
|
-
|
|
88
|
+
def _json_response(self, action: str, response: Response) -> Dict[str, Any]:
|
|
89
|
+
try:
|
|
65
90
|
data = response.json() or {}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
91
|
+
except Exception as error:
|
|
92
|
+
for handler in self._service.middleware.exception_handlers:
|
|
93
|
+
handler(error)
|
|
94
|
+
raise
|
|
95
|
+
for handler in self._service.middleware.response_handlers:
|
|
96
|
+
data = handler(data, response)
|
|
97
|
+
if int(data.get("RetCode", -1)) != 0:
|
|
98
|
+
error = ucloud_exc.RetCodeException(
|
|
99
|
+
action=action,
|
|
100
|
+
code=int(data.get("RetCode", 0)),
|
|
101
|
+
message=data.get("Message", ""),
|
|
102
|
+
request_uuid=response.request_uuid,
|
|
103
|
+
)
|
|
104
|
+
for handler in self._service.middleware.exception_handlers:
|
|
105
|
+
handler(error)
|
|
106
|
+
raise error
|
|
107
|
+
return data
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
compshare_cli/__init__.py,sha256=
|
|
1
|
+
compshare_cli/__init__.py,sha256=dFbD4eJkqYWkk4nUZvNLCRpjKYnpXCoaLGlgBARFFyk,60
|
|
2
2
|
compshare_cli/__main__.py,sha256=ftkB0R9jLZejzr717131qktgfFhTe12noFeGqQsVZMc,74
|
|
3
|
-
compshare_cli/actions.py,sha256=
|
|
4
|
-
compshare_cli/api.py,sha256=
|
|
3
|
+
compshare_cli/actions.py,sha256=lLvd2zPelRVzMokLHGX0O0VFucrmTqk-uR0cOitqroc,3594
|
|
4
|
+
compshare_cli/api.py,sha256=O3qQkUW3f80-EdF-dZ-z9ziwsZEZLp211bZ4WkqSu5o,8952
|
|
5
5
|
compshare_cli/cli.py,sha256=esimt5yCxnAb0KIFaxvj4iwEPPv1S7wJzwDhFlMS2-0,19664
|
|
6
6
|
compshare_cli/config.py,sha256=xzcP4dvZEclEAaQHsB0ybF7jnxKC9cY_EbWQl0w7TO4,7529
|
|
7
7
|
compshare_cli/errors.py,sha256=ZVVxqJnmaBFfV4k-Q7wuLvxA83iQhmFZ_Bx5w6o9EN4,262
|
|
8
|
-
compshare_cli/i18n.py,sha256=
|
|
8
|
+
compshare_cli/i18n.py,sha256=0CpQyQIuP5wKAKS4s1TwmNYNgyEG6aEquzD2Cz0wtN8,66590
|
|
9
9
|
compshare_cli/insights.py,sha256=0ouShkU_8_XusQG8JttfZBW-cG6GD9YBpB_AbPS5tnU,4819
|
|
10
10
|
compshare_cli/instance_templates.py,sha256=UGDxQ5IChId4hTTDByKEVk594qswMj1r6LIuU9Qty7A,7894
|
|
11
11
|
compshare_cli/location.py,sha256=17hE_AGU3yKYEA5v-5W6HEU61l4K1JZDdgCpbGIM2KE,4324
|
|
12
|
-
compshare_cli/mcp_server.py,sha256=
|
|
12
|
+
compshare_cli/mcp_server.py,sha256=0DwiIXhuYR0XEgjJkUQqakpSUhS-asHCSCJgnR6DYZ4,20234
|
|
13
13
|
compshare_cli/output.py,sha256=uvmmN3yT6jHkfMEo_GmzQTX8qMF2HHgcJ4aEKZcBBps,12525
|
|
14
14
|
compshare_cli/parsing.py,sha256=pn4W_lZY2FBhdUjHUDFAHvA_kgcc1ch6D-7uOfJZ68E,4578
|
|
15
15
|
compshare_cli/remote_jobs.py,sha256=soAPdpJLCG5Hus-ciqQ0f0vYm-4hgl_thz62RWR1wSA,18808
|
|
16
16
|
compshare_cli/runtime.py,sha256=RQ6KRfj814Sx5mPxmXVWs_wOoNqnQI7UbBDJNt4qvo0,508
|
|
17
|
-
compshare_cli/sdk.py,sha256
|
|
17
|
+
compshare_cli/sdk.py,sha256=ioAlFLyUhYQDCzYChcCjXhFVfPRolQRTQcmikqFZ3rk,4456
|
|
18
18
|
compshare_cli/ssh.py,sha256=xKPR7vS4zF8s3_tqKqWAfK9CNXlapE1iYrNJecj5cG8,15621
|
|
19
19
|
compshare_cli/ssh_cache.py,sha256=0Y8x6ewVTKx0R_Uum407udlCPBB-rnonSic92BCoeeA,7357
|
|
20
20
|
compshare_cli/commands/__init__.py,sha256=Rb-d2e6JpWZ5pPUP-TjKMWGtNCwpZCMYc0GulfEXbRs,26
|
|
@@ -23,13 +23,13 @@ compshare_cli/commands/common.py,sha256=BNjn4lunbHMjvo5TsLghR6e9ZYuW1xpGvzrg9C_s
|
|
|
23
23
|
compshare_cli/commands/doctor.py,sha256=JgX9Lg-wvIAql8KkyKKMh51BUyNxqK5ZGlgmBONj1q8,4564
|
|
24
24
|
compshare_cli/commands/feedback.py,sha256=wSoIq-1z_mkRr7w4h_jfWQf492aEyZCUvZcJs2lvNJM,575
|
|
25
25
|
compshare_cli/commands/image.py,sha256=e-3_9FVPOxAyRK-ZLW7L4FSWFUyiM7KyZyPAdABY4ik,22735
|
|
26
|
-
compshare_cli/commands/instance.py,sha256=
|
|
26
|
+
compshare_cli/commands/instance.py,sha256=Ua1BPGntf-JXFZy1rv4GDdi3JlH9CRistaXirKo94j0,113011
|
|
27
27
|
compshare_cli/commands/minimax.py,sha256=ng0X09NcDTidYtA14O9nnJu5wEamvx-HkTmV4ifxeD8,43034
|
|
28
28
|
compshare_cli/commands/storage.py,sha256=eUmX2KWx-aYr3ea6GVHVjffq0-58cjsEzINxLOrspyI,8975
|
|
29
29
|
compshare_cli/commands/team.py,sha256=weVCgFPOoDDl03LWmVGhXNR0BPkUvyOUwUHlxUOWyKY,23651
|
|
30
|
-
compshare_cli-0.5.
|
|
31
|
-
compshare_cli-0.5.
|
|
32
|
-
compshare_cli-0.5.
|
|
33
|
-
compshare_cli-0.5.
|
|
34
|
-
compshare_cli-0.5.
|
|
35
|
-
compshare_cli-0.5.
|
|
30
|
+
compshare_cli-0.5.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
31
|
+
compshare_cli-0.5.3.dist-info/METADATA,sha256=tUR62_UZkvqouu3R7G1w-M7pBjEr4hHckogJ-Hx8jDY,4824
|
|
32
|
+
compshare_cli-0.5.3.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
33
|
+
compshare_cli-0.5.3.dist-info/entry_points.txt,sha256=GGv28Bsp3CfBKbcoG6nr2ceqPWYR_XIk0HxxN02olsU,149
|
|
34
|
+
compshare_cli-0.5.3.dist-info/top_level.txt,sha256=ROBw509DOLNt7Z-xwrArjK066G7s4IH0jTcGiaKyMNw,14
|
|
35
|
+
compshare_cli-0.5.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|