Skip to content

Commit 8cbef23

Browse files
authored
feat(notebooks): require projectId to fork notebook N-39 (#329)
1 parent d530034 commit 8cbef23

File tree

5 files changed

+24
-8
lines changed

5 files changed

+24
-8
lines changed

gradient/api_sdk/clients/notebook_client.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,17 @@ def start(
122122

123123
return handle
124124

125-
def fork(self, id, tags=None):
125+
def fork(self, id, project_id, tags=None):
126126
"""Fork an existing notebook
127127
:param str|int id:
128+
:param str project_id:
128129
:param list[str] tags: List of tags
129130
130131
:return: Notebook ID
131132
:rtype str:
132133
"""
133134
repository = self.build_repository(repositories.ForkNotebook)
134-
handle = repository.fork(id)
135+
handle = repository.fork(id, project_id)
135136

136137
if tags:
137138
self.add_tags(entity_id=handle, tags=tags)

gradient/api_sdk/repositories/notebooks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class ForkNotebook(GetNotebookApiUrlMixin, BaseRepository):
3737
SERIALIZER_CLS = serializers.NotebookSchema
3838
VALIDATION_ERROR_MESSAGE = "Failed to fork notebook"
3939

40-
def fork(self, id):
41-
instance = {"notebookId": id}
40+
def fork(self, id_, project_id):
41+
instance = {"notebookId": id_, "projectId": project_id}
4242
handle = self._send_request(instance)
4343
return handle
4444

gradient/cli/notebooks.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,23 @@ def start_notebook(api_key, options_file, **notebook):
237237
@click.option(
238238
"--id",
239239
"id_",
240+
required=True,
240241
help="Notebook ID",
241242
cls=common.GradientOption,
242243
)
244+
@click.option(
245+
"--projectId",
246+
"project_id",
247+
required=True,
248+
type=str,
249+
help="Project ID",
250+
cls=common.GradientOption,
251+
)
243252
@common.api_key_option
244253
@common.options_file
245-
def delete_notebook(id_, api_key, options_file):
254+
def fork_notebook(id_, project_id, api_key, options_file):
246255
command = notebooks.ForkNotebookCommand(api_key=api_key)
247-
command.execute(id_=id_)
256+
command.execute(id_=id_, project_id=project_id)
248257

249258

250259
@notebooks_group.command("delete", help="Delete existing notebook")

gradient/commands/notebooks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ def get_instance_url(self, notebook_id):
6969
class ForkNotebookCommand(BaseNotebookCommand):
7070
WAITING_FOR_RESPONSE_MESSAGE = "Forking notebook"
7171

72-
def execute(self, id_):
72+
def execute(self, id_, project_id):
7373
with halo.Halo(text=self.WAITING_FOR_RESPONSE_MESSAGE, spinner="dots"):
74-
handle = self.client.fork(id_)
74+
handle = self.client.fork(id_, project_id)
7575

7676
self.logger.log("Notebook forked to id: {}".format(handle))
7777

@@ -120,6 +120,7 @@ def _get_table_data(self, instance):
120120
data = (
121121
("Name", instance.name),
122122
("ID", instance.id),
123+
("Project", instance.project_handle),
123124
("VM Type", instance.vm_type),
124125
("State", instance.state),
125126
("FQDN", instance.fqdn),

tests/functional/test_notebooks.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,11 @@ class TestNotebooksFork(object):
234234
"notebooks",
235235
"fork",
236236
"--id", "n1234",
237+
"--projectId", "p1234",
237238
]
238239
EXPECTED_REQUEST_JSON = {
239240
"notebookId": "n1234",
241+
"projectId": "p1234",
240242
}
241243
EXPECTED_RESPONSE_JSON = {
242244
"handle": "n1234",
@@ -251,6 +253,7 @@ class TestNotebooksFork(object):
251253
"notebooks",
252254
"fork",
253255
"--id", "n1234",
256+
"--projectId", "p1234",
254257
"--apiKey", "some_key",
255258
]
256259
RESPONSE_JSON_WITH_WRONG_API_TOKEN = {"status": 400, "message": "Invalid API token"}
@@ -645,6 +648,7 @@ class TestNotebooksdetails(object):
645648
| Name | some_name |
646649
+---------+-----------------------------------+
647650
| ID | ngw7piq9 |
651+
| Project | prg284tu2 |
648652
| VM Type | K80 |
649653
| State | Running |
650654
| FQDN | ngw7piq9.dgradient.paperspace.com |
@@ -655,6 +659,7 @@ class TestNotebooksdetails(object):
655659
| Name | some_name |
656660
+---------+-----------------------------------+
657661
| ID | ngw7piq9 |
662+
| Project | prg284tu2 |
658663
| VM Type | K80 |
659664
| State | Running |
660665
| FQDN | ngw7piq9.dgradient.paperspace.com |

0 commit comments

Comments
 (0)