-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathnotebook.py
82 lines (65 loc) · 2.94 KB
/
notebook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from .discussion import DSSObjectDiscussions
class DSSNotebook(object):
"""
A Python/R/Scala notebook on the DSS instance.
.. attention::
Deprecated. Use :class:`dataikuapi.dss.jupyternotebook.DSSJupyterNotebook`
"""
def __init__(self, client, project_key, notebook_name, state=None):
self.client = client
self.project_key = project_key
self.notebook_name = notebook_name
self.state = state
self.state_is_peek = True
def unload(self, session_id=None):
"""
Stop this Jupyter notebook and release its resources.
.. attention::
Deprecated. Use :class:`dataikuapi.dss.jupyternotebook.DSSJupyterNotebook`
"""
state = self.get_state()
if state is None:
raise Exception("Notebook isn't running")
if state.get('activeSessions', None) is None:
raise Exception("Notebook isn't running")
if len(state['activeSessions']) == 0:
raise Exception("Notebook isn't running")
if session_id is None:
if len(state['activeSessions']) > 1:
raise Exception("Several sessions of the notebook are running, choose one")
else:
session_id = state['activeSessions'][0].get('sessionId', None)
return self.client._perform_json("DELETE", "/projects/%s/notebooks/" % self.project_key, params={'notebookName' : self.notebook_name, 'sessionId' : session_id})
def get_state(self):
"""
Get the metadata associated to this Jupyter notebook.
.. attention::
Deprecated. Use :class:`dataikuapi.dss.jupyternotebook.DSSJupyterNotebook`
"""
if self.state is None:
self.state = self.client._perform_json("GET", "/projects/%s/notebooks/" % self.project_key, params={'notebookName' : self.notebook_name})
return self.state
def get_sessions(self):
"""
Get the list of running sessions of this Jupyter notebook.
.. attention::
Deprecated. Use :class:`dataikuapi.dss.jupyternotebook.DSSJupyterNotebook`
"""
state = self.get_state()
if state is None:
raise Exception("Notebook isn't running")
if state.get('activeSessions', None) is None:
raise Exception("Notebook isn't running")
return state['activeSessions']
########################################################
# Discussions
########################################################
def get_object_discussions(self):
"""
Get a handle to manage discussions on the notebook.
.. attention::
Deprecated. Use :class:`dataikuapi.dss.jupyternotebook.DSSJupyterNotebook`
:return: the handle to manage discussions
:rtype: :class:`dataikuapi.dss.discussion.DSSObjectDiscussions`
"""
return DSSObjectDiscussions(self.client, self.project_key, "JUPYTER_NOTEBOOK", self.notebook_name)