Skip to content
This repository was archived by the owner on Aug 11, 2020. It is now read-only.

Commit 41f3231

Browse files
kossakBartoszCki
authored andcommitted
cluster and node related params added to job creating commands
1 parent 370a1a7 commit 41f3231

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

paperspace/cli/common.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import functools
22
import getpass
3+
import json
34

45
import click
56
from click_didyoumean import DYMMixin
@@ -19,6 +20,16 @@ def del_if_value_is_none(dict_):
1920
del dict_[key]
2021

2122

23+
def jsonify_dicts(dict_):
24+
json_fields = [
25+
"envVars",
26+
"nodeAttrs"
27+
]
28+
for field in json_fields:
29+
if field in dict_:
30+
dict_[field] = json.dumps(dict_[field])
31+
32+
2233
class ClickGroup(DYMMixin, HelpColorsGroup):
2334
def group(self, *args, **kwargs):
2435
aliases = []

paperspace/cli/jobs.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from paperspace import client, config
66
from paperspace.cli.cli import cli
77
from paperspace.cli.cli_types import json_string
8-
from paperspace.cli.common import api_key_option, del_if_value_is_none, ClickGroup
8+
from paperspace.cli.common import api_key_option, del_if_value_is_none, ClickGroup, jsonify_dicts
99
from paperspace.commands import jobs as jobs_commands
1010

1111

@@ -89,6 +89,9 @@ def common_jobs_create_options(f):
8989
click.option("--relDockerfilePath", "relDockerfilePath", help="Relative path to Dockerfile"),
9090
click.option("--registryUsername", "registryUsername", help="Docker registry username"),
9191
click.option("--registryPassword", "registryPassword", help="Docker registry password"),
92+
click.option("--cluster", "cluster", help="Cluster name"),
93+
click.option("--clusterId", "cluster", help="Cluster id"),
94+
click.option("--nodeAttrs", "nodeAttrs", type=json_string, help="Cluster node details"),
9295
]
9396
return functools.reduce(lambda x, opt: opt(x), reversed(options), f)
9497

@@ -99,6 +102,8 @@ def common_jobs_create_options(f):
99102
@click.pass_context
100103
def create_job(ctx, api_key, **kwargs):
101104
del_if_value_is_none(kwargs)
105+
jsonify_dicts(kwargs)
106+
102107
jobs_api = client.API(config.CONFIG_HOST, api_key=api_key)
103108
command = jobs_commands.CreateJobCommand(api=jobs_api)
104109
job = command.execute(kwargs)

paperspace/cli/run.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from paperspace import client, config
44
from paperspace.cli import common
55
from paperspace.cli.cli import cli
6-
from paperspace.cli.common import del_if_value_is_none, deprecated
6+
from paperspace.cli.common import del_if_value_is_none, deprecated, jsonify_dicts
77
from paperspace.cli.jobs import common_jobs_create_options
88
from paperspace.commands.run import RunCommand
99
from paperspace.constants import RunMode
@@ -19,6 +19,8 @@
1919
@common.api_key_option
2020
def run(api_key, **kwargs):
2121
del_if_value_is_none(kwargs)
22+
jsonify_dicts(kwargs)
23+
2224
jobs_api = client.API(config.CONFIG_HOST, api_key=api_key)
2325
command = RunCommand(api=jobs_api)
2426
command.execute(**kwargs)

0 commit comments

Comments
 (0)