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 CHANGED
@@ -1,3 +1,3 @@
1
1
  """CompShare command-line client."""
2
2
 
3
- __version__ = "0.5.2"
3
+ __version__ = "0.5.3"
compshare_cli/actions.py CHANGED
@@ -113,7 +113,6 @@ UNAVAILABLE_ACTIONS = frozenset(
113
113
  {
114
114
  "AddFavoriteImage",
115
115
  "DescribeFavoriteImages",
116
- "GetCompShareInstanceMonitor",
117
116
  "GetSoftwareURL",
118
117
  "RemoveFavoriteImage",
119
118
  }
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
- "Get instance monitoring data (coming soon).": "获取实例监控数据(待上线)。",
363
- "Instance monitoring is coming soon.": "实例监控功能待上线。",
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
  ),
@@ -23,6 +23,7 @@ _READ_COMMANDS = {
23
23
  ("instance", "families"),
24
24
  ("instance", "list"),
25
25
  ("instance", "show"),
26
+ ("instance", "monitor"),
26
27
  ("instance", "wait"),
27
28
  ("instance", "price"),
28
29
  ("instance", "resize-price"),
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
- response = self._service.transport.send(
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
- content_type = str(response.headers.get("Content-Type", "")).lower()
64
- if "json" in content_type:
88
+ def _json_response(self, action: str, response: Response) -> Dict[str, Any]:
89
+ try:
65
90
  data = response.json() or {}
66
- if int(data.get("RetCode", -1)) != 0:
67
- error = ucloud_exc.RetCodeException(
68
- action=action,
69
- code=int(data.get("RetCode", 0)),
70
- message=data.get("Message", ""),
71
- request_uuid=response.request_uuid,
72
- )
73
- for handler in self._service.middleware.exception_handlers:
74
- handler(error)
75
- raise error
76
- return response.content, {str(key): str(value) for key, value in response.headers.items()}
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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: compshare-cli
3
- Version: 0.5.2
3
+ Version: 0.5.3
4
4
  Summary: Command-line client for CompShare GPU compute and MiniMax H3
5
5
  Author: CompShare
6
6
  License-Expression: Apache-2.0
@@ -1,20 +1,20 @@
1
- compshare_cli/__init__.py,sha256=vkxM7_X9GIc6Ffyh9YEIwMWKJbI3JnPE6RcQ576ciS4,60
1
+ compshare_cli/__init__.py,sha256=dFbD4eJkqYWkk4nUZvNLCRpjKYnpXCoaLGlgBARFFyk,60
2
2
  compshare_cli/__main__.py,sha256=ftkB0R9jLZejzr717131qktgfFhTe12noFeGqQsVZMc,74
3
- compshare_cli/actions.py,sha256=DWIXXrUHru_mT6DNnrV5VhkfRhgyBGsu73uQk-7o8Mc,3633
4
- compshare_cli/api.py,sha256=S4hUvkbG0l7qUqQaAf7trX29GteF1yVnOGgjcJj99jc,9286
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=Iole4nwgRceA02BzQYGbJn4aV9aAKxBdui37yOc2RX8,66832
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=9c9ALWetTur0SQJSZ76usuW7ilpir7C4bPcKFQyGGZo,20205
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=-E10iHykUx0DKbNksZ6hRaFfegV93bk5yU4nsL0WTsw,2937
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=CO9TJdL0FQWup_j0B3Pv6ubbh5JJa3UdPgwJcqmY2_s,110049
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.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
31
- compshare_cli-0.5.2.dist-info/METADATA,sha256=TGjMQ3rCHVQHxX_Q3rSoLA--CDHJyXARFr8kh9mQXME,4824
32
- compshare_cli-0.5.2.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
33
- compshare_cli-0.5.2.dist-info/entry_points.txt,sha256=GGv28Bsp3CfBKbcoG6nr2ceqPWYR_XIk0HxxN02olsU,149
34
- compshare_cli-0.5.2.dist-info/top_level.txt,sha256=ROBw509DOLNt7Z-xwrArjK066G7s4IH0jTcGiaKyMNw,14
35
- compshare_cli-0.5.2.dist-info/RECORD,,
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,,