openbayes-cli 0.4.5__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.
- bayes/__init__.py +0 -0
- bayes/client/__init__.py +0 -0
- bayes/client/base.py +20 -0
- bayes/client/dataset_version_client.py +91 -0
- bayes/client/gear_client.py +468 -0
- bayes/client/job_run_client.py +504 -0
- bayes/client/job_upload_client.py +114 -0
- bayes/client/org_client.py +67 -0
- bayes/client/resource_client.py +108 -0
- bayes/client/runtime_client.py +32 -0
- bayes/client/ssh_client.py +66 -0
- bayes/client/status_client.py +14 -0
- bayes/client/user_client.py +58 -0
- bayes/commands/__init__.py +0 -0
- bayes/commands/gear.py +691 -0
- bayes/commands/org.py +100 -0
- bayes/commands/ssh.py +70 -0
- bayes/error.py +9 -0
- bayes/model/__init__.py +0 -0
- bayes/model/dataset_version.py +14 -0
- bayes/model/file/__init__.py +0 -0
- bayes/model/file/data_bindings.py +42 -0
- bayes/model/file/openbayes_data.py +133 -0
- bayes/model/file/openbayes_gear.py +72 -0
- bayes/model/file/openbayes_ignore.py +75 -0
- bayes/model/file/openbayes_yaml.py +180 -0
- bayes/model/file/settings.py +157 -0
- bayes/model/party.py +35 -0
- bayes/model/resource.py +147 -0
- bayes/model/runtime.py +34 -0
- bayes/root.py +170 -0
- bayes/templates/openbayes_zh-Hans.yaml +134 -0
- bayes/templates/openbayesignore.yaml +3 -0
- bayes/usercases/__init__.py +0 -0
- bayes/usercases/archive_usecase.py +79 -0
- bayes/usercases/auth_usecase.py +35 -0
- bayes/usercases/dataset_version_usecase.py +61 -0
- bayes/usercases/disk_usecase.py +98 -0
- bayes/usercases/gear_download_usecese.py +113 -0
- bayes/usercases/gear_logs_usecase.py +44 -0
- bayes/usercases/gear_open_usecase.py +16 -0
- bayes/usercases/gear_run_usecase.py +123 -0
- bayes/usercases/gear_upload_usecase.py +248 -0
- bayes/usercases/gear_usecase.py +301 -0
- bayes/usercases/openbayes_data_usecase.py +73 -0
- bayes/usercases/org_usecase.py +85 -0
- bayes/usercases/resource_usecase.py +74 -0
- bayes/usercases/runtime_usecase.py +58 -0
- bayes/usercases/ssh_usecase.py +110 -0
- bayes/usercases/switch_usercase.py +19 -0
- bayes/utils.py +163 -0
- openbayes_cli-0.4.5.dist-info/METADATA +62 -0
- openbayes_cli-0.4.5.dist-info/RECORD +55 -0
- openbayes_cli-0.4.5.dist-info/WHEEL +4 -0
- openbayes_cli-0.4.5.dist-info/entry_points.txt +3 -0
bayes/commands/gear.py
ADDED
|
@@ -0,0 +1,691 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import time
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Optional, List
|
|
5
|
+
|
|
6
|
+
import typer
|
|
7
|
+
|
|
8
|
+
from bayes.client import job_run_client
|
|
9
|
+
from bayes.model.file.openbayes_gear import OpenBayesGearSettings, FILE_NAME as GEAR_FILE_NAME
|
|
10
|
+
from bayes.model.file.openbayes_yaml import OpenBayesYamlSettings, FILE_NAME, DEFAULT_JOB_RESOURCE, DEFAULT_JOB_RUNTIME
|
|
11
|
+
from bayes.model.file.settings import BayesEnvConfig
|
|
12
|
+
from bayes.model.party import ModeEnum
|
|
13
|
+
from bayes.usercases import auth_usecase, gear_usecase, gear_open_usecase, resource_usecase, runtime_usecase, \
|
|
14
|
+
gear_logs_usecase, gear_download_usecese, gear_run_usecase
|
|
15
|
+
from bayes.utils import Utils
|
|
16
|
+
|
|
17
|
+
app = typer.Typer()
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@app.command()
|
|
21
|
+
def init(ctx: typer.Context, id_or_name: str,
|
|
22
|
+
message: str = typer.Option(None, "-m", "--message", help="容器描述"),
|
|
23
|
+
open: bool = typer.Option(False, "-o", "--open", help="成功初始化容器后,在浏览器打开")):
|
|
24
|
+
"""
|
|
25
|
+
初始化容器
|
|
26
|
+
用法:
|
|
27
|
+
bayes gear init [容器名称 或 容器编码] [选项]
|
|
28
|
+
|
|
29
|
+
可用选项:
|
|
30
|
+
-h, --help 查看 init 的帮助
|
|
31
|
+
-m, --message string [可选] 容器描述
|
|
32
|
+
-o, --open [可选] 成功初始化容器后,在浏览器打开
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
# 检查用户是否已登录
|
|
36
|
+
login = auth_usecase.check_login()
|
|
37
|
+
if not login:
|
|
38
|
+
print("尚未授权,请先登录")
|
|
39
|
+
raise typer.Exit(code=1)
|
|
40
|
+
# 检查现在是处于 组织/用户 状态
|
|
41
|
+
bayes_settings = ctx.obj
|
|
42
|
+
default_env: Optional[BayesEnvConfig] = bayes_settings.default_env
|
|
43
|
+
|
|
44
|
+
party_name = ""
|
|
45
|
+
if auth_usecase.is_working_on_org():
|
|
46
|
+
party_name = default_env.orgName
|
|
47
|
+
print(f"当前正在组织 {party_name} 上进行操作...")
|
|
48
|
+
else:
|
|
49
|
+
party_name = default_env.username
|
|
50
|
+
print(f"当前正在个人账号 {party_name} 上进行操作...")
|
|
51
|
+
|
|
52
|
+
# 获取当前工作目录
|
|
53
|
+
current_path = Path(os.getcwd())
|
|
54
|
+
|
|
55
|
+
# 创建 OpenBayesYamlSettings 去读取 openbayes.yaml ,如果不存在就创建默认的
|
|
56
|
+
OpenBayesYamlSettings(config_path=current_path / FILE_NAME)
|
|
57
|
+
|
|
58
|
+
get_project_tags = ["BUSINESS_CHANNEL_ML"]
|
|
59
|
+
project = gear_usecase.get_project_by_id_or_name(party_name, id_or_name, get_project_tags, 1, 200)
|
|
60
|
+
if project is None:
|
|
61
|
+
create_project_tags = [
|
|
62
|
+
{
|
|
63
|
+
"name": "BUSINESS_CHANNEL_ML"
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
project = gear_usecase.create_project(party_name, id_or_name, message, create_project_tags)
|
|
67
|
+
|
|
68
|
+
gear_usecase.init_project(current_path, project.id, project.name)
|
|
69
|
+
|
|
70
|
+
print("容器初始化成功")
|
|
71
|
+
if open:
|
|
72
|
+
print("正在跳转到浏览器...")
|
|
73
|
+
gear_open_usecase.open_browser(project.get_link_value("frontend"))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@app.command()
|
|
77
|
+
def ls(ctx: typer.Context,
|
|
78
|
+
page: int = typer.Option(1, "-p", "--page", help="跳转页码")):
|
|
79
|
+
"""
|
|
80
|
+
查看所有容器
|
|
81
|
+
用法:
|
|
82
|
+
bayes gear ls [选项]
|
|
83
|
+
|
|
84
|
+
可用选项:
|
|
85
|
+
-h, --help 查看 ls 的帮助
|
|
86
|
+
-p, --page string [可选] 跳转页码
|
|
87
|
+
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
# 检查用户是否已登录
|
|
91
|
+
login = auth_usecase.check_login()
|
|
92
|
+
if not login:
|
|
93
|
+
print("尚未授权,请先登录")
|
|
94
|
+
raise typer.Exit(code=1)
|
|
95
|
+
# 检查现在是处于 组织/用户 状态
|
|
96
|
+
bayes_settings = ctx.obj
|
|
97
|
+
default_env: Optional[BayesEnvConfig] = bayes_settings.default_env
|
|
98
|
+
|
|
99
|
+
party_name = ""
|
|
100
|
+
if auth_usecase.is_working_on_org():
|
|
101
|
+
party_name = default_env.orgName
|
|
102
|
+
print(f"当前正在组织 {party_name} 上进行操作...")
|
|
103
|
+
else:
|
|
104
|
+
party_name = default_env.username
|
|
105
|
+
print(f"当前正在个人账号 {party_name} 上进行操作...")
|
|
106
|
+
|
|
107
|
+
get_projects_tags = ["BUSINESS_CHANNEL_ML"]
|
|
108
|
+
project_data_list = gear_usecase.get_party_projects(party_name, get_projects_tags, page)
|
|
109
|
+
gear_usecase.list_projects_display_table(project_data_list)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@app.command()
|
|
113
|
+
def run(
|
|
114
|
+
ctx: typer.Context,
|
|
115
|
+
mode: ModeEnum = typer.Argument(..., help="task 或 workspace 或 hypertuning", case_sensitive=True, clamp=True),
|
|
116
|
+
data: List[str] = typer.Option([], "-d", "--data", help="绑定数据"),
|
|
117
|
+
env: str = typer.Option("", "-e", "--env", help="选择镜像"),
|
|
118
|
+
resource: str = typer.Option("", "-r", "--resource", help="选择算力"),
|
|
119
|
+
follow: bool = typer.Option(False, "-f", "--follow", help="运行容器的状态跟踪"),
|
|
120
|
+
message: str = typer.Option("", "-m", "--message", help="执行描述"),
|
|
121
|
+
open_browser: bool = typer.Option(False, "-o", "--open", help="成功创建容器后,在浏览器打开"),
|
|
122
|
+
node: int = typer.Option(-1, "-n", "--node", help="指定运行节点数量"),
|
|
123
|
+
extra_args: Optional[List[str]] = typer.Argument(None, help="task command 额外参数")
|
|
124
|
+
):
|
|
125
|
+
"""
|
|
126
|
+
运行容器
|
|
127
|
+
用法:
|
|
128
|
+
bayes gear run [task 或 workspace 或 hypertuning] [选项]
|
|
129
|
+
|
|
130
|
+
可用选项:
|
|
131
|
+
-d, --data strings 绑定数据
|
|
132
|
+
-e, --env string 选择镜像
|
|
133
|
+
-f, --follow [可选] 运行容器的状态跟踪
|
|
134
|
+
-h, --help 查看 run 的帮助
|
|
135
|
+
-m, --message string 执行描述
|
|
136
|
+
-o, --open [可选] 成功创建容器后,在浏览器打开
|
|
137
|
+
-r, --resource string 选择算力
|
|
138
|
+
"""
|
|
139
|
+
# 检查用户是否已登录
|
|
140
|
+
login = auth_usecase.check_login()
|
|
141
|
+
if not login:
|
|
142
|
+
print("尚未授权,请先登录")
|
|
143
|
+
raise typer.Exit(code=1)
|
|
144
|
+
# 检查现在是处于 组织/用户 状态
|
|
145
|
+
bayes_settings = ctx.obj
|
|
146
|
+
default_env: Optional[BayesEnvConfig] = bayes_settings.default_env
|
|
147
|
+
|
|
148
|
+
party_name = ""
|
|
149
|
+
if auth_usecase.is_working_on_org():
|
|
150
|
+
party_name = default_env.orgName
|
|
151
|
+
print(f"当前正在组织 {party_name} 上进行操作...")
|
|
152
|
+
else:
|
|
153
|
+
party_name = default_env.username
|
|
154
|
+
print(f"当前正在个人账号 {party_name} 上进行操作...")
|
|
155
|
+
|
|
156
|
+
# 获得当前路径 去读取 openbayesgear 文件获得 init 的 id(projectId)
|
|
157
|
+
current_path = Path(os.getcwd())
|
|
158
|
+
gear_settings = OpenBayesGearSettings(config_path=current_path / GEAR_FILE_NAME)
|
|
159
|
+
|
|
160
|
+
if gear_settings.configuration is None or not gear_settings.configuration.id:
|
|
161
|
+
print('项目编号不存在,请先使用 "bayes gear init [项目编码 或 项目名称]" 完成初始化')
|
|
162
|
+
raise typer.Exit(code=1)
|
|
163
|
+
pid = gear_settings.configuration.id
|
|
164
|
+
|
|
165
|
+
try:
|
|
166
|
+
yaml_settings = OpenBayesYamlSettings(config_path=current_path / FILE_NAME)
|
|
167
|
+
except Exception as e:
|
|
168
|
+
|
|
169
|
+
print("访问文档可查看示例,文档地址: https://openbayes.com/docs/cli/#创建python-脚本执行")
|
|
170
|
+
raise typer.Exit(code=1)
|
|
171
|
+
|
|
172
|
+
if mode == "":
|
|
173
|
+
print("请先设置 mode")
|
|
174
|
+
raise typer.Exit(code=1)
|
|
175
|
+
|
|
176
|
+
if len(data) == 0 and yaml_settings is not None and yaml_settings.configuration is not None:
|
|
177
|
+
data = yaml_settings.configuration.get_dataset_bindings()
|
|
178
|
+
|
|
179
|
+
if resource == "" and yaml_settings is not None and yaml_settings.configuration is not None:
|
|
180
|
+
resource = yaml_settings.configuration.resource
|
|
181
|
+
|
|
182
|
+
if resource == "":
|
|
183
|
+
resource = DEFAULT_JOB_RESOURCE
|
|
184
|
+
|
|
185
|
+
if env == "" and yaml_settings is not None and yaml_settings.configuration is not None:
|
|
186
|
+
env = yaml_settings.configuration.get_runtime()
|
|
187
|
+
|
|
188
|
+
if env == "":
|
|
189
|
+
env = DEFAULT_JOB_RUNTIME
|
|
190
|
+
|
|
191
|
+
task_command = ""
|
|
192
|
+
if yaml_settings is not None and yaml_settings.configuration is not None:
|
|
193
|
+
task_command = yaml_settings.configuration.command
|
|
194
|
+
|
|
195
|
+
if extra_args:
|
|
196
|
+
extra_command = " ".join(extra_args)
|
|
197
|
+
task_command = f"{task_command} {extra_command}".strip()
|
|
198
|
+
|
|
199
|
+
if mode == ModeEnum.task and task_command == "":
|
|
200
|
+
print("准备创建 task,执行命令不能为空")
|
|
201
|
+
raise typer.Exit(code=1)
|
|
202
|
+
|
|
203
|
+
cid = gear_usecase.upload_code(str(current_path), pid)
|
|
204
|
+
print(f"code id: {cid}")
|
|
205
|
+
|
|
206
|
+
print("正在向服务器请求创建容器...")
|
|
207
|
+
|
|
208
|
+
frontend_value, job_id, err = gear_run_usecase.create(party_name, current_path, "", mode, yaml_settings.configuration,
|
|
209
|
+
data, node, env, resource, cid, task_command, message)
|
|
210
|
+
|
|
211
|
+
if err is not None and frontend_value == "":
|
|
212
|
+
print(f"create err:{err}")
|
|
213
|
+
raise typer.Exit(code=1)
|
|
214
|
+
|
|
215
|
+
print("容器创建成功")
|
|
216
|
+
print(f"create job : {job_id}")
|
|
217
|
+
|
|
218
|
+
if open_browser:
|
|
219
|
+
open_url = Utils.replace_last_id(frontend_value, job_id)
|
|
220
|
+
is_open = gear_open_usecase.open_browser(open_url)
|
|
221
|
+
if is_open:
|
|
222
|
+
print(f"打开网页 {open_url} 可查看容器的详细信息")
|
|
223
|
+
|
|
224
|
+
gear_settings.update_jid(str(current_path), job_id)
|
|
225
|
+
|
|
226
|
+
time.sleep(3)
|
|
227
|
+
|
|
228
|
+
if follow and mode != ModeEnum.hypertuning:
|
|
229
|
+
gear_usecase.follow_status(job_id, party_name, True)
|
|
230
|
+
gear_usecase.print_last_status(job_id, party_name)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
@app.command()
|
|
234
|
+
def status(ctx: typer.Context,
|
|
235
|
+
page: int = typer.Option(1, "-p", "--page", help="跳转页码")):
|
|
236
|
+
"""
|
|
237
|
+
查看容器下的所有任务
|
|
238
|
+
用法:
|
|
239
|
+
bayes gear status [选项]
|
|
240
|
+
|
|
241
|
+
可用选项:
|
|
242
|
+
-h, --help 查看 status 的帮助
|
|
243
|
+
-p, --page string [可选] 跳转页码
|
|
244
|
+
|
|
245
|
+
"""
|
|
246
|
+
login = auth_usecase.check_login()
|
|
247
|
+
if not login:
|
|
248
|
+
print("尚未授权,请先登录")
|
|
249
|
+
raise typer.Exit(code=1)
|
|
250
|
+
# 检查现在是处于 组织/用户 状态
|
|
251
|
+
bayes_settings = ctx.obj
|
|
252
|
+
default_env: Optional[BayesEnvConfig] = bayes_settings.default_env
|
|
253
|
+
|
|
254
|
+
party_name = ""
|
|
255
|
+
if auth_usecase.is_working_on_org():
|
|
256
|
+
party_name = default_env.orgName
|
|
257
|
+
print(f"当前正在组织 {party_name} 上进行操作...")
|
|
258
|
+
else:
|
|
259
|
+
party_name = default_env.username
|
|
260
|
+
print(f"当前正在个人账号 {party_name} 上进行操作...")
|
|
261
|
+
|
|
262
|
+
# 获取当前路径下的 gear 文件中的 projectId,不存在提示信息
|
|
263
|
+
current_path = Path(os.getcwd())
|
|
264
|
+
gear_settings = OpenBayesGearSettings(config_path=current_path / GEAR_FILE_NAME)
|
|
265
|
+
gear_settings.load_from_file()
|
|
266
|
+
if gear_settings.configuration is None or not gear_settings.configuration.id:
|
|
267
|
+
print('项目编号不存在,请先使用 "bayes gear init [项目编码 或 项目名称]" 完成初始化')
|
|
268
|
+
return
|
|
269
|
+
|
|
270
|
+
project_id = gear_settings.configuration.id
|
|
271
|
+
project = gear_usecase.get_project_jobs_by_id(party_name, project_id, page)
|
|
272
|
+
gear_usecase.list_project_jobs_display_table(project)
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
@app.command()
|
|
276
|
+
def restart(ctx: typer.Context,
|
|
277
|
+
id: str,
|
|
278
|
+
data: List[str] = typer.Option([], "-d", "--data", help="绑定数据"),
|
|
279
|
+
env: str = typer.Option("", "-e", "--env", help="选择镜像"),
|
|
280
|
+
resource: str = typer.Option("", "-r", "--resource", help="选择算力"),
|
|
281
|
+
follow: bool = typer.Option(False, "-f", "--follow", help="运行容器的状态跟踪"),
|
|
282
|
+
message: str = typer.Option("", "-m", "--message", help="执行描述"),
|
|
283
|
+
open_browser: bool = typer.Option(False, "-o", "--open", help="成功创建容器后,在浏览器打开"),
|
|
284
|
+
node: int = typer.Option(-1, "-n", "--node", help="指定运行节点数量"),
|
|
285
|
+
extra_args: Optional[List[str]] = typer.Argument(None, help="task command 额外参数")
|
|
286
|
+
):
|
|
287
|
+
"""
|
|
288
|
+
继续执行容器
|
|
289
|
+
用法:
|
|
290
|
+
bayes gear restart [任务编码] [选项]
|
|
291
|
+
|
|
292
|
+
可用选项:
|
|
293
|
+
-d, --data strings 绑定数据
|
|
294
|
+
-e, --env string 选择镜像
|
|
295
|
+
-f, --follow [可选] 继续执行容器的状态跟踪
|
|
296
|
+
-h, --help 查看 restart 的帮助
|
|
297
|
+
-m, --message string 执行描述
|
|
298
|
+
-o, --open [可选] 继续执行容器后,在浏览器打开
|
|
299
|
+
-r, --resource string 选择算力
|
|
300
|
+
|
|
301
|
+
"""
|
|
302
|
+
# 检查用户是否已登录
|
|
303
|
+
login = auth_usecase.check_login()
|
|
304
|
+
if not login:
|
|
305
|
+
print("尚未授权,请先登录")
|
|
306
|
+
raise typer.Exit(code=1)
|
|
307
|
+
# 检查现在是处于 组织/用户 状态
|
|
308
|
+
bayes_settings = ctx.obj
|
|
309
|
+
default_env: Optional[BayesEnvConfig] = bayes_settings.default_env
|
|
310
|
+
|
|
311
|
+
party_name = ""
|
|
312
|
+
if auth_usecase.is_working_on_org():
|
|
313
|
+
party_name = default_env.orgName
|
|
314
|
+
print(f"当前正在组织 {party_name} 上进行操作...")
|
|
315
|
+
else:
|
|
316
|
+
party_name = default_env.username
|
|
317
|
+
print(f"当前正在个人账号 {party_name} 上进行操作...")
|
|
318
|
+
|
|
319
|
+
job = gear_usecase.get_job_by_id(id, party_name)
|
|
320
|
+
if job is None:
|
|
321
|
+
print("请输入正确的任务编码")
|
|
322
|
+
raise typer.Exit(code=1)
|
|
323
|
+
|
|
324
|
+
project_name = job.project.name
|
|
325
|
+
frontend_url = job.get_link_value("frontend")
|
|
326
|
+
open_url = Utils.replace_last_id(frontend_url, job.id)
|
|
327
|
+
|
|
328
|
+
task_command = ""
|
|
329
|
+
if extra_args:
|
|
330
|
+
extra_command = " ".join(extra_args)
|
|
331
|
+
task_command = f"{task_command} {extra_command}".strip()
|
|
332
|
+
|
|
333
|
+
try:
|
|
334
|
+
new_frontend_value, job_id = gear_run_usecase.restart(id, party_name, data, env, resource, task_command, node,
|
|
335
|
+
message)
|
|
336
|
+
except Exception as e:
|
|
337
|
+
print(f"e:{e}")
|
|
338
|
+
print("重启失败")
|
|
339
|
+
if open_url is not None:
|
|
340
|
+
print(f"打开网页 {open_url} 可查看容器 {project_name} 的详细信息")
|
|
341
|
+
raise typer.Exit(code=1)
|
|
342
|
+
|
|
343
|
+
print("容器继续执行...")
|
|
344
|
+
if new_frontend_value is not None:
|
|
345
|
+
new_open_url = Utils.replace_last_id(new_frontend_value, job_id)
|
|
346
|
+
print(f"打开网页 {new_open_url} 可查看容器 {project_name} 的详细信息")
|
|
347
|
+
|
|
348
|
+
if message != "":
|
|
349
|
+
gear_usecase.update_job_description(party_name, job_id, message)
|
|
350
|
+
|
|
351
|
+
if open_browser:
|
|
352
|
+
gear_open_usecase.open_browser(new_open_url)
|
|
353
|
+
|
|
354
|
+
if follow:
|
|
355
|
+
gear_usecase.follow_status(job_id, party_name, True)
|
|
356
|
+
gear_usecase.print_last_status(job_id, party_name)
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
@app.command()
|
|
360
|
+
def stop(ctx: typer.Context,
|
|
361
|
+
id: str = typer.Argument(None, help="指定下载的任务 ID"),
|
|
362
|
+
follow: bool = typer.Option(False, "-f", "--follow", help="停止容器的状态跟踪"),
|
|
363
|
+
open: bool = typer.Option(False, "-o", "--open", help="在浏览器打开正在关闭的容器")):
|
|
364
|
+
"""
|
|
365
|
+
停止容器
|
|
366
|
+
用法:
|
|
367
|
+
bayes gear stop [任务编码] [选项]
|
|
368
|
+
|
|
369
|
+
可用选项:
|
|
370
|
+
-f, --follow [可选] 停止容器的状态跟踪
|
|
371
|
+
-h, --help 查看 stop 的帮助
|
|
372
|
+
-o, --open [可选] 在浏览器打开正在关闭的容器
|
|
373
|
+
"""
|
|
374
|
+
login = auth_usecase.check_login()
|
|
375
|
+
if not login:
|
|
376
|
+
print("尚未授权,请先登录")
|
|
377
|
+
raise typer.Exit(code=1)
|
|
378
|
+
# 检查现在是处于 组织/用户 状态
|
|
379
|
+
bayes_settings = ctx.obj
|
|
380
|
+
default_env: Optional[BayesEnvConfig] = bayes_settings.default_env
|
|
381
|
+
|
|
382
|
+
party_name = ""
|
|
383
|
+
if auth_usecase.is_working_on_org():
|
|
384
|
+
party_name = default_env.orgName
|
|
385
|
+
print(f"当前正在组织 {party_name} 上进行操作...")
|
|
386
|
+
else:
|
|
387
|
+
party_name = default_env.username
|
|
388
|
+
print(f"当前正在个人账号 {party_name} 上进行操作...")
|
|
389
|
+
|
|
390
|
+
if id is None:
|
|
391
|
+
# 获得当前路径 去读取 openbayesgear 文件获得 init 的 id(projectId)
|
|
392
|
+
current_path = Path(os.getcwd())
|
|
393
|
+
gear_settings = OpenBayesGearSettings(config_path=current_path / GEAR_FILE_NAME)
|
|
394
|
+
if gear_settings.configuration is None or not gear_settings.configuration.id or not gear_settings.configuration.jid:
|
|
395
|
+
print('项目编号不存在,请先使用 "bayes gear run [task 或 workspace 或 hypertuning] [选项]" 完成项目创建')
|
|
396
|
+
raise typer.Exit(code=1)
|
|
397
|
+
else:
|
|
398
|
+
id = gear_settings.configuration.jid
|
|
399
|
+
|
|
400
|
+
job = gear_usecase.stopJob(id, party_name)
|
|
401
|
+
print("同步数据并关闭容器")
|
|
402
|
+
frontend = job.get_link_value("frontend")
|
|
403
|
+
link_value = Utils.replace_last_id(frontend, job.id)
|
|
404
|
+
if link_value is not None:
|
|
405
|
+
print(f"打开网页 {link_value} 可查看容器 {job.project.name} 的详细信息")
|
|
406
|
+
if open:
|
|
407
|
+
gear_open_usecase.open_browser(link_value)
|
|
408
|
+
|
|
409
|
+
if follow:
|
|
410
|
+
gear_usecase.follow_status(id, party_name, True)
|
|
411
|
+
gear_usecase.print_last_status(id, party_name)
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
@app.command()
|
|
415
|
+
def bindings(ctx: typer.Context):
|
|
416
|
+
"""
|
|
417
|
+
查看运行容器可绑定的数据
|
|
418
|
+
用法:
|
|
419
|
+
bayes gear bindings [选项]
|
|
420
|
+
|
|
421
|
+
可用选项:
|
|
422
|
+
-h, --help 查看 bindings 的帮助
|
|
423
|
+
-q, --query string 输入关键字查询可绑定的数据
|
|
424
|
+
"""
|
|
425
|
+
# 检查用户是否已登录
|
|
426
|
+
login = auth_usecase.check_login()
|
|
427
|
+
if not login:
|
|
428
|
+
print("尚未授权,请先登录")
|
|
429
|
+
raise typer.Exit(code=1)
|
|
430
|
+
# 检查现在是处于 组织/用户 状态
|
|
431
|
+
bayes_settings = ctx.obj
|
|
432
|
+
default_env: Optional[BayesEnvConfig] = bayes_settings.default_env
|
|
433
|
+
|
|
434
|
+
party_name = ""
|
|
435
|
+
if auth_usecase.is_working_on_org():
|
|
436
|
+
party_name = default_env.orgName
|
|
437
|
+
print(f"当前正在组织 {party_name} 上进行操作...")
|
|
438
|
+
else:
|
|
439
|
+
party_name = default_env.username
|
|
440
|
+
print(f"当前正在个人账号 {party_name} 上进行操作...")
|
|
441
|
+
|
|
442
|
+
binding_datasets = gear_usecase.list_binding_datasets(party_name, "--data")
|
|
443
|
+
gear_usecase.list_binding_datasets_display_table(binding_datasets)
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
@app.command()
|
|
447
|
+
def download(ctx: typer.Context,
|
|
448
|
+
id: str = typer.Argument(None, help="指定下载的任务 ID"),
|
|
449
|
+
download_from: str = typer.Option("", "--from", "-f", help="指定下载的子路径,不填则下载整个输出"),
|
|
450
|
+
download_target: str = typer.Option("", "--target", "-t", help="本地存在位置,不填则使用当前路径"),
|
|
451
|
+
unarchive: bool = typer.Option(False, "--unarchive", "-u", help="是否自动解压压缩包并删除源文件")):
|
|
452
|
+
"""
|
|
453
|
+
下载容器输出
|
|
454
|
+
用法:
|
|
455
|
+
bayes gear download [任务编码] [选项]
|
|
456
|
+
|
|
457
|
+
可用选项:
|
|
458
|
+
-f, --from string [可选] 指定下载的子路径,不填则下载整个输出
|
|
459
|
+
-h, --help 查看 download 的帮助
|
|
460
|
+
-t, --target string [可选] 本地存在位置,不填则使用当前路径
|
|
461
|
+
-u, --unarchive [可选] 是否自动解压压缩包并删除源文件
|
|
462
|
+
"""
|
|
463
|
+
# 检查用户是否已登录
|
|
464
|
+
login = auth_usecase.check_login()
|
|
465
|
+
if not login:
|
|
466
|
+
print("尚未授权,请先登录")
|
|
467
|
+
raise typer.Exit(code=1)
|
|
468
|
+
# 检查现在是处于 组织/用户 状态
|
|
469
|
+
bayes_settings = ctx.obj
|
|
470
|
+
default_env: Optional[BayesEnvConfig] = bayes_settings.default_env
|
|
471
|
+
|
|
472
|
+
party_name = ""
|
|
473
|
+
if auth_usecase.is_working_on_org():
|
|
474
|
+
party_name = default_env.orgName
|
|
475
|
+
print(f"当前正在组织 {party_name} 上进行操作...")
|
|
476
|
+
else:
|
|
477
|
+
party_name = default_env.username
|
|
478
|
+
print(f"当前正在个人账号 {party_name} 上进行操作...")
|
|
479
|
+
|
|
480
|
+
target = gear_usecase.get_download_target(download_target)
|
|
481
|
+
|
|
482
|
+
id = gear_usecase.get_jobId_from_curPath(id)
|
|
483
|
+
|
|
484
|
+
if unarchive and not gear_download_usecese.is_folder_empty(target):
|
|
485
|
+
print(f"下载无法完成,{target} 已存在,且不是一个空文件夹,请选择其他路径后重试")
|
|
486
|
+
raise typer.Exit(code=1)
|
|
487
|
+
|
|
488
|
+
payload = gear_download_usecese.get_download_url(id, party_name, download_from)
|
|
489
|
+
if payload is None:
|
|
490
|
+
print(f"{download_from} 文件或路径不存在,请检查你所填写的参数")
|
|
491
|
+
raise typer.Exit(code=1)
|
|
492
|
+
|
|
493
|
+
filename = gear_download_usecese.get_target_file_name(target, payload)
|
|
494
|
+
if gear_download_usecese.is_file_exist(filename) and not gear_download_usecese.is_continuing(filename):
|
|
495
|
+
print("已终止下载")
|
|
496
|
+
raise typer.Exit(code=1)
|
|
497
|
+
|
|
498
|
+
zip, err = gear_download_usecese.download(target, payload)
|
|
499
|
+
if err is not None:
|
|
500
|
+
print("下载失败,请重试")
|
|
501
|
+
raise typer.Exit(code=1)
|
|
502
|
+
|
|
503
|
+
if zip != "" and unarchive:
|
|
504
|
+
new_zip = gear_download_usecese.rename_zip(zip, payload.get_file_name())
|
|
505
|
+
time.sleep(1)
|
|
506
|
+
print("正在解压中,请稍候")
|
|
507
|
+
if new_zip != zip:
|
|
508
|
+
print(f"压缩包被重命名为 {new_zip}")
|
|
509
|
+
|
|
510
|
+
err = gear_download_usecese.unzip(new_zip, target)
|
|
511
|
+
if err is not None:
|
|
512
|
+
print("自动解压无法完成")
|
|
513
|
+
raise typer.Exit(code=1)
|
|
514
|
+
|
|
515
|
+
print(f"解压完成,文件保存在 {target}")
|
|
516
|
+
print(f"压缩包 {new_zip} 已删除")
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
@app.command()
|
|
520
|
+
def env(ctx: typer.Context):
|
|
521
|
+
"""
|
|
522
|
+
查看运行容器可选的环境
|
|
523
|
+
用法:
|
|
524
|
+
bayes gear env [选项]
|
|
525
|
+
|
|
526
|
+
可用选项:
|
|
527
|
+
-h, --help 查看 env 的帮助
|
|
528
|
+
"""
|
|
529
|
+
# 检查用户是否已登录
|
|
530
|
+
login = auth_usecase.check_login()
|
|
531
|
+
if not login:
|
|
532
|
+
print("尚未授权,请先登录")
|
|
533
|
+
raise typer.Exit(code=1)
|
|
534
|
+
# 检查现在是处于 组织/用户 状态
|
|
535
|
+
bayes_settings = ctx.obj
|
|
536
|
+
default_env: Optional[BayesEnvConfig] = bayes_settings.default_env
|
|
537
|
+
|
|
538
|
+
party_name = ""
|
|
539
|
+
if auth_usecase.is_working_on_org():
|
|
540
|
+
party_name = default_env.orgName
|
|
541
|
+
print(f"当前正在组织 {party_name} 上进行操作...")
|
|
542
|
+
else:
|
|
543
|
+
party_name = default_env.username
|
|
544
|
+
print(f"当前正在个人账号 {party_name} 上进行操作...")
|
|
545
|
+
|
|
546
|
+
runtimes = runtime_usecase.get_list_runtimes(party_name, ["JOB"], ["MACHINE_LEARNING"],
|
|
547
|
+
["CONTAINER", "VIRTUAL_MACHINE"])
|
|
548
|
+
runtime_usecase.list_runtimes_display_table(runtimes, "--env")
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
@app.command()
|
|
552
|
+
def logs(id: str, ctx: typer.Context,
|
|
553
|
+
follow: bool = typer.Option(False, "--follow", "-f", help="日志自动更新")):
|
|
554
|
+
"""
|
|
555
|
+
查看容器日志
|
|
556
|
+
用法:
|
|
557
|
+
bayes gear logs [选项]
|
|
558
|
+
|
|
559
|
+
可用选项:
|
|
560
|
+
-f, --follow [可选] 日志自动更新
|
|
561
|
+
-h, --help 查看 logs 的帮助
|
|
562
|
+
|
|
563
|
+
"""
|
|
564
|
+
# 检查用户是否已登录
|
|
565
|
+
login = auth_usecase.check_login()
|
|
566
|
+
if not login:
|
|
567
|
+
print("尚未授权,请先登录")
|
|
568
|
+
raise typer.Exit(code=1)
|
|
569
|
+
# 检查现在是处于 组织/用户 状态
|
|
570
|
+
bayes_settings = ctx.obj
|
|
571
|
+
default_env: Optional[BayesEnvConfig] = bayes_settings.default_env
|
|
572
|
+
|
|
573
|
+
party_name = ""
|
|
574
|
+
if auth_usecase.is_working_on_org():
|
|
575
|
+
party_name = default_env.orgName
|
|
576
|
+
print(f"当前正在组织 {party_name} 上进行操作...")
|
|
577
|
+
else:
|
|
578
|
+
party_name = default_env.username
|
|
579
|
+
print(f"当前正在个人账号 {party_name} 上进行操作...")
|
|
580
|
+
|
|
581
|
+
logs = gear_logs_usecase.get_logs(id, party_name)
|
|
582
|
+
if follow:
|
|
583
|
+
ws, error = gear_logs_usecase.get_logs_follow(id, party_name)
|
|
584
|
+
if error is not None:
|
|
585
|
+
print(error)
|
|
586
|
+
raise typer.Exit(code=1)
|
|
587
|
+
if ws is None:
|
|
588
|
+
print(logs)
|
|
589
|
+
|
|
590
|
+
while True:
|
|
591
|
+
data, error = gear_logs_usecase.receive_logs(ws, id)
|
|
592
|
+
if error is None:
|
|
593
|
+
print(data)
|
|
594
|
+
else:
|
|
595
|
+
print(error)
|
|
596
|
+
raise typer.Exit(code=1)
|
|
597
|
+
else:
|
|
598
|
+
print(logs)
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
@app.command()
|
|
602
|
+
def open(ctx: typer.Context, id_or_name: Optional[str] = typer.Argument(None, help="容器名称 或 容器ID 或 任务ID")):
|
|
603
|
+
"""
|
|
604
|
+
在浏览器打开容器页面
|
|
605
|
+
|
|
606
|
+
用法:
|
|
607
|
+
bayes gear open [容器名称 或 容器ID 或 任务ID] [选项]
|
|
608
|
+
|
|
609
|
+
可用选项:
|
|
610
|
+
-h, --help 查看 open 的帮助
|
|
611
|
+
"""
|
|
612
|
+
# 检查用户是否已登录
|
|
613
|
+
login = auth_usecase.check_login()
|
|
614
|
+
if not login:
|
|
615
|
+
print("尚未授权,请先登录")
|
|
616
|
+
raise typer.Exit(code=1)
|
|
617
|
+
# 检查现在是处于 组织/用户 状态
|
|
618
|
+
bayes_settings = ctx.obj
|
|
619
|
+
default_env: Optional[BayesEnvConfig] = bayes_settings.default_env
|
|
620
|
+
|
|
621
|
+
party_name = ""
|
|
622
|
+
if auth_usecase.is_working_on_org():
|
|
623
|
+
party_name = default_env.orgName
|
|
624
|
+
print(f"当前正在组织 {party_name} 上进行操作...")
|
|
625
|
+
else:
|
|
626
|
+
party_name = default_env.username
|
|
627
|
+
print(f"当前正在个人账号 {party_name} 上进行操作...")
|
|
628
|
+
|
|
629
|
+
if id_or_name is None:
|
|
630
|
+
# 获得当前路径 去读取 openbayesgear 文件获得 init 的 id(projectId)
|
|
631
|
+
current_path = Path(os.getcwd())
|
|
632
|
+
gear_settings = OpenBayesGearSettings(config_path=current_path / GEAR_FILE_NAME)
|
|
633
|
+
if gear_settings.configuration is None or not gear_settings.configuration.id:
|
|
634
|
+
print('项目编号不存在,请先使用 "bayes gear init [项目编码 或 项目名称]" 完成初始化')
|
|
635
|
+
raise typer.Exit(code=1)
|
|
636
|
+
id_or_name = gear_settings.configuration.id
|
|
637
|
+
|
|
638
|
+
job = gear_usecase.get_job_by_id(id_or_name, party_name)
|
|
639
|
+
if job:
|
|
640
|
+
frontend = job.get_link_value("frontend")
|
|
641
|
+
link = Utils.replace_last_id(frontend, job.id)
|
|
642
|
+
print(f"正在打开任务 {link}")
|
|
643
|
+
print("正在跳转到浏览器...")
|
|
644
|
+
gear_open_usecase.open_browser(link)
|
|
645
|
+
return
|
|
646
|
+
|
|
647
|
+
project = gear_usecase.get_project_by_id_or_name(party_name, id_or_name, [], 1, 200)
|
|
648
|
+
if project:
|
|
649
|
+
link = project.get_link_value("frontend")
|
|
650
|
+
print(f"正在打开容器 {link}")
|
|
651
|
+
print("正在跳转到浏览器...")
|
|
652
|
+
gear_open_usecase.open_browser(link)
|
|
653
|
+
else:
|
|
654
|
+
print(f"未查询到容器 {id_or_name}, 请输入正确的容器名称或ID")
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
@app.command()
|
|
658
|
+
def resource(ctx: typer.Context):
|
|
659
|
+
"""
|
|
660
|
+
查看运行容器可选的资源
|
|
661
|
+
|
|
662
|
+
用法:
|
|
663
|
+
bayes gear resource [选项]
|
|
664
|
+
|
|
665
|
+
可用选项:
|
|
666
|
+
-h, --help 查看 open 的帮助
|
|
667
|
+
|
|
668
|
+
"""
|
|
669
|
+
|
|
670
|
+
# 检查用户是否已登录
|
|
671
|
+
login = auth_usecase.check_login()
|
|
672
|
+
if not login:
|
|
673
|
+
print("尚未授权,请先登录")
|
|
674
|
+
raise typer.Exit(code=1)
|
|
675
|
+
# 检查现在是处于 组织/用户 状态
|
|
676
|
+
bayes_settings = ctx.obj
|
|
677
|
+
default_env: Optional[BayesEnvConfig] = bayes_settings.default_env
|
|
678
|
+
|
|
679
|
+
party_name = ""
|
|
680
|
+
if auth_usecase.is_working_on_org():
|
|
681
|
+
party_name = default_env.orgName
|
|
682
|
+
print(f"当前正在组织 {party_name} 上进行操作...")
|
|
683
|
+
else:
|
|
684
|
+
party_name = default_env.username
|
|
685
|
+
print(f"当前正在个人账号 {party_name} 上进行操作...")
|
|
686
|
+
|
|
687
|
+
resource_usecase.list_resources_display_table("--resource", party_name, ["JOB"], ["MACHINE_LEARNING", "CONTAINER"])
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
if __name__ == "__main__":
|
|
691
|
+
app()
|