Skip to content

Commit 091b1fa

Browse files
authored
feat(notebooks): expose projectId flag and make it required (#314)
1 parent aa3b0a1 commit 091b1fa

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

gradient/api_sdk/clients/notebook_client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class NotebooksClient(TagsSupportMixin, BaseClient):
88
def create(
99
self,
1010
machine_type,
11+
project_id=None,
1112
cluster_id=None,
1213
container=None,
1314
container_id=None,
@@ -30,6 +31,7 @@ def create(
3031
3132
:param str machine_type:
3233
:param int container_id:
34+
:param str|int project_id:
3335
:param str cluster_id:
3436
:param str container:
3537
:param str name:
@@ -53,6 +55,7 @@ def create(
5355

5456
notebook = models.Notebook(
5557
container_id=container_id,
58+
project_id=project_id,
5659
cluster_id=cluster_id,
5760
container=container,
5861
name=name,

gradient/api_sdk/models/notebook.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ class Notebook(object):
2323
container_user = attr.ib(type=str, default=None)
2424
shutdown_timeout = attr.ib(type=int, default=None)
2525
is_preemptible = attr.ib(type=bool, default=None)
26-
project_id = attr.ib(type=bool, default=None)
27-
state = attr.ib(type=bool, default=None)
28-
vm_type = attr.ib(type=bool, default=None)
29-
fqdn = attr.ib(type=bool, default=None)
26+
project_id = attr.ib(type=str, default=None)
27+
project_handle = attr.ib(type=str, default=None)
28+
state = attr.ib(type=str, default=None)
29+
vm_type = attr.ib(type=str, default=None)
30+
fqdn = attr.ib(type=str, default=None)
3031
namespace = attr.ib(type=str, default=None)
3132
tags = attr.ib(type=list, factory=list)
3233
metrics_url = attr.ib(type=str, default=None)
@@ -58,7 +59,7 @@ class Notebook(object):
5859

5960
@property
6061
def url(self):
61-
url = concatenate_urls(config.WEB_URL, "/{}/notebook/{}".format(self.namespace, self.project_id))
62+
url = concatenate_urls(config.WEB_URL, "/{}/notebook/{}".format(self.namespace, self.project_handle))
6263
return url
6364

6465

gradient/api_sdk/serializers/notebook.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ class NotebookSchema(BaseSchema):
2525
shutdown_timeout = marshmallow.fields.Int(load_from="shutdownTimeout", dump_to="shutdownTimeout")
2626
is_preemptible = marshmallow.fields.Bool(load_from="isPreemptible", dump_to="isPreemptible")
2727
is_public = marshmallow.fields.Bool(load_from="isPublic", dump_to="isPublic")
28-
project_id = marshmallow.fields.Str(load_from="projectHandle", dump_to="projectHandle")
28+
project_id = marshmallow.fields.Str(load_from="projectId", dump_to="projectId")
29+
project_handle = marshmallow.fields.Str(load_from="projectHandle", dump_to="projectHandle")
2930
state = marshmallow.fields.Str()
3031
token = marshmallow.fields.Str()
3132
job_error = marshmallow.fields.Str(load_from="jobError", dump_to="jobError")

gradient/cli/notebooks.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ def notebook_metrics():
4141
help="Container name",
4242
cls=common.GradientOption,
4343
)
44+
@click.option(
45+
"--projectId",
46+
"project_id",
47+
required=True,
48+
type=str,
49+
help="Project ID",
50+
cls=common.GradientOption,
51+
)
4452
@click.option(
4553
"--clusterId",
4654
"cluster_id",

tests/config_files/notebooks_create.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
apiKey: some_key
22
clusterId: 321
3+
projectId: pr1234
34
container: "jupyter/notebook"
45
command: some_entrypoint
56
containerUser: some_container_user
@@ -11,4 +12,4 @@ shutdownTimeout: 8
1112
machineType: P5000
1213
environment:
1314
key: val
14-
workspace: https://github.com/fake/repo.git
15+
workspace: https://github.com/fake/repo.git

tests/functional/test_notebooks.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class TestNotebooksCreate(object):
5353
"create",
5454
"--machineType", "P5000",
5555
"--container", "jupyter/notebook",
56-
"--clusterId", "321"
56+
"--projectId", "pr1234",
57+
"--clusterId", "321",
5758
]
5859
EXPECTED_REQUEST_JSON = {
5960
"machineType": "P5000",
@@ -62,6 +63,7 @@ class TestNotebooksCreate(object):
6263
"isPreemptible": False,
6364
"isPublic": False,
6465
"workspace": "none",
66+
"projectId": "pr1234",
6567
}
6668
EXPECTED_RESPONSE_JSON = {
6769
"handle": "some_id",
@@ -79,6 +81,7 @@ class TestNotebooksCreate(object):
7981
"create",
8082
"--machineType", "P5000",
8183
"--container", "jupyter/notebook",
84+
"--projectId", "pr1234",
8285
"--clusterId", "321",
8386
"--apiKey", "some_key",
8487
]
@@ -88,6 +91,7 @@ class TestNotebooksCreate(object):
8891
"create",
8992
"--machineType", "P5000",
9093
"--container", "jupyter/notebook",
94+
"--projectId", "pr1234",
9195
"--clusterId", "321",
9296
"--name", "some_notebook_name",
9397
"--registryUsername", "some_username",
@@ -102,6 +106,7 @@ class TestNotebooksCreate(object):
102106
EXPECTED_REQUEST_JSON_WITH_ALL_OPTIONS = {
103107
"machineType": "P5000",
104108
"container": "jupyter/notebook",
109+
"projectId": "pr1234",
105110
"clusterId": "321",
106111
"name": "some_notebook_name",
107112
"registryUsername": "some_username",

0 commit comments

Comments
 (0)