From 40f2869561f02fe578be94c9eb58c750e19deb37 Mon Sep 17 00:00:00 2001 From: Ben Batha Date: Thu, 16 Jul 2020 09:57:43 -0400 Subject: [PATCH] feat(notebooks): expose projectId flag and make it required --- gradient/api_sdk/clients/notebook_client.py | 3 +++ gradient/api_sdk/models/notebook.py | 11 ++++++----- gradient/api_sdk/serializers/notebook.py | 3 ++- gradient/cli/notebooks.py | 8 ++++++++ tests/config_files/notebooks_create.yaml | 3 ++- tests/functional/test_notebooks.py | 7 ++++++- 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/gradient/api_sdk/clients/notebook_client.py b/gradient/api_sdk/clients/notebook_client.py index 0a160970..2dde6e76 100644 --- a/gradient/api_sdk/clients/notebook_client.py +++ b/gradient/api_sdk/clients/notebook_client.py @@ -8,6 +8,7 @@ class NotebooksClient(TagsSupportMixin, BaseClient): def create( self, machine_type, + project_id=None, cluster_id=None, container=None, container_id=None, @@ -30,6 +31,7 @@ def create( :param str machine_type: :param int container_id: + :param str|int project_id: :param str cluster_id: :param str container: :param str name: @@ -53,6 +55,7 @@ def create( notebook = models.Notebook( container_id=container_id, + project_id=project_id, cluster_id=cluster_id, container=container, name=name, diff --git a/gradient/api_sdk/models/notebook.py b/gradient/api_sdk/models/notebook.py index d169625c..8397a289 100644 --- a/gradient/api_sdk/models/notebook.py +++ b/gradient/api_sdk/models/notebook.py @@ -23,10 +23,11 @@ class Notebook(object): container_user = attr.ib(type=str, default=None) shutdown_timeout = attr.ib(type=int, default=None) is_preemptible = attr.ib(type=bool, default=None) - project_id = attr.ib(type=bool, default=None) - state = attr.ib(type=bool, default=None) - vm_type = attr.ib(type=bool, default=None) - fqdn = attr.ib(type=bool, default=None) + project_id = attr.ib(type=str, default=None) + project_handle = attr.ib(type=str, default=None) + state = attr.ib(type=str, default=None) + vm_type = attr.ib(type=str, default=None) + fqdn = attr.ib(type=str, default=None) namespace = attr.ib(type=str, default=None) tags = attr.ib(type=list, factory=list) metrics_url = attr.ib(type=str, default=None) @@ -58,7 +59,7 @@ class Notebook(object): @property def url(self): - url = concatenate_urls(config.WEB_URL, "/{}/notebook/{}".format(self.namespace, self.project_id)) + url = concatenate_urls(config.WEB_URL, "/{}/notebook/{}".format(self.namespace, self.project_handle)) return url diff --git a/gradient/api_sdk/serializers/notebook.py b/gradient/api_sdk/serializers/notebook.py index f39d8eb7..bad9ecc9 100644 --- a/gradient/api_sdk/serializers/notebook.py +++ b/gradient/api_sdk/serializers/notebook.py @@ -25,7 +25,8 @@ class NotebookSchema(BaseSchema): shutdown_timeout = marshmallow.fields.Int(load_from="shutdownTimeout", dump_to="shutdownTimeout") is_preemptible = marshmallow.fields.Bool(load_from="isPreemptible", dump_to="isPreemptible") is_public = marshmallow.fields.Bool(load_from="isPublic", dump_to="isPublic") - project_id = marshmallow.fields.Str(load_from="projectHandle", dump_to="projectHandle") + project_id = marshmallow.fields.Str(load_from="projectId", dump_to="projectId") + project_handle = marshmallow.fields.Str(load_from="projectHandle", dump_to="projectHandle") state = marshmallow.fields.Str() token = marshmallow.fields.Str() job_error = marshmallow.fields.Str(load_from="jobError", dump_to="jobError") diff --git a/gradient/cli/notebooks.py b/gradient/cli/notebooks.py index 975fb723..1d631ea7 100644 --- a/gradient/cli/notebooks.py +++ b/gradient/cli/notebooks.py @@ -41,6 +41,14 @@ def notebook_metrics(): help="Container name", cls=common.GradientOption, ) +@click.option( + "--projectId", + "project_id", + required=True, + type=str, + help="Project ID", + cls=common.GradientOption, +) @click.option( "--clusterId", "cluster_id", diff --git a/tests/config_files/notebooks_create.yaml b/tests/config_files/notebooks_create.yaml index a2b547cd..64b0afbc 100644 --- a/tests/config_files/notebooks_create.yaml +++ b/tests/config_files/notebooks_create.yaml @@ -1,5 +1,6 @@ apiKey: some_key clusterId: 321 +projectId: pr1234 container: "jupyter/notebook" command: some_entrypoint containerUser: some_container_user @@ -11,4 +12,4 @@ shutdownTimeout: 8 machineType: P5000 environment: key: val -workspace: https://github.com/fake/repo.git \ No newline at end of file +workspace: https://github.com/fake/repo.git diff --git a/tests/functional/test_notebooks.py b/tests/functional/test_notebooks.py index bda0d18f..9b79b159 100644 --- a/tests/functional/test_notebooks.py +++ b/tests/functional/test_notebooks.py @@ -53,7 +53,8 @@ class TestNotebooksCreate(object): "create", "--machineType", "P5000", "--container", "jupyter/notebook", - "--clusterId", "321" + "--projectId", "pr1234", + "--clusterId", "321", ] EXPECTED_REQUEST_JSON = { "machineType": "P5000", @@ -62,6 +63,7 @@ class TestNotebooksCreate(object): "isPreemptible": False, "isPublic": False, "workspace": "none", + "projectId": "pr1234", } EXPECTED_RESPONSE_JSON = { "handle": "some_id", @@ -79,6 +81,7 @@ class TestNotebooksCreate(object): "create", "--machineType", "P5000", "--container", "jupyter/notebook", + "--projectId", "pr1234", "--clusterId", "321", "--apiKey", "some_key", ] @@ -88,6 +91,7 @@ class TestNotebooksCreate(object): "create", "--machineType", "P5000", "--container", "jupyter/notebook", + "--projectId", "pr1234", "--clusterId", "321", "--name", "some_notebook_name", "--registryUsername", "some_username", @@ -102,6 +106,7 @@ class TestNotebooksCreate(object): EXPECTED_REQUEST_JSON_WITH_ALL_OPTIONS = { "machineType": "P5000", "container": "jupyter/notebook", + "projectId": "pr1234", "clusterId": "321", "name": "some_notebook_name", "registryUsername": "some_username",