compshare-cli 0.1.0__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.
Files changed (35) hide show
  1. compshare_cli-0.1.0/PKG-INFO +283 -0
  2. compshare_cli-0.1.0/README.md +266 -0
  3. compshare_cli-0.1.0/pyproject.toml +45 -0
  4. compshare_cli-0.1.0/setup.cfg +4 -0
  5. compshare_cli-0.1.0/src/compshare_cli/__init__.py +3 -0
  6. compshare_cli-0.1.0/src/compshare_cli/__main__.py +4 -0
  7. compshare_cli-0.1.0/src/compshare_cli/actions.py +71 -0
  8. compshare_cli-0.1.0/src/compshare_cli/api.py +127 -0
  9. compshare_cli-0.1.0/src/compshare_cli/cli.py +219 -0
  10. compshare_cli-0.1.0/src/compshare_cli/commands/__init__.py +1 -0
  11. compshare_cli-0.1.0/src/compshare_cli/commands/common.py +57 -0
  12. compshare_cli-0.1.0/src/compshare_cli/commands/image.py +528 -0
  13. compshare_cli-0.1.0/src/compshare_cli/commands/instance.py +1493 -0
  14. compshare_cli-0.1.0/src/compshare_cli/commands/storage.py +276 -0
  15. compshare_cli-0.1.0/src/compshare_cli/config.py +127 -0
  16. compshare_cli-0.1.0/src/compshare_cli/errors.py +10 -0
  17. compshare_cli-0.1.0/src/compshare_cli/i18n.py +506 -0
  18. compshare_cli-0.1.0/src/compshare_cli/location.py +91 -0
  19. compshare_cli-0.1.0/src/compshare_cli/output.py +124 -0
  20. compshare_cli-0.1.0/src/compshare_cli/parsing.py +93 -0
  21. compshare_cli-0.1.0/src/compshare_cli/runtime.py +34 -0
  22. compshare_cli-0.1.0/src/compshare_cli/sdk.py +27 -0
  23. compshare_cli-0.1.0/src/compshare_cli.egg-info/PKG-INFO +283 -0
  24. compshare_cli-0.1.0/src/compshare_cli.egg-info/SOURCES.txt +33 -0
  25. compshare_cli-0.1.0/src/compshare_cli.egg-info/dependency_links.txt +1 -0
  26. compshare_cli-0.1.0/src/compshare_cli.egg-info/entry_points.txt +2 -0
  27. compshare_cli-0.1.0/src/compshare_cli.egg-info/requires.txt +11 -0
  28. compshare_cli-0.1.0/src/compshare_cli.egg-info/top_level.txt +1 -0
  29. compshare_cli-0.1.0/tests/test_actions.py +47 -0
  30. compshare_cli-0.1.0/tests/test_cli.py +571 -0
  31. compshare_cli-0.1.0/tests/test_config.py +80 -0
  32. compshare_cli-0.1.0/tests/test_location.py +33 -0
  33. compshare_cli-0.1.0/tests/test_output.py +22 -0
  34. compshare_cli-0.1.0/tests/test_parsing.py +34 -0
  35. compshare_cli-0.1.0/tests/test_sdk.py +38 -0
@@ -0,0 +1,283 @@
1
+ Metadata-Version: 2.4
2
+ Name: compshare-cli
3
+ Version: 0.1.0
4
+ Summary: Command-line client for CompShare GPU compute
5
+ Author: CompShare
6
+ License: Apache-2.0
7
+ Requires-Python: >=3.9
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: rich<15,>=13
10
+ Requires-Dist: typer<1,>=0.12
11
+ Requires-Dist: ucloud-sdk-python3<0.12,>=0.11.103
12
+ Requires-Dist: urllib3<2,>=1.26.18; python_version < "3.10" and platform_system == "Darwin"
13
+ Provides-Extra: dev
14
+ Requires-Dist: pytest<10,>=8; extra == "dev"
15
+ Requires-Dist: pytest-cov<8,>=5; extra == "dev"
16
+ Requires-Dist: ruff<1,>=0.6; extra == "dev"
17
+
18
+ # CompShare CLI
19
+
20
+ 在终端中管理优云智算 GPU 实例、实例镜像、云盘与 US3 挂载。
21
+
22
+ 第一阶段覆盖 `compshare-docs` 中三个公开 API 目录的 51 个 Action:
23
+
24
+ - GPU 实例:27 个 Action
25
+ - 实例镜像:17 个 Action
26
+ - 磁盘与云存储:7 个 Action
27
+
28
+ CLI 使用官方 [`ucloud-sdk-python3`](https://github.com/ucloud/ucloud-sdk-python3) 完成鉴权、参数编码、请求传输与重试。调用层使用 SDK 的通用 `invoke` 接口,因为 CompShare 的公开 API 更新可能早于 SDK 的生成式请求模型;这样不会静默丢弃新参数。
29
+
30
+ ## 安装
31
+
32
+ 要求 Python 3.9 或更高版本。
33
+
34
+ ```bash
35
+ python -m pip install .
36
+ compshare --help
37
+ ```
38
+
39
+ 开发环境:
40
+
41
+ ```bash
42
+ python -m venv .venv
43
+ .venv/bin/python -m pip install --upgrade pip
44
+ .venv/bin/python -m pip install -e '.[dev]'
45
+ .venv/bin/pytest
46
+ ```
47
+
48
+ ## 配置
49
+
50
+ 交互式保存 API 密钥:
51
+
52
+ ```bash
53
+ compshare config --name production
54
+ ```
55
+
56
+ 每个凭证 profile 只保存名称、公钥和私钥,不绑定地域、可用区或项目。配置默认保存到 `~/.config/compshare/config.json`,目录权限为 `0700`,文件权限为 `0600`。支持多个凭证 profile:
57
+
58
+ ```bash
59
+ compshare --profile production instance list
60
+ compshare config list
61
+ compshare config use production
62
+ compshare config delete staging
63
+ compshare config path
64
+ ```
65
+
66
+ 也可以完全通过环境变量运行:
67
+
68
+ ```bash
69
+ export COMPSHARE_PUBLIC_KEY='...'
70
+ export COMPSHARE_PRIVATE_KEY='...'
71
+ export COMPSHARE_REGION='cn-wlcb'
72
+ export COMPSHARE_ZONE='cn-wlcb-01'
73
+ ```
74
+
75
+ 其中公私钥属于凭证;Region 和 Zone 只是请求位置。支持的环境变量还有 `COMPSHARE_PROFILE` 和 `COMPSHARE_CONFIG_FILE`。
76
+
77
+ ## 全局参数
78
+
79
+ ```text
80
+ --profile 选择凭证 profile
81
+ --json 输出适合脚本处理的 JSON
82
+ ```
83
+
84
+ 地域和可用区是资源参数,不是全局选项。它们会出现在真正需要位置的子命令后面:
85
+
86
+ ```bash
87
+ compshare instance list --region cn-sh2
88
+ compshare instance create --zone cn-sh2-02
89
+ ```
90
+
91
+ 实例和已挂载云盘的生命周期命令会根据资源 ID 自动查找 Region 和 Zone。列表命令未指定 `--region` 时会聚合所有支持地域。
92
+
93
+ `ProjectId` 不是账户凭证的一部分。定时关机会通过 `GetProjectList` 自动选择默认项目;只有需要覆盖自动选择结果时才传 `--project-id`。
94
+
95
+ `--json` 和 `--profile` 是全局选项,必须放在子命令前:
96
+
97
+ ```bash
98
+ compshare --json instance list
99
+ compshare --profile production instance list
100
+ ```
101
+
102
+ 成功时 JSON 模式直接输出 API 响应;失败时输出 `{"ok":false,"error":"..."}` 并返回非零退出码。实例密码和 FileBrowser 密码保留 API 原值,API 私钥仍会脱敏。
103
+
104
+ CLI 默认显示中文帮助描述。使用一级命令持久切换语言,配置会写入本地配置文件,但不属于任何凭证 profile:
105
+
106
+ ```bash
107
+ compshare --help
108
+ compshare lang en
109
+ compshare instance create --help
110
+ compshare lang zh
111
+ compshare lang # 查看当前语言
112
+ ```
113
+
114
+ 也可以通过 `COMPSHARE_LANG=en` 覆盖当前终端会话的帮助语言。当前版本不安装 Shell completion,仅提供 `-h/--help`。
115
+
116
+ ## 实例
117
+
118
+ ### 查规格和库存
119
+
120
+ 不带镜像时,`search` 展示合法的 GPU、CPU 和内存组合:
121
+
122
+ ```bash
123
+ compshare instance search
124
+ compshare instance search --gpu 4090 --gpu A100
125
+ ```
126
+
127
+ 库存不是机型的固定属性。它还取决于镜像、磁盘、计费方式和 CPU 平台,因此检查真实库存时需要指定镜像:
128
+
129
+ ```bash
130
+ compshare instance search \
131
+ --gpu 4090 \
132
+ --image compshareImage-xxxx \
133
+ --disk 100GiB \
134
+ --disk-type CLOUD_SSD \
135
+ --charge Postpay \
136
+ --available
137
+ ```
138
+
139
+ 该命令先调用 `DescribeAvailableCompShareInstanceTypes` 获取合法规格,再按匹配的 GPU 型号调用 `CheckCompShareResourceCapacity`。`--available` 不会用 Describe 接口的状态冒充库存。
140
+
141
+ ### 创建
142
+
143
+ 直接运行不带规格参数的命令会进入交互向导:
144
+
145
+ ```bash
146
+ compshare instance create
147
+ ```
148
+
149
+ 向导会依次读取可用区、GPU 机型和镜像;选择计费方式与磁盘后,调用真实库存接口,只展示当前可创建的 GPU、CPU、内存组合。最后查询完整价格并要求确认。镜像来源支持 `platform`、`custom`、`community` 和 `shared`。
150
+
151
+ 也可以预先指定部分选项,让向导只补齐剩余内容:
152
+
153
+ ```bash
154
+ compshare instance create --gpu 3080Ti --image-source platform
155
+ ```
156
+
157
+ 自动化场景使用完整参数模式:
158
+
159
+ ```bash
160
+ compshare instance create \
161
+ --gpu 4090 \
162
+ --count 1 \
163
+ --cpu 16 \
164
+ --memory 64GiB \
165
+ --image compshareImage-xxxx \
166
+ --disk 100GiB \
167
+ --data-disk 200GiB:CLOUD_SSD \
168
+ --charge Postpay
169
+ ```
170
+
171
+ 创建前会依次检查目标组合库存和价格,得到确认后才创建。自动化中可使用 `--yes` 跳过最终确认。`--json` 不会启动交互向导,因此必须同时提供 `--gpu`、`--count`、`--cpu`、`--memory` 和 `--image`。
172
+
173
+ 可以先检查库存、价格和最终请求,但不创建资源:
174
+
175
+ ```bash
176
+ compshare instance create ... --dry-run --json
177
+ ```
178
+
179
+ 人类交互终端默认等待创建和生命周期操作进入稳定状态,脚本使用的 JSON 模式默认提交后立即返回。可以用 `--wait`、`--no-wait` 和 `--timeout` 显式控制;创建镜像也支持相同选项。
180
+
181
+ ### 命令概览
182
+
183
+ ```text
184
+ compshare instance search
185
+ compshare instance zones
186
+ compshare instance families
187
+ compshare instance list
188
+ compshare instance show INSTANCE
189
+ compshare instance create
190
+ compshare instance start INSTANCE
191
+ compshare instance stop INSTANCE
192
+ compshare instance reboot INSTANCE
193
+ compshare instance delete INSTANCE
194
+ compshare instance rename INSTANCE NAME
195
+ compshare instance password INSTANCE
196
+ compshare instance reinstall INSTANCE
197
+ compshare instance resize INSTANCE
198
+ compshare instance price
199
+ compshare instance resize-price INSTANCE
200
+ compshare instance billing
201
+ compshare instance refund INSTANCE...
202
+ compshare instance monitor [INSTANCE...]
203
+ compshare instance charge INSTANCE --to Month
204
+ compshare instance network
205
+ compshare instance models
206
+ compshare instance ssh INSTANCE
207
+ compshare instance ports list
208
+ compshare instance ports update INSTANCE
209
+ compshare instance schedule set INSTANCE --at 2h
210
+ compshare instance schedule cancel INSTANCE
211
+ compshare instance software list
212
+ compshare instance software url INSTANCE JupyterLab
213
+ ```
214
+
215
+ `ssh` 会在连接前显示 API 返回的实例密码;使用 `ssh INSTANCE --print` 时会同时输出 SSH 命令和密码。
216
+
217
+ `resize` 明确区分计算规格调整和磁盘扩容,两者不能放在同一次请求中。执行删除、关机、重启、重装、改配等高影响操作时默认要求确认。
218
+
219
+ `instance list` 支持 `--name`、`--status`、`--gpu` 和 `--billing` 组合筛选。`instance show` 默认显示重点字段卡片,使用 `--json` 时保留完整 API 响应。旧命令 `upgrade-price` 仍兼容,但帮助中统一使用 `resize-price`。
220
+
221
+ 生产实测中 `monitor` 和 `software url` 对应接口当前不可用,CLI 会在帮助和 API 错误提示中明确标记;命令仍保留,便于服务端恢复后直接使用。
222
+
223
+ ## 镜像
224
+
225
+ 用 `--source` 在不同镜像来源间切换:
226
+
227
+ ```bash
228
+ compshare image list --source platform
229
+ compshare image list --source custom
230
+ compshare image list --source community --query pytorch --tag LLM
231
+ compshare image list --source shared
232
+ compshare image list --source published
233
+ compshare image list --source user --user 12345
234
+ ```
235
+
236
+ 完整命令:
237
+
238
+ ```text
239
+ compshare image list
240
+ compshare image show IMAGE
241
+ compshare image create --instance INSTANCE --name NAME
242
+ compshare image progress IMAGE
243
+ compshare image update IMAGE
244
+ compshare image delete IMAGE
245
+ compshare image shares IMAGE
246
+ compshare image share IMAGE ACCOUNT...
247
+ compshare image unshare IMAGE ACCOUNT...
248
+ compshare image publish IMAGE --version v1.0
249
+ compshare image favorite IMAGE
250
+ compshare image unfavorite IMAGE
251
+ compshare image tags
252
+ ```
253
+
254
+ 社区镜像列表支持名称、作者、模糊查询、标签、免费/付费、官方/非官方、自启动和排序筛选。封面文件由 CLI 转成 Base64,README 文件按 UTF-8 读取。
255
+
256
+ 创建镜像时可使用 `--wait` 跟踪 `GetCompShareImageCreateProgress`,或继续使用独立的 `image progress` 命令。
257
+
258
+ ## 磁盘与云存储
259
+
260
+ ```text
261
+ compshare storage disk list
262
+ compshare storage disk create --instance INSTANCE --size 100GiB --name DATA
263
+ compshare storage disk attach DISK --instance INSTANCE
264
+ compshare storage disk detach DISK --instance INSTANCE --device /dev/vdb
265
+ compshare storage disk price DISK --instance INSTANCE --size 200GiB
266
+ compshare storage disk resize DISK --size 200GiB
267
+ compshare storage disk delete DISK
268
+ compshare storage us3 attach --instance INSTANCE
269
+ ```
270
+
271
+ `storage us3 attach` 覆盖 CompShare 的 US3 挂载 Action。对象上传、下载、Bucket 管理继续使用独立的 `us3cli`,避免在本 CLI 中复制另一套成熟工具的能力。
272
+
273
+ 云盘删除会对“仍在卸载中”的暂时性错误自动重试;其他已知生产错误会附带可执行的处理建议。
274
+
275
+ ## 开发校验
276
+
277
+ ```bash
278
+ .venv/bin/ruff check src tests
279
+ .venv/bin/ruff format --check src tests
280
+ .venv/bin/pytest
281
+ ```
282
+
283
+ 公开 Action 清单维护在 `compshare_cli.actions` 中,测试会校验 27/17/7 的领域数量以及命令实现是否包含全部 51 个 Action。
@@ -0,0 +1,266 @@
1
+ # CompShare CLI
2
+
3
+ 在终端中管理优云智算 GPU 实例、实例镜像、云盘与 US3 挂载。
4
+
5
+ 第一阶段覆盖 `compshare-docs` 中三个公开 API 目录的 51 个 Action:
6
+
7
+ - GPU 实例:27 个 Action
8
+ - 实例镜像:17 个 Action
9
+ - 磁盘与云存储:7 个 Action
10
+
11
+ CLI 使用官方 [`ucloud-sdk-python3`](https://github.com/ucloud/ucloud-sdk-python3) 完成鉴权、参数编码、请求传输与重试。调用层使用 SDK 的通用 `invoke` 接口,因为 CompShare 的公开 API 更新可能早于 SDK 的生成式请求模型;这样不会静默丢弃新参数。
12
+
13
+ ## 安装
14
+
15
+ 要求 Python 3.9 或更高版本。
16
+
17
+ ```bash
18
+ python -m pip install .
19
+ compshare --help
20
+ ```
21
+
22
+ 开发环境:
23
+
24
+ ```bash
25
+ python -m venv .venv
26
+ .venv/bin/python -m pip install --upgrade pip
27
+ .venv/bin/python -m pip install -e '.[dev]'
28
+ .venv/bin/pytest
29
+ ```
30
+
31
+ ## 配置
32
+
33
+ 交互式保存 API 密钥:
34
+
35
+ ```bash
36
+ compshare config --name production
37
+ ```
38
+
39
+ 每个凭证 profile 只保存名称、公钥和私钥,不绑定地域、可用区或项目。配置默认保存到 `~/.config/compshare/config.json`,目录权限为 `0700`,文件权限为 `0600`。支持多个凭证 profile:
40
+
41
+ ```bash
42
+ compshare --profile production instance list
43
+ compshare config list
44
+ compshare config use production
45
+ compshare config delete staging
46
+ compshare config path
47
+ ```
48
+
49
+ 也可以完全通过环境变量运行:
50
+
51
+ ```bash
52
+ export COMPSHARE_PUBLIC_KEY='...'
53
+ export COMPSHARE_PRIVATE_KEY='...'
54
+ export COMPSHARE_REGION='cn-wlcb'
55
+ export COMPSHARE_ZONE='cn-wlcb-01'
56
+ ```
57
+
58
+ 其中公私钥属于凭证;Region 和 Zone 只是请求位置。支持的环境变量还有 `COMPSHARE_PROFILE` 和 `COMPSHARE_CONFIG_FILE`。
59
+
60
+ ## 全局参数
61
+
62
+ ```text
63
+ --profile 选择凭证 profile
64
+ --json 输出适合脚本处理的 JSON
65
+ ```
66
+
67
+ 地域和可用区是资源参数,不是全局选项。它们会出现在真正需要位置的子命令后面:
68
+
69
+ ```bash
70
+ compshare instance list --region cn-sh2
71
+ compshare instance create --zone cn-sh2-02
72
+ ```
73
+
74
+ 实例和已挂载云盘的生命周期命令会根据资源 ID 自动查找 Region 和 Zone。列表命令未指定 `--region` 时会聚合所有支持地域。
75
+
76
+ `ProjectId` 不是账户凭证的一部分。定时关机会通过 `GetProjectList` 自动选择默认项目;只有需要覆盖自动选择结果时才传 `--project-id`。
77
+
78
+ `--json` 和 `--profile` 是全局选项,必须放在子命令前:
79
+
80
+ ```bash
81
+ compshare --json instance list
82
+ compshare --profile production instance list
83
+ ```
84
+
85
+ 成功时 JSON 模式直接输出 API 响应;失败时输出 `{"ok":false,"error":"..."}` 并返回非零退出码。实例密码和 FileBrowser 密码保留 API 原值,API 私钥仍会脱敏。
86
+
87
+ CLI 默认显示中文帮助描述。使用一级命令持久切换语言,配置会写入本地配置文件,但不属于任何凭证 profile:
88
+
89
+ ```bash
90
+ compshare --help
91
+ compshare lang en
92
+ compshare instance create --help
93
+ compshare lang zh
94
+ compshare lang # 查看当前语言
95
+ ```
96
+
97
+ 也可以通过 `COMPSHARE_LANG=en` 覆盖当前终端会话的帮助语言。当前版本不安装 Shell completion,仅提供 `-h/--help`。
98
+
99
+ ## 实例
100
+
101
+ ### 查规格和库存
102
+
103
+ 不带镜像时,`search` 展示合法的 GPU、CPU 和内存组合:
104
+
105
+ ```bash
106
+ compshare instance search
107
+ compshare instance search --gpu 4090 --gpu A100
108
+ ```
109
+
110
+ 库存不是机型的固定属性。它还取决于镜像、磁盘、计费方式和 CPU 平台,因此检查真实库存时需要指定镜像:
111
+
112
+ ```bash
113
+ compshare instance search \
114
+ --gpu 4090 \
115
+ --image compshareImage-xxxx \
116
+ --disk 100GiB \
117
+ --disk-type CLOUD_SSD \
118
+ --charge Postpay \
119
+ --available
120
+ ```
121
+
122
+ 该命令先调用 `DescribeAvailableCompShareInstanceTypes` 获取合法规格,再按匹配的 GPU 型号调用 `CheckCompShareResourceCapacity`。`--available` 不会用 Describe 接口的状态冒充库存。
123
+
124
+ ### 创建
125
+
126
+ 直接运行不带规格参数的命令会进入交互向导:
127
+
128
+ ```bash
129
+ compshare instance create
130
+ ```
131
+
132
+ 向导会依次读取可用区、GPU 机型和镜像;选择计费方式与磁盘后,调用真实库存接口,只展示当前可创建的 GPU、CPU、内存组合。最后查询完整价格并要求确认。镜像来源支持 `platform`、`custom`、`community` 和 `shared`。
133
+
134
+ 也可以预先指定部分选项,让向导只补齐剩余内容:
135
+
136
+ ```bash
137
+ compshare instance create --gpu 3080Ti --image-source platform
138
+ ```
139
+
140
+ 自动化场景使用完整参数模式:
141
+
142
+ ```bash
143
+ compshare instance create \
144
+ --gpu 4090 \
145
+ --count 1 \
146
+ --cpu 16 \
147
+ --memory 64GiB \
148
+ --image compshareImage-xxxx \
149
+ --disk 100GiB \
150
+ --data-disk 200GiB:CLOUD_SSD \
151
+ --charge Postpay
152
+ ```
153
+
154
+ 创建前会依次检查目标组合库存和价格,得到确认后才创建。自动化中可使用 `--yes` 跳过最终确认。`--json` 不会启动交互向导,因此必须同时提供 `--gpu`、`--count`、`--cpu`、`--memory` 和 `--image`。
155
+
156
+ 可以先检查库存、价格和最终请求,但不创建资源:
157
+
158
+ ```bash
159
+ compshare instance create ... --dry-run --json
160
+ ```
161
+
162
+ 人类交互终端默认等待创建和生命周期操作进入稳定状态,脚本使用的 JSON 模式默认提交后立即返回。可以用 `--wait`、`--no-wait` 和 `--timeout` 显式控制;创建镜像也支持相同选项。
163
+
164
+ ### 命令概览
165
+
166
+ ```text
167
+ compshare instance search
168
+ compshare instance zones
169
+ compshare instance families
170
+ compshare instance list
171
+ compshare instance show INSTANCE
172
+ compshare instance create
173
+ compshare instance start INSTANCE
174
+ compshare instance stop INSTANCE
175
+ compshare instance reboot INSTANCE
176
+ compshare instance delete INSTANCE
177
+ compshare instance rename INSTANCE NAME
178
+ compshare instance password INSTANCE
179
+ compshare instance reinstall INSTANCE
180
+ compshare instance resize INSTANCE
181
+ compshare instance price
182
+ compshare instance resize-price INSTANCE
183
+ compshare instance billing
184
+ compshare instance refund INSTANCE...
185
+ compshare instance monitor [INSTANCE...]
186
+ compshare instance charge INSTANCE --to Month
187
+ compshare instance network
188
+ compshare instance models
189
+ compshare instance ssh INSTANCE
190
+ compshare instance ports list
191
+ compshare instance ports update INSTANCE
192
+ compshare instance schedule set INSTANCE --at 2h
193
+ compshare instance schedule cancel INSTANCE
194
+ compshare instance software list
195
+ compshare instance software url INSTANCE JupyterLab
196
+ ```
197
+
198
+ `ssh` 会在连接前显示 API 返回的实例密码;使用 `ssh INSTANCE --print` 时会同时输出 SSH 命令和密码。
199
+
200
+ `resize` 明确区分计算规格调整和磁盘扩容,两者不能放在同一次请求中。执行删除、关机、重启、重装、改配等高影响操作时默认要求确认。
201
+
202
+ `instance list` 支持 `--name`、`--status`、`--gpu` 和 `--billing` 组合筛选。`instance show` 默认显示重点字段卡片,使用 `--json` 时保留完整 API 响应。旧命令 `upgrade-price` 仍兼容,但帮助中统一使用 `resize-price`。
203
+
204
+ 生产实测中 `monitor` 和 `software url` 对应接口当前不可用,CLI 会在帮助和 API 错误提示中明确标记;命令仍保留,便于服务端恢复后直接使用。
205
+
206
+ ## 镜像
207
+
208
+ 用 `--source` 在不同镜像来源间切换:
209
+
210
+ ```bash
211
+ compshare image list --source platform
212
+ compshare image list --source custom
213
+ compshare image list --source community --query pytorch --tag LLM
214
+ compshare image list --source shared
215
+ compshare image list --source published
216
+ compshare image list --source user --user 12345
217
+ ```
218
+
219
+ 完整命令:
220
+
221
+ ```text
222
+ compshare image list
223
+ compshare image show IMAGE
224
+ compshare image create --instance INSTANCE --name NAME
225
+ compshare image progress IMAGE
226
+ compshare image update IMAGE
227
+ compshare image delete IMAGE
228
+ compshare image shares IMAGE
229
+ compshare image share IMAGE ACCOUNT...
230
+ compshare image unshare IMAGE ACCOUNT...
231
+ compshare image publish IMAGE --version v1.0
232
+ compshare image favorite IMAGE
233
+ compshare image unfavorite IMAGE
234
+ compshare image tags
235
+ ```
236
+
237
+ 社区镜像列表支持名称、作者、模糊查询、标签、免费/付费、官方/非官方、自启动和排序筛选。封面文件由 CLI 转成 Base64,README 文件按 UTF-8 读取。
238
+
239
+ 创建镜像时可使用 `--wait` 跟踪 `GetCompShareImageCreateProgress`,或继续使用独立的 `image progress` 命令。
240
+
241
+ ## 磁盘与云存储
242
+
243
+ ```text
244
+ compshare storage disk list
245
+ compshare storage disk create --instance INSTANCE --size 100GiB --name DATA
246
+ compshare storage disk attach DISK --instance INSTANCE
247
+ compshare storage disk detach DISK --instance INSTANCE --device /dev/vdb
248
+ compshare storage disk price DISK --instance INSTANCE --size 200GiB
249
+ compshare storage disk resize DISK --size 200GiB
250
+ compshare storage disk delete DISK
251
+ compshare storage us3 attach --instance INSTANCE
252
+ ```
253
+
254
+ `storage us3 attach` 覆盖 CompShare 的 US3 挂载 Action。对象上传、下载、Bucket 管理继续使用独立的 `us3cli`,避免在本 CLI 中复制另一套成熟工具的能力。
255
+
256
+ 云盘删除会对“仍在卸载中”的暂时性错误自动重试;其他已知生产错误会附带可执行的处理建议。
257
+
258
+ ## 开发校验
259
+
260
+ ```bash
261
+ .venv/bin/ruff check src tests
262
+ .venv/bin/ruff format --check src tests
263
+ .venv/bin/pytest
264
+ ```
265
+
266
+ 公开 Action 清单维护在 `compshare_cli.actions` 中,测试会校验 27/17/7 的领域数量以及命令实现是否包含全部 51 个 Action。
@@ -0,0 +1,45 @@
1
+ [build-system]
2
+ requires = ["setuptools>=69"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "compshare-cli"
7
+ version = "0.1.0"
8
+ description = "Command-line client for CompShare GPU compute"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { text = "Apache-2.0" }
12
+ authors = [
13
+ { name = "CompShare" },
14
+ ]
15
+ dependencies = [
16
+ "rich>=13,<15",
17
+ "typer>=0.12,<1",
18
+ "ucloud-sdk-python3>=0.11.103,<0.12",
19
+ "urllib3>=1.26.18,<2; python_version < '3.10' and platform_system == 'Darwin'",
20
+ ]
21
+
22
+ [project.optional-dependencies]
23
+ dev = [
24
+ "pytest>=8,<10",
25
+ "pytest-cov>=5,<8",
26
+ "ruff>=0.6,<1",
27
+ ]
28
+
29
+ [project.scripts]
30
+ compshare = "compshare_cli.cli:main"
31
+
32
+ [tool.setuptools.packages.find]
33
+ where = ["src"]
34
+
35
+ [tool.pytest.ini_options]
36
+ addopts = "-q"
37
+ testpaths = ["tests"]
38
+
39
+ [tool.ruff]
40
+ line-length = 100
41
+ target-version = "py39"
42
+
43
+ [tool.ruff.lint]
44
+ select = ["E", "F", "I", "B"]
45
+ ignore = ["B008"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ """CompShare command-line client."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1,4 @@
1
+ from compshare_cli.cli import main
2
+
3
+ if __name__ == "__main__":
4
+ main()
@@ -0,0 +1,71 @@
1
+ """Public CompShare API actions covered by the first CLI release."""
2
+
3
+ INSTANCE_ACTIONS = frozenset(
4
+ {
5
+ "CheckCompShareNetOptimizer",
6
+ "CheckCompShareResourceCapacity",
7
+ "CreateCompShareInstance",
8
+ "DeleteCompShareStopScheduler",
9
+ "DescribeAvailableCompShareInstanceTypes",
10
+ "DescribeCompShareInstance",
11
+ "DescribeCompShareMachineTypeFamilies",
12
+ "DescribeCompShareSoftwarePort",
13
+ "DescribeCompShareSupportZone",
14
+ "DescribeModelRepositoryModels",
15
+ "GetCompShareInstanceMonitor",
16
+ "GetCompShareInstancePrice",
17
+ "GetCompShareInstanceUpgradePrice",
18
+ "GetCompShareInstanceUserPrice",
19
+ "GetCompShareRefundPrice",
20
+ "GetSoftwareURL",
21
+ "ModifyCompShareInstanceName",
22
+ "RebootCompShareInstance",
23
+ "ReinstallCompShareInstance",
24
+ "ResetCompShareInstancePassword",
25
+ "ResizeCompShareInstance",
26
+ "StartCompShareInstance",
27
+ "StopCompShareInstance",
28
+ "SwitchChargeType",
29
+ "TerminateCompShareInstance",
30
+ "UpdateCompShareInstancePorts",
31
+ "UpdateCompShareStopScheduler",
32
+ }
33
+ )
34
+
35
+ IMAGE_ACTIONS = frozenset(
36
+ {
37
+ "AddFavoriteImage",
38
+ "CreateCompShareCustomImage",
39
+ "DescribeCommunityImages",
40
+ "DescribeCompShareCustomImages",
41
+ "DescribeCompShareImages",
42
+ "DescribeCompShareImageShareAccounts",
43
+ "DescribeCompShareImageTags",
44
+ "DescribeCompShareSharingImages",
45
+ "DescribeSelfCommunityImages",
46
+ "DescribeUserCommunityImages",
47
+ "GetCompShareImageCreateProgress",
48
+ "ModifyCompShareImageShareAccount",
49
+ "PublishCompShareImage",
50
+ "RemoveFavoriteImage",
51
+ "TerminateCompShareCustomImage",
52
+ "UpdateCompShareImage",
53
+ }
54
+ )
55
+
56
+ STORAGE_ACTIONS = frozenset(
57
+ {
58
+ "AttachCompshareDisk",
59
+ "AttachUS3",
60
+ "CreateAndAttachCompshareDisk",
61
+ "DeleteCompshareDisk",
62
+ "DetachCompshareDisk",
63
+ "GetCompShareAttachedDiskUpgradePrice",
64
+ "ResizeCompShareDisk",
65
+ }
66
+ )
67
+
68
+ PUBLIC_ACTIONS = INSTANCE_ACTIONS | IMAGE_ACTIONS | STORAGE_ACTIONS
69
+
70
+ # Documented publicly but unavailable in the production API (RetCode 161).
71
+ UNAVAILABLE_ACTIONS = frozenset({"DescribeFavoriteImages"})