Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ halo = "*"
pyyaml = "*"
python-dateutil = ">=2.0,<3.0"
websocket-client = "*"
gradient-utils = ">=0.1.1"

[dev-packages]
twine = "*"
Expand Down
494 changes: 293 additions & 201 deletions Pipfile.lock

Large diffs are not rendered by default.

34 changes: 14 additions & 20 deletions gradient/api_sdk/clients/notebook_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ class NotebooksClient(TagsSupportMixin, BaseClient):

def create(
self,
cluster_id,
machine_type,
cluster_id=None,
container=None,
container_id=None,
vm_type_id=None,
vm_type_label=None,
container_name=None,
name=None,
registry_username=None,
registry_password=None,
default_entrypoint=None,
command=None,
container_user=None,
shutdown_timeout=None,
is_preemptible=None,
Expand All @@ -24,15 +23,14 @@ def create(
):
"""Create new notebook

:param str machine_type:
:param int container_id:
:param str cluster_id:
:param str vm_type_id:
:param int vm_type_label:
:param str container_name:
:param str container:
:param str name:
:param str registry_username:
:param str registry_password:
:param str default_entrypoint:
:param str command:
:param str container_user:
:param int shutdown_timeout:
:param bool is_preemptible:
Expand All @@ -46,16 +44,15 @@ def create(
notebook = models.Notebook(
container_id=container_id,
cluster_id=cluster_id,
container_name=container_name,
container=container,
name=name,
registry_username=registry_username,
registry_password=registry_password,
default_entrypoint=default_entrypoint,
command=command,
container_user=container_user,
shutdown_timeout=shutdown_timeout,
is_preemptible=is_preemptible,
vm_type_label=vm_type_label,
vm_type_id=vm_type_id,
machine_type=machine_type,
is_public=is_public,
)

Expand All @@ -70,19 +67,17 @@ def create(
def start(
self,
id,
cluster_id,
vm_type_id=None,
vm_type_label=None,
machine_type,
cluster_id=None,
name=None,
shutdown_timeout=None,
is_preemptible=None,
tags=None,
):
"""Start existing notebook
:param str|int id:
:param str machine_type:
:param str cluster_id:
:param str vm_type_id:
:param int vm_type_label:
:param str name:
:param int shutdown_timeout:
:param bool is_preemptible:
Expand All @@ -93,8 +88,7 @@ def start(
"""
notebook = models.NotebookStart(
notebook_id=id,
vm_type_id=vm_type_id,
vm_type_label=vm_type_label,
machine_type=machine_type,
cluster_id=cluster_id,
notebook_name=name,
shutdown_timeout=shutdown_timeout,
Expand Down
3 changes: 3 additions & 0 deletions gradient/api_sdk/models/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@attr.s
class Notebook(object):
id = attr.ib(type=str, default=None)
machine_type = attr.ib(type=str, default=None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

vm_type_id = attr.ib(type=int, default=None)
vm_type_label = attr.ib(type=str, default=None)
container_id = attr.ib(type=int, default=None)
Expand All @@ -17,6 +18,7 @@ class Notebook(object):
cluster_id = attr.ib(type=str, default=None)
registry_username = attr.ib(type=str, default=None)
registry_password = attr.ib(type=str, default=None)
command = attr.ib(type=str, default=None)
default_entrypoint = attr.ib(type=str, default=None)
container_user = attr.ib(type=str, default=None)
shutdown_timeout = attr.ib(type=int, default=None)
Expand Down Expand Up @@ -57,6 +59,7 @@ def url(self):
@attr.s
class NotebookStart(object):
notebook_id = attr.ib(type=str, default=None)
machine_type = attr.ib(type=str, default=None)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to leave the old fields in the models because the responses have not been updated to the new field names yet.

vm_type_id = attr.ib(type=int, default=None)
vm_type_label = attr.ib(type=str, default=None)
cluster_id = attr.ib(type=str, default=None)
Expand Down
6 changes: 5 additions & 1 deletion gradient/api_sdk/serializers/notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ class NotebookSchema(BaseSchema):
MODEL = models.Notebook

id = marshmallow.fields.Str()
machine_type = marshmallow.fields.Str(load_from="machineType", dump_to="machineType")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

vm_type_id = marshmallow.fields.Int(load_from="vmTypeId", dump_to="vmTypeId")
vm_type_label = marshmallow.fields.Str(load_from="vmTypeLabel", dump_to="vmTypeLabel")
container_id = marshmallow.fields.Int(load_from="containerId", dump_to="containerId", allow_none=True)
container = marshmallow.fields.Str(load_from="container", dump_to="container", allow_none=True)
container_name = marshmallow.fields.Str(load_from="containerName", dump_to="containerName", allow_none=True)
name = marshmallow.fields.Str()
cluster_id = marshmallow.fields.Str(load_from="clusterId", dump_to="clusterId")
registry_username = marshmallow.fields.Str(load_from="registryUsername", dump_to="registryUsername")
registry_password = marshmallow.fields.Str(load_from="registryPassword", dump_to="registryPassword")
command = marshmallow.fields.Str(load_from="command", dump_to="command")
default_entrypoint = marshmallow.fields.Str(load_from="defaultEntrypoint", dump_to="defaultEntrypoint")
container_user = marshmallow.fields.Str(load_from="containerUser", dump_to="containerUser")
shutdown_timeout = marshmallow.fields.Int(load_from="shutdownTimeout", dump_to="shutdownTimeout")
Expand Down Expand Up @@ -52,14 +55,15 @@ class NotebookSchema(BaseSchema):
def preprocess(self, data, **kwargs):
data = copy.copy(data)

utils.base64_encode_attribute(data, "default_entrypoint")
utils.base64_encode_attribute(data, "command")
return data


class NotebookStartSchema(BaseSchema):
MODEL = models.NotebookStart

notebook_id = marshmallow.fields.Str(load_from="notebookId", dump_to="notebookId")
machine_type = marshmallow.fields.Str(load_from="machineType", dump_to="machineType")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

vm_type_id = marshmallow.fields.Int(load_from="vmTypeId", dump_to="vmTypeId")
vm_type_label = marshmallow.fields.Str(load_from="vmTypeLabel", dump_to="vmTypeLabel")
name = marshmallow.fields.Str(load_from="notebookName", dump_to="notebookName")
Expand Down
12 changes: 6 additions & 6 deletions gradient/cli/notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ def notebook_metrics():
"--clusterId",
"cluster_id",
type=str,
required=True,
help="Cluster ID",
cls=common.GradientOption,
)
@click.option(
"--machineType",
"vm_type_label",
"machine_type",
required=True,
type=str,
help="Virtual Machine type label e.g. P5000",
cls=common.GradientOption,
Expand All @@ -49,7 +49,7 @@ def notebook_metrics():
)
@click.option(
"--container",
"container_name",
"container",
type=str,
help="Container name",
cls=common.GradientOption,
Expand Down Expand Up @@ -77,7 +77,7 @@ def notebook_metrics():
)
@click.option(
"--command",
"default_entrypoint",
"command",
type=str,
help="Command (executed as `/bin/sh -c 'YOUR COMMAND'`)",
cls=common.GradientOption,
Expand Down Expand Up @@ -143,7 +143,8 @@ def create_notebook(api_key, options_file, **notebook):
)
@click.option(
"--machineType",
"vm_type_label",
"machine_type",
required=True,
type=str,
help="Virtual Machine type label e.g. P5000",
cls=common.GradientOption,
Expand All @@ -152,7 +153,6 @@ def create_notebook(api_key, options_file, **notebook):
"--clusterId",
"cluster_id",
type=str,
required=True,
help="Cluster ID",
cls=common.GradientOption,
)
Expand Down
3 changes: 1 addition & 2 deletions tests/config_files/notebooks_create.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
apiKey: some_key
clusterId: 321
container: "jupyter/notebook"
command: "some_entrypoint"
command: some_entrypoint
containerUser: some_container_user
defaultEntrypoint: some_entrypoint
isPreemptible: true
name: some_notebook_name
registryPassword: some_password
Expand Down
14 changes: 7 additions & 7 deletions tests/functional/test_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class TestNotebooksCreate(object):
"--clusterId", "321"
]
EXPECTED_REQUEST_JSON = {
"vmTypeLabel": "P5000",
"containerName": "jupyter/notebook",
"machineType": "P5000",
"container": "jupyter/notebook",
"clusterId": "321",
'isPreemptible': False,
'isPublic': False,
Expand All @@ -68,7 +68,7 @@ class TestNotebooksCreate(object):
"jobId": 20163,
"isPublic": False,
"id": 1811,
"containerName": "jupyter/notebook",
"container": "jupyter/notebook",
}
EXPECTED_STDOUT = "Created new notebook with id: some_id\n" \
"https://www.paperspace.com/some_namespace/notebook/prg284tu2\n"
Expand Down Expand Up @@ -97,13 +97,13 @@ class TestNotebooksCreate(object):
"--isPreemptible",
]
EXPECTED_REQUEST_JSON_WITH_ALL_OPTIONS = {
"vmTypeLabel": "P5000",
"containerName": "jupyter/notebook",
"machineType": "P5000",
"container": "jupyter/notebook",
"clusterId": "321",
"name": "some_notebook_name",
"registryUsername": "some_username",
"registryPassword": "some_password",
"defaultEntrypoint": "c29tZV9lbnRyeXBvaW50",
"command": "c29tZV9lbnRyeXBvaW50",
"containerUser": "some_container_user",
"shutdownTimeout": 8,
"isPreemptible": True,
Expand Down Expand Up @@ -320,7 +320,7 @@ class TestNotebooksStart(object):
]
EXPECTED_REQUEST_JSON = {
"notebookId": "n123",
"vmTypeLabel": "c5.xlarge",
"machineType": "c5.xlarge",
"clusterId": "cl123",
"isPreemptible": False,
}
Expand Down
7 changes: 7 additions & 0 deletions unset-env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
unset PAPERSPACE_API_KEY
unset PAPERSPACE_WEB_URL
unset PAPERSPACE_CONFIG_HOST
unset PAPERSPACE_CONFIG_LOG_HOST
unset PAPERSPACE_CONFIG_EXPERIMENTS_HOST
unset PAPERSPACE_CONFIG_EXPERIMENTS_HOST_V2
unset PAPERSPACE_CONFIG_SERVICE_HOST