From d1ea0d753c1fc608bd35ed4b5e18905238a2323d Mon Sep 17 00:00:00 2001 From: e-r-i-k-a Date: Thu, 29 Oct 2020 16:25:17 -0400 Subject: [PATCH 1/3] init --- gradient/api_sdk/clients/notebook_client.py | 5 +++-- gradient/api_sdk/repositories/notebooks.py | 4 ++-- gradient/cli/notebooks.py | 13 +++++++++++-- gradient/commands/notebooks.py | 4 ++-- tests/functional/test_notebooks.py | 3 +++ 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/gradient/api_sdk/clients/notebook_client.py b/gradient/api_sdk/clients/notebook_client.py index 2dde6e76..9961432e 100644 --- a/gradient/api_sdk/clients/notebook_client.py +++ b/gradient/api_sdk/clients/notebook_client.py @@ -122,16 +122,17 @@ def start( return handle - def fork(self, id, tags=None): + def fork(self, id, project_id, tags=None): """Fork an existing notebook :param str|int id: + :param str project_id: :param list[str] tags: List of tags :return: Notebook ID :rtype str: """ repository = self.build_repository(repositories.ForkNotebook) - handle = repository.fork(id) + handle = repository.fork(id, project_id) if tags: self.add_tags(entity_id=handle, tags=tags) diff --git a/gradient/api_sdk/repositories/notebooks.py b/gradient/api_sdk/repositories/notebooks.py index fde00b0c..8dcd1fe3 100644 --- a/gradient/api_sdk/repositories/notebooks.py +++ b/gradient/api_sdk/repositories/notebooks.py @@ -37,8 +37,8 @@ class ForkNotebook(GetNotebookApiUrlMixin, BaseRepository): SERIALIZER_CLS = serializers.NotebookSchema VALIDATION_ERROR_MESSAGE = "Failed to fork notebook" - def fork(self, id): - instance = {"notebookId": id} + def fork(self, id_, project_id): + instance = {"notebookId": id_, "projectId": project_id} handle = self._send_request(instance) return handle diff --git a/gradient/cli/notebooks.py b/gradient/cli/notebooks.py index 1d631ea7..04af61ab 100644 --- a/gradient/cli/notebooks.py +++ b/gradient/cli/notebooks.py @@ -237,14 +237,23 @@ def start_notebook(api_key, options_file, **notebook): @click.option( "--id", "id_", + required=True, help="Notebook ID", cls=common.GradientOption, ) +@click.option( + "--projectId", + "project_id", + required=True, + type=str, + help="Project ID", + cls=common.GradientOption, +) @common.api_key_option @common.options_file -def delete_notebook(id_, api_key, options_file): +def fork_notebook(id_, project_id, api_key, options_file): command = notebooks.ForkNotebookCommand(api_key=api_key) - command.execute(id_=id_) + command.execute(id_=id_, project_id=project_id) @notebooks_group.command("delete", help="Delete existing notebook") diff --git a/gradient/commands/notebooks.py b/gradient/commands/notebooks.py index 5d7b597a..b9bb0b5f 100644 --- a/gradient/commands/notebooks.py +++ b/gradient/commands/notebooks.py @@ -69,9 +69,9 @@ def get_instance_url(self, notebook_id): class ForkNotebookCommand(BaseNotebookCommand): WAITING_FOR_RESPONSE_MESSAGE = "Forking notebook" - def execute(self, id_): + def execute(self, id_, project_id): with halo.Halo(text=self.WAITING_FOR_RESPONSE_MESSAGE, spinner="dots"): - handle = self.client.fork(id_) + handle = self.client.fork(id_, project_id) self.logger.log("Notebook forked to id: {}".format(handle)) diff --git a/tests/functional/test_notebooks.py b/tests/functional/test_notebooks.py index d0fe332d..d17b34e4 100644 --- a/tests/functional/test_notebooks.py +++ b/tests/functional/test_notebooks.py @@ -234,9 +234,11 @@ class TestNotebooksFork(object): "notebooks", "fork", "--id", "n1234", + "--projectId", "p1234", ] EXPECTED_REQUEST_JSON = { "notebookId": "n1234", + "projectId": "p1234", } EXPECTED_RESPONSE_JSON = { "handle": "n1234", @@ -251,6 +253,7 @@ class TestNotebooksFork(object): "notebooks", "fork", "--id", "n1234", + "--projectId", "p1234", "--apiKey", "some_key", ] RESPONSE_JSON_WITH_WRONG_API_TOKEN = {"status": 400, "message": "Invalid API token"} From 33669a63592d6c644306d882658ee06127d53260 Mon Sep 17 00:00:00 2001 From: e-r-i-k-a Date: Fri, 30 Oct 2020 15:07:07 -0400 Subject: [PATCH 2/3] added project to notebook detail --- gradient/commands/notebooks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/gradient/commands/notebooks.py b/gradient/commands/notebooks.py index b9bb0b5f..6122f195 100644 --- a/gradient/commands/notebooks.py +++ b/gradient/commands/notebooks.py @@ -120,6 +120,7 @@ def _get_table_data(self, instance): data = ( ("Name", instance.name), ("ID", instance.id), + ("Project", instance.project_handle), ("VM Type", instance.vm_type), ("State", instance.state), ("FQDN", instance.fqdn), From 11cd93d04946a7464d268ad085337f6655ad7a8e Mon Sep 17 00:00:00 2001 From: e-r-i-k-a Date: Fri, 30 Oct 2020 15:49:22 -0400 Subject: [PATCH 3/3] updated tests --- tests/functional/test_notebooks.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/functional/test_notebooks.py b/tests/functional/test_notebooks.py index d17b34e4..a48d7f56 100644 --- a/tests/functional/test_notebooks.py +++ b/tests/functional/test_notebooks.py @@ -648,6 +648,7 @@ class TestNotebooksdetails(object): | Name | some_name | +---------+-----------------------------------+ | ID | ngw7piq9 | +| Project | prg284tu2 | | VM Type | K80 | | State | Running | | FQDN | ngw7piq9.dgradient.paperspace.com | @@ -658,6 +659,7 @@ class TestNotebooksdetails(object): | Name | some_name | +---------+-----------------------------------+ | ID | ngw7piq9 | +| Project | prg284tu2 | | VM Type | K80 | | State | Running | | FQDN | ngw7piq9.dgradient.paperspace.com |