dma-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.
- dma_cli-0.1.0/PKG-INFO +269 -0
- dma_cli-0.1.0/README.md +260 -0
- dma_cli-0.1.0/batch.example.json +16 -0
- dma_cli-0.1.0/config.example.yaml +18 -0
- dma_cli-0.1.0/dma_cli/__init__.py +3 -0
- dma_cli-0.1.0/dma_cli/__main__.py +6 -0
- dma_cli-0.1.0/dma_cli/calc.py +42 -0
- dma_cli-0.1.0/dma_cli/cli.py +148 -0
- dma_cli-0.1.0/dma_cli/client.py +245 -0
- dma_cli-0.1.0/dma_cli/resources.py +251 -0
- dma_cli-0.1.0/dma_cli/state.py +65 -0
- dma_cli-0.1.0/dma_cli/submit.py +673 -0
- dma_cli-0.1.0/dma_cli.egg-info/PKG-INFO +269 -0
- dma_cli-0.1.0/dma_cli.egg-info/SOURCES.txt +22 -0
- dma_cli-0.1.0/dma_cli.egg-info/dependency_links.txt +1 -0
- dma_cli-0.1.0/dma_cli.egg-info/entry_points.txt +2 -0
- dma_cli-0.1.0/dma_cli.egg-info/requires.txt +2 -0
- dma_cli-0.1.0/dma_cli.egg-info/top_level.txt +1 -0
- dma_cli-0.1.0/input/calc.py +42 -0
- dma_cli-0.1.0/input/case1/calc.py +42 -0
- dma_cli-0.1.0/input/case2/calc.py +42 -0
- dma_cli-0.1.0/job.example.json +13 -0
- dma_cli-0.1.0/pyproject.toml +25 -0
- dma_cli-0.1.0/setup.cfg +4 -0
dma_cli-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dma-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: DMA 任务提交命令行工具
|
|
5
|
+
Requires-Python: >=3.8
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: requests
|
|
8
|
+
Requires-Dist: pyyaml
|
|
9
|
+
|
|
10
|
+
# DMA CLI —— 任务提交工具
|
|
11
|
+
|
|
12
|
+
深度挖掘(DMA,`https://szc.test.dp.tech`)网页外的命令行提交工具,用于提交单个或批量任务。
|
|
13
|
+
与压测无关,只借用压测脚本里已验证的接口形态,不改动任何压测内容。
|
|
14
|
+
|
|
15
|
+
> **术语**:本工具的 `image`(镜像)即网页上的「软件目录」,底层接口为 `/softwares/deep-mining`,
|
|
16
|
+
> snapshot 用 `softwareId`/`softwareVersionId`。容器镜像接口(image/public|private)不参与 job 提交,但 `image list` 合并展示供参考。
|
|
17
|
+
|
|
18
|
+
## 安装
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# 从 PyPI 安装
|
|
22
|
+
pip install dma-cli
|
|
23
|
+
dma --help
|
|
24
|
+
|
|
25
|
+
# 从源码安装
|
|
26
|
+
cd tools/dma-cli
|
|
27
|
+
pip install .
|
|
28
|
+
|
|
29
|
+
# 方式二:本地开发模式(可直接修改代码调试)
|
|
30
|
+
cd tools/dma-cli
|
|
31
|
+
pip install -e .
|
|
32
|
+
|
|
33
|
+
# 安装后 dma 命令即可全局使用
|
|
34
|
+
dma --help
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 配置
|
|
38
|
+
|
|
39
|
+
PyPI 安装同时包含配置模板和 `input/` 样例,位于当前 Python 环境的 `share/dma-cli/`。
|
|
40
|
+
可在空的工作目录中运行以下命令,将模板和样例复制到当前目录:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
python - <<'PY'
|
|
44
|
+
import shutil
|
|
45
|
+
import sysconfig
|
|
46
|
+
from pathlib import Path
|
|
47
|
+
|
|
48
|
+
examples = Path(sysconfig.get_path("data")) / "share" / "dma-cli"
|
|
49
|
+
for name in ("config.example.yaml", "job.example.json", "batch.example.json"):
|
|
50
|
+
shutil.copy2(examples / name, name)
|
|
51
|
+
shutil.copytree(examples / "input", "input")
|
|
52
|
+
PY
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
复制模板并填写:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
cp config.example.yaml config.yaml
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`config.yaml` 关键项:
|
|
62
|
+
|
|
63
|
+
```yaml
|
|
64
|
+
base_url: https://szc.test.dp.tech
|
|
65
|
+
auth:
|
|
66
|
+
email: "" # 验证码登录邮箱(留空则必须填 token)
|
|
67
|
+
captcha: "952754" # 固定验证码(测试环境)
|
|
68
|
+
token: "" # 直接配 token(优先于 email 登录)
|
|
69
|
+
uexid: "" # 留空从 JWT 自动解析为 fe_<userId>
|
|
70
|
+
user_id: "" # 留空从 JWT 自动解析
|
|
71
|
+
defaults:
|
|
72
|
+
biz_platform: 2
|
|
73
|
+
name_prefix: "cli-job"
|
|
74
|
+
max_run_time: 15
|
|
75
|
+
max_run_time_unit: d
|
|
76
|
+
concurrency: 5
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**配置优先级**:CLI 参数 > 环境变量(`DMA_BASE_URL` / `DMA_TOKEN`)> `config.yaml` > 内置默认。
|
|
80
|
+
当前项目持久化于 `~/.dma_cli/session.json`,由 `project use` 写入、`submit` 读取。
|
|
81
|
+
机型与镜像不持久化,每次通过参数或 JSON 配置文件传入。
|
|
82
|
+
|
|
83
|
+
**安全**:`config.yaml` 与 `~/.dma_cli/` 不入库(仅提交 `config.example.yaml`),禁止提交真实 JWT。
|
|
84
|
+
|
|
85
|
+
## 入口
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# 方式一:如果您已经执行了 pip install .,则可以全局直接使用:
|
|
89
|
+
dma <cmd> ...
|
|
90
|
+
|
|
91
|
+
# 方式二:如果您未安装,可以直接通过 python 入口模块运行:
|
|
92
|
+
python -m dma_cli <cmd> ...
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
所有命令支持 `-h`:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
dma --help
|
|
99
|
+
dma job submit --help
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## 命令
|
|
103
|
+
|
|
104
|
+
### login —— 验证码登录
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
dma login
|
|
108
|
+
dma login --email you@example.com
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
解析 JWT 缓存 `token` / `user_id` / `uexid` 到 `~/.dma_cli/credentials.json`。也可跳过登录,直接在 `config.yaml` 填 `token`。
|
|
112
|
+
|
|
113
|
+
### whoami —— 查看当前状态
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
dma whoami
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
显示 base_url、当前用户、当前项目。
|
|
120
|
+
|
|
121
|
+
### project —— 项目管理
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
dma project list # 列 projectId | name
|
|
125
|
+
dma project use 3948 # 设为当前项目
|
|
126
|
+
dma project current # 显示当前项目
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### sku —— 机型查询
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
dma sku list --kind cpu # 列 skuId|skuName|cpu|memory|gpuModel|gpuNum|hasStock
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
> 仅查询参考,不持久化。提交任务时通过 `--machine_type` 参数传入。
|
|
136
|
+
|
|
137
|
+
### image —— 镜像查询
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
dma image list # 列出镜像(公共+私有合并,含 url 列)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
> 仅查询参考,不持久化。输出 `url` 列可直接填入 `--image_address`。
|
|
144
|
+
|
|
145
|
+
### job submit —— 提交任务
|
|
146
|
+
|
|
147
|
+
提交任务,支持两种入参方式:
|
|
148
|
+
|
|
149
|
+
**方式一:JSON 配置文件**
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
dma job submit -i job.example.json
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**方式二:CLI 参数**
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
dma job submit \
|
|
159
|
+
--machine_type c2_m2_cpu \
|
|
160
|
+
--image_address ubuntu:22.04-py3.10-terminal-20260916 \
|
|
161
|
+
--project_id 3283 \
|
|
162
|
+
--command "python calc.py" \
|
|
163
|
+
--job_name my-job
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
**完整参数列表**:
|
|
167
|
+
|
|
168
|
+
| 参数 | 缩写 | 说明 |
|
|
169
|
+
|---|---|---|
|
|
170
|
+
| `--config_file` | `-i` | JSON 配置文件路径 |
|
|
171
|
+
| `--input_directory` | — | 输入文件目录 |
|
|
172
|
+
| `--project_id` | — | 项目 ID(0=用当前选择) |
|
|
173
|
+
| `--job_name` | `-n` | 任务名称 |
|
|
174
|
+
| `--image_address` | `-m` | 镜像地址(自动匹配) |
|
|
175
|
+
| `--machine_type` | `-t` | 机器类型名(自动匹配) |
|
|
176
|
+
| `--command` | `-c` | 执行命令 |
|
|
177
|
+
| `--max_run_time` | — | 最大运行时间(分钟) |
|
|
178
|
+
| `--nnode` | — | 节点数 |
|
|
179
|
+
| `--count` | — | 批量提交任务数 |
|
|
180
|
+
| `--concurrency` | — | 批量并发数 |
|
|
181
|
+
| `--batch_file` | — | 批量任务 JSON 数组文件 |
|
|
182
|
+
| `--batch_input_dir` | — | 批量目录扫描路径 |
|
|
183
|
+
| `--dry_run` | — | 只打印 snapshot body |
|
|
184
|
+
| `--poll` | — | 提交后轮询状态 |
|
|
185
|
+
|
|
186
|
+
## 批量提交
|
|
187
|
+
|
|
188
|
+
### 方式一:--count(相同参数)
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
dma job submit \
|
|
192
|
+
--machine_type c2_m2_cpu \
|
|
193
|
+
--image_address ubuntu:22.04-py3.10-terminal-20260916 \
|
|
194
|
+
--count 10 \
|
|
195
|
+
--concurrency 5
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### 方式二:--batch_file(差异化配置)
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
# batch.json 格式:
|
|
202
|
+
# [
|
|
203
|
+
# {"job_name": "job-001", "machine_type": "c2_m2_cpu", ...},
|
|
204
|
+
# {"job_name": "job-002", "machine_type": "c4_m8_cpu", ...}
|
|
205
|
+
# ]
|
|
206
|
+
|
|
207
|
+
dma job submit --batch_file batch.json --concurrency 3
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### 方式三:--batch_input_dir(目录扫描)
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
# 每个子目录作为一个任务的输入
|
|
214
|
+
dma job submit \
|
|
215
|
+
--batch_input_dir ./inputs \
|
|
216
|
+
--machine_type c2_m2_cpu \
|
|
217
|
+
--image_address ubuntu:22.04-py3.10-terminal-20260916 \
|
|
218
|
+
--concurrency 5
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## 典型流程
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
# 1. 配置
|
|
225
|
+
cp config.example.yaml config.yaml
|
|
226
|
+
# 编辑 config.yaml 填入 token
|
|
227
|
+
|
|
228
|
+
# 2. 查看状态
|
|
229
|
+
dma whoami
|
|
230
|
+
|
|
231
|
+
# 3. 切换项目
|
|
232
|
+
dma project list
|
|
233
|
+
dma project use 3948
|
|
234
|
+
|
|
235
|
+
# 4. 查询机型和镜像
|
|
236
|
+
dma sku list --kind cpu
|
|
237
|
+
dma image list
|
|
238
|
+
|
|
239
|
+
# 5. 提交任务
|
|
240
|
+
dma job submit -i job.example.json
|
|
241
|
+
|
|
242
|
+
# 6. 批量提交
|
|
243
|
+
dma job submit --batch_file batch.json
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## 文件结构
|
|
247
|
+
|
|
248
|
+
```
|
|
249
|
+
tools/dma-cli/
|
|
250
|
+
├── README.md # 本文档
|
|
251
|
+
├── pyproject.toml # 打包配置
|
|
252
|
+
├── requirements.txt # requests, pyyaml
|
|
253
|
+
├── config.example.yaml # 配置模板
|
|
254
|
+
├── job.example.json # 任务配置示例
|
|
255
|
+
├── batch.example.json # 批量任务示例
|
|
256
|
+
└── dma_cli/ # Python 包目录
|
|
257
|
+
├── __init__.py
|
|
258
|
+
├── cli.py # 命令行入口
|
|
259
|
+
├── client.py # API 客户端
|
|
260
|
+
├── state.py # 状态管理
|
|
261
|
+
├── resources.py # 资源查询
|
|
262
|
+
├── submit.py # 任务提交
|
|
263
|
+
└── calc.py # 默认任务脚本
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
## 不在范围
|
|
267
|
+
|
|
268
|
+
- 不做多用户 / 不改压测脚本
|
|
269
|
+
- 不做分布式压测
|
dma_cli-0.1.0/README.md
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# DMA CLI —— 任务提交工具
|
|
2
|
+
|
|
3
|
+
深度挖掘(DMA,`https://szc.test.dp.tech`)网页外的命令行提交工具,用于提交单个或批量任务。
|
|
4
|
+
与压测无关,只借用压测脚本里已验证的接口形态,不改动任何压测内容。
|
|
5
|
+
|
|
6
|
+
> **术语**:本工具的 `image`(镜像)即网页上的「软件目录」,底层接口为 `/softwares/deep-mining`,
|
|
7
|
+
> snapshot 用 `softwareId`/`softwareVersionId`。容器镜像接口(image/public|private)不参与 job 提交,但 `image list` 合并展示供参考。
|
|
8
|
+
|
|
9
|
+
## 安装
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# 从 PyPI 安装
|
|
13
|
+
pip install dma-cli
|
|
14
|
+
dma --help
|
|
15
|
+
|
|
16
|
+
# 从源码安装
|
|
17
|
+
cd tools/dma-cli
|
|
18
|
+
pip install .
|
|
19
|
+
|
|
20
|
+
# 方式二:本地开发模式(可直接修改代码调试)
|
|
21
|
+
cd tools/dma-cli
|
|
22
|
+
pip install -e .
|
|
23
|
+
|
|
24
|
+
# 安装后 dma 命令即可全局使用
|
|
25
|
+
dma --help
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## 配置
|
|
29
|
+
|
|
30
|
+
PyPI 安装同时包含配置模板和 `input/` 样例,位于当前 Python 环境的 `share/dma-cli/`。
|
|
31
|
+
可在空的工作目录中运行以下命令,将模板和样例复制到当前目录:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
python - <<'PY'
|
|
35
|
+
import shutil
|
|
36
|
+
import sysconfig
|
|
37
|
+
from pathlib import Path
|
|
38
|
+
|
|
39
|
+
examples = Path(sysconfig.get_path("data")) / "share" / "dma-cli"
|
|
40
|
+
for name in ("config.example.yaml", "job.example.json", "batch.example.json"):
|
|
41
|
+
shutil.copy2(examples / name, name)
|
|
42
|
+
shutil.copytree(examples / "input", "input")
|
|
43
|
+
PY
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
复制模板并填写:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
cp config.example.yaml config.yaml
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`config.yaml` 关键项:
|
|
53
|
+
|
|
54
|
+
```yaml
|
|
55
|
+
base_url: https://szc.test.dp.tech
|
|
56
|
+
auth:
|
|
57
|
+
email: "" # 验证码登录邮箱(留空则必须填 token)
|
|
58
|
+
captcha: "952754" # 固定验证码(测试环境)
|
|
59
|
+
token: "" # 直接配 token(优先于 email 登录)
|
|
60
|
+
uexid: "" # 留空从 JWT 自动解析为 fe_<userId>
|
|
61
|
+
user_id: "" # 留空从 JWT 自动解析
|
|
62
|
+
defaults:
|
|
63
|
+
biz_platform: 2
|
|
64
|
+
name_prefix: "cli-job"
|
|
65
|
+
max_run_time: 15
|
|
66
|
+
max_run_time_unit: d
|
|
67
|
+
concurrency: 5
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**配置优先级**:CLI 参数 > 环境变量(`DMA_BASE_URL` / `DMA_TOKEN`)> `config.yaml` > 内置默认。
|
|
71
|
+
当前项目持久化于 `~/.dma_cli/session.json`,由 `project use` 写入、`submit` 读取。
|
|
72
|
+
机型与镜像不持久化,每次通过参数或 JSON 配置文件传入。
|
|
73
|
+
|
|
74
|
+
**安全**:`config.yaml` 与 `~/.dma_cli/` 不入库(仅提交 `config.example.yaml`),禁止提交真实 JWT。
|
|
75
|
+
|
|
76
|
+
## 入口
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
# 方式一:如果您已经执行了 pip install .,则可以全局直接使用:
|
|
80
|
+
dma <cmd> ...
|
|
81
|
+
|
|
82
|
+
# 方式二:如果您未安装,可以直接通过 python 入口模块运行:
|
|
83
|
+
python -m dma_cli <cmd> ...
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
所有命令支持 `-h`:
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
dma --help
|
|
90
|
+
dma job submit --help
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## 命令
|
|
94
|
+
|
|
95
|
+
### login —— 验证码登录
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
dma login
|
|
99
|
+
dma login --email you@example.com
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
解析 JWT 缓存 `token` / `user_id` / `uexid` 到 `~/.dma_cli/credentials.json`。也可跳过登录,直接在 `config.yaml` 填 `token`。
|
|
103
|
+
|
|
104
|
+
### whoami —— 查看当前状态
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
dma whoami
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
显示 base_url、当前用户、当前项目。
|
|
111
|
+
|
|
112
|
+
### project —— 项目管理
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
dma project list # 列 projectId | name
|
|
116
|
+
dma project use 3948 # 设为当前项目
|
|
117
|
+
dma project current # 显示当前项目
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### sku —— 机型查询
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
dma sku list --kind cpu # 列 skuId|skuName|cpu|memory|gpuModel|gpuNum|hasStock
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
> 仅查询参考,不持久化。提交任务时通过 `--machine_type` 参数传入。
|
|
127
|
+
|
|
128
|
+
### image —— 镜像查询
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
dma image list # 列出镜像(公共+私有合并,含 url 列)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
> 仅查询参考,不持久化。输出 `url` 列可直接填入 `--image_address`。
|
|
135
|
+
|
|
136
|
+
### job submit —— 提交任务
|
|
137
|
+
|
|
138
|
+
提交任务,支持两种入参方式:
|
|
139
|
+
|
|
140
|
+
**方式一:JSON 配置文件**
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
dma job submit -i job.example.json
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
**方式二:CLI 参数**
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
dma job submit \
|
|
150
|
+
--machine_type c2_m2_cpu \
|
|
151
|
+
--image_address ubuntu:22.04-py3.10-terminal-20260916 \
|
|
152
|
+
--project_id 3283 \
|
|
153
|
+
--command "python calc.py" \
|
|
154
|
+
--job_name my-job
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**完整参数列表**:
|
|
158
|
+
|
|
159
|
+
| 参数 | 缩写 | 说明 |
|
|
160
|
+
|---|---|---|
|
|
161
|
+
| `--config_file` | `-i` | JSON 配置文件路径 |
|
|
162
|
+
| `--input_directory` | — | 输入文件目录 |
|
|
163
|
+
| `--project_id` | — | 项目 ID(0=用当前选择) |
|
|
164
|
+
| `--job_name` | `-n` | 任务名称 |
|
|
165
|
+
| `--image_address` | `-m` | 镜像地址(自动匹配) |
|
|
166
|
+
| `--machine_type` | `-t` | 机器类型名(自动匹配) |
|
|
167
|
+
| `--command` | `-c` | 执行命令 |
|
|
168
|
+
| `--max_run_time` | — | 最大运行时间(分钟) |
|
|
169
|
+
| `--nnode` | — | 节点数 |
|
|
170
|
+
| `--count` | — | 批量提交任务数 |
|
|
171
|
+
| `--concurrency` | — | 批量并发数 |
|
|
172
|
+
| `--batch_file` | — | 批量任务 JSON 数组文件 |
|
|
173
|
+
| `--batch_input_dir` | — | 批量目录扫描路径 |
|
|
174
|
+
| `--dry_run` | — | 只打印 snapshot body |
|
|
175
|
+
| `--poll` | — | 提交后轮询状态 |
|
|
176
|
+
|
|
177
|
+
## 批量提交
|
|
178
|
+
|
|
179
|
+
### 方式一:--count(相同参数)
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
dma job submit \
|
|
183
|
+
--machine_type c2_m2_cpu \
|
|
184
|
+
--image_address ubuntu:22.04-py3.10-terminal-20260916 \
|
|
185
|
+
--count 10 \
|
|
186
|
+
--concurrency 5
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### 方式二:--batch_file(差异化配置)
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
# batch.json 格式:
|
|
193
|
+
# [
|
|
194
|
+
# {"job_name": "job-001", "machine_type": "c2_m2_cpu", ...},
|
|
195
|
+
# {"job_name": "job-002", "machine_type": "c4_m8_cpu", ...}
|
|
196
|
+
# ]
|
|
197
|
+
|
|
198
|
+
dma job submit --batch_file batch.json --concurrency 3
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### 方式三:--batch_input_dir(目录扫描)
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
# 每个子目录作为一个任务的输入
|
|
205
|
+
dma job submit \
|
|
206
|
+
--batch_input_dir ./inputs \
|
|
207
|
+
--machine_type c2_m2_cpu \
|
|
208
|
+
--image_address ubuntu:22.04-py3.10-terminal-20260916 \
|
|
209
|
+
--concurrency 5
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## 典型流程
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
# 1. 配置
|
|
216
|
+
cp config.example.yaml config.yaml
|
|
217
|
+
# 编辑 config.yaml 填入 token
|
|
218
|
+
|
|
219
|
+
# 2. 查看状态
|
|
220
|
+
dma whoami
|
|
221
|
+
|
|
222
|
+
# 3. 切换项目
|
|
223
|
+
dma project list
|
|
224
|
+
dma project use 3948
|
|
225
|
+
|
|
226
|
+
# 4. 查询机型和镜像
|
|
227
|
+
dma sku list --kind cpu
|
|
228
|
+
dma image list
|
|
229
|
+
|
|
230
|
+
# 5. 提交任务
|
|
231
|
+
dma job submit -i job.example.json
|
|
232
|
+
|
|
233
|
+
# 6. 批量提交
|
|
234
|
+
dma job submit --batch_file batch.json
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## 文件结构
|
|
238
|
+
|
|
239
|
+
```
|
|
240
|
+
tools/dma-cli/
|
|
241
|
+
├── README.md # 本文档
|
|
242
|
+
├── pyproject.toml # 打包配置
|
|
243
|
+
├── requirements.txt # requests, pyyaml
|
|
244
|
+
├── config.example.yaml # 配置模板
|
|
245
|
+
├── job.example.json # 任务配置示例
|
|
246
|
+
├── batch.example.json # 批量任务示例
|
|
247
|
+
└── dma_cli/ # Python 包目录
|
|
248
|
+
├── __init__.py
|
|
249
|
+
├── cli.py # 命令行入口
|
|
250
|
+
├── client.py # API 客户端
|
|
251
|
+
├── state.py # 状态管理
|
|
252
|
+
├── resources.py # 资源查询
|
|
253
|
+
├── submit.py # 任务提交
|
|
254
|
+
└── calc.py # 默认任务脚本
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## 不在范围
|
|
258
|
+
|
|
259
|
+
- 不做多用户 / 不改压测脚本
|
|
260
|
+
- 不做分布式压测
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"job_name": "cli-job-case1",
|
|
4
|
+
"machine_type": "c2_m2_cpu",
|
|
5
|
+
"image_address": "ubuntu:22.04-py3.10-terminal-20260916",
|
|
6
|
+
"input_directory": "./input/case1",
|
|
7
|
+
"command": "python calc.py"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"job_name": "cli-job-case2",
|
|
11
|
+
"machine_type": "c2_m2_cpu",
|
|
12
|
+
"image_address": "ubuntu:22.04-py3.10-terminal-20260916",
|
|
13
|
+
"input_directory": "./input/case2",
|
|
14
|
+
"command": "python calc.py"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# DMA CLI 配置模板 —— 复制为 config.yaml 后填写。
|
|
2
|
+
# 安全:禁止把含真实 token 的 config.yaml 提交到代码仓库(已在 .gitignore 排除)。
|
|
3
|
+
base_url: https://szc.test.dp.tech
|
|
4
|
+
|
|
5
|
+
auth:
|
|
6
|
+
email: "" # 验证码登录邮箱(留空则必须填 token)
|
|
7
|
+
captcha: "952754" # 固定验证码(测试环境)
|
|
8
|
+
token: "" # 直接配 token(优先于 email 登录,留空走 email)
|
|
9
|
+
uexid: "" # 留空则从 JWT 自动解析为 fe_<userId>
|
|
10
|
+
user_id: "" # 留空则从 JWT 自动解析
|
|
11
|
+
|
|
12
|
+
defaults:
|
|
13
|
+
biz_platform: 2
|
|
14
|
+
name_prefix: "cli-job"
|
|
15
|
+
cmd: "python calc.py"
|
|
16
|
+
max_run_time: 15
|
|
17
|
+
max_run_time_unit: d
|
|
18
|
+
concurrency: 5
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""内置默认任务脚本。
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
import argparse
|
|
5
|
+
import time
|
|
6
|
+
import sys
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def main():
|
|
10
|
+
parser = argparse.ArgumentParser()
|
|
11
|
+
parser.add_argument("--num1", type=float, default=1)
|
|
12
|
+
parser.add_argument("--operator", choices=["+", "-"], default="+")
|
|
13
|
+
parser.add_argument("--num2", type=float, default=1)
|
|
14
|
+
args = parser.parse_args()
|
|
15
|
+
|
|
16
|
+
# 打开 run.log 文件并将 print 输出重定向追加至日志
|
|
17
|
+
with open("run.log", "a", encoding="utf-8") as f:
|
|
18
|
+
f.write(f"--- 任务启动时间: {time.strftime('%Y-%m-%d %H:%M:%S')} ---\n")
|
|
19
|
+
f.flush()
|
|
20
|
+
|
|
21
|
+
total_seconds = 10 * 60
|
|
22
|
+
interval = 5
|
|
23
|
+
elapsed = 0
|
|
24
|
+
while elapsed < total_seconds:
|
|
25
|
+
msg = "我大概运行10分钟,你可以先检查其他功能\n"
|
|
26
|
+
sys.stdout.write(msg)
|
|
27
|
+
sys.stdout.flush()
|
|
28
|
+
f.write(msg)
|
|
29
|
+
f.flush()
|
|
30
|
+
time.sleep(interval)
|
|
31
|
+
elapsed += interval
|
|
32
|
+
|
|
33
|
+
result = args.num1 + args.num2 if args.operator == "+" else args.num1 - args.num2
|
|
34
|
+
res_msg = f"计算结果: {args.num1} {args.operator} {args.num2} = {result}\n"
|
|
35
|
+
sys.stdout.write(res_msg)
|
|
36
|
+
sys.stdout.flush()
|
|
37
|
+
f.write(res_msg)
|
|
38
|
+
f.flush()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
main()
|