|
4 | 4 |
|
5 | 5 | import click |
6 | 6 |
|
7 | | -from paperspace import constants |
| 7 | +from paperspace import constants, client, config |
8 | 8 | from paperspace.commands import experiments as experiments_commands, deployments as deployments_commands |
9 | 9 |
|
10 | 10 |
|
@@ -116,6 +116,10 @@ def common_experiments_create_options(f): |
116 | 116 | "--modelPath", |
117 | 117 | "modelPath", |
118 | 118 | ), |
| 119 | + click.option( |
| 120 | + "--apiKey", |
| 121 | + "api_key", |
| 122 | + ) |
119 | 123 | ] |
120 | 124 | return functools.reduce(lambda x, opt: opt(x), reversed(options), f) |
121 | 125 |
|
@@ -232,60 +236,84 @@ def common_experiments_create_single_node_options(f): |
232 | 236 | @create.command(name="multinode") |
233 | 237 | @common_experiments_create_options |
234 | 238 | @common_experiment_create_multi_node_options |
235 | | -def create_multi_node(**kwargs): |
| 239 | +def create_multi_node(api_key, **kwargs): |
236 | 240 | del_if_value_is_none(kwargs) |
237 | | - experiments_commands.create_experiment(kwargs) |
| 241 | + experiments_api = client.API(config.CONFIG_EXPERIMENTS_HOST, api_key=api_key) |
| 242 | + experiments_commands.create_experiment(kwargs, api=experiments_api) |
238 | 243 |
|
239 | 244 |
|
240 | 245 | @create.command(name="singlenode") |
241 | 246 | @common_experiments_create_options |
242 | 247 | @common_experiments_create_single_node_options |
243 | | -def create_single_node(**kwargs): |
| 248 | +def create_single_node(api_key, **kwargs): |
244 | 249 | kwargs["experimentTypeId"] = constants.ExperimentType.SINGLE_NODE |
245 | 250 | del_if_value_is_none(kwargs) |
246 | | - experiments_commands.create_experiment(kwargs) |
| 251 | + experiments_api = client.API(config.CONFIG_EXPERIMENTS_HOST, api_key=api_key) |
| 252 | + experiments_commands.create_experiment(kwargs, api=experiments_api) |
247 | 253 |
|
248 | 254 |
|
249 | 255 | @create_and_start.command(name="multinode") |
250 | 256 | @common_experiments_create_options |
251 | 257 | @common_experiment_create_multi_node_options |
252 | | -def create_and_start_multi_node(**kwargs): |
| 258 | +def create_and_start_multi_node(api_key, **kwargs): |
253 | 259 | del_if_value_is_none(kwargs) |
254 | | - experiments_commands.create_and_start_experiment(kwargs) |
| 260 | + experiments_api = client.API(config.CONFIG_EXPERIMENTS_HOST, api_key=api_key) |
| 261 | + experiments_commands.create_and_start_experiment(kwargs, api=experiments_api) |
255 | 262 |
|
256 | 263 |
|
257 | 264 | @create_and_start.command(name="singlenode") |
258 | 265 | @common_experiments_create_options |
259 | 266 | @common_experiments_create_single_node_options |
260 | | -def create_and_start_single_node(**kwargs): |
| 267 | +def create_and_start_single_node(api_key, **kwargs): |
261 | 268 | kwargs["experimentTypeId"] = constants.ExperimentType.SINGLE_NODE |
262 | 269 | del_if_value_is_none(kwargs) |
263 | | - experiments_commands.create_and_start_experiment(kwargs) |
| 270 | + experiments_api = client.API(config.CONFIG_EXPERIMENTS_HOST, api_key=api_key) |
| 271 | + experiments_commands.create_and_start_experiment(kwargs, api=experiments_api) |
264 | 272 |
|
265 | 273 |
|
266 | 274 | @experiments.command() |
267 | 275 | @click.argument("experiment-handle") |
268 | | -def start(experiment_handle): |
269 | | - experiments_commands.start_experiment(experiment_handle) |
| 276 | +@click.option( |
| 277 | + "--apiKey", |
| 278 | + "api_key", |
| 279 | +) |
| 280 | +def start(experiment_handle, api_key): |
| 281 | + experiments_api = client.API(config.CONFIG_EXPERIMENTS_HOST, api_key=api_key) |
| 282 | + experiments_commands.start_experiment(experiment_handle, api=experiments_api) |
270 | 283 |
|
271 | 284 |
|
272 | 285 | @experiments.command() |
273 | 286 | @click.argument("experiment-handle") |
274 | | -def stop(experiment_handle): |
275 | | - experiments_commands.stop_experiment(experiment_handle) |
| 287 | +@click.option( |
| 288 | + "--apiKey", |
| 289 | + "api_key", |
| 290 | +) |
| 291 | +def stop(experiment_handle, api_key): |
| 292 | + experiments_api = client.API(config.CONFIG_EXPERIMENTS_HOST, api_key=api_key) |
| 293 | + experiments_commands.stop_experiment(experiment_handle, api=experiments_api) |
276 | 294 |
|
277 | 295 |
|
278 | 296 | @experiments.command("list") |
279 | 297 | @click.option("--projectHandle", "-p", "project_handles", multiple=True) |
280 | | -def list_experiments(project_handles): |
281 | | - command = experiments_commands.ListExperimentsCommand() |
| 298 | +@click.option( |
| 299 | + "--apiKey", |
| 300 | + "api_key", |
| 301 | +) |
| 302 | +def list_experiments(project_handles, api_key): |
| 303 | + experiments_api = client.API(config.CONFIG_EXPERIMENTS_HOST, api_key=api_key) |
| 304 | + command = experiments_commands.ListExperimentsCommand(api=experiments_api) |
282 | 305 | command.execute(project_handles) |
283 | 306 |
|
284 | 307 |
|
285 | 308 | @experiments.command("details") |
286 | 309 | @click.argument("experiment-handle") |
287 | | -def get_experiment_details(experiment_handle): |
288 | | - experiments_commands.get_experiment_details(experiment_handle) |
| 310 | +@click.option( |
| 311 | + "--apiKey", |
| 312 | + "api_key", |
| 313 | +) |
| 314 | +def get_experiment_details(experiment_handle, api_key): |
| 315 | + experiments_api = client.API(config.CONFIG_EXPERIMENTS_HOST, api_key=api_key) |
| 316 | + experiments_commands.get_experiment_details(experiment_handle, api=experiments_api) |
289 | 317 |
|
290 | 318 |
|
291 | 319 | # TODO: delete experiment - not implemented in the api |
|
0 commit comments