Skip to content

Commit ab12fa4

Browse files
committed
forgot file
1 parent 369cb21 commit ab12fa4

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

dataikuapi/dss/notebook.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
class DSSNotebook(object):
2+
"""
3+
A Python/R/Scala notebook on the DSS instance
4+
"""
5+
def __init__(self, client, project_key, notebook_name, state=None):
6+
self.client = client
7+
self.project_key = project_key
8+
self.notebook_name = notebook_name
9+
self.state = state
10+
self.state_is_peek = True
11+
12+
def unload(self, session_id=None):
13+
"""
14+
Stop the notebook and release its resources
15+
"""
16+
state = self.get_state()
17+
if state is None:
18+
raise Exception("Notebook isn't running")
19+
if state.get('activeSessions', None) is None:
20+
raise Exception("Notebook isn't running")
21+
if len(state['activeSessions']) == 0:
22+
raise Exception("Notebook isn't running")
23+
if session_id is None:
24+
if len(state['activeSessions']) > 1:
25+
raise Exception("Several sessions of the notebook are running, choose one")
26+
else:
27+
session_id = state['activeSessions'][0].get('sessionId', None)
28+
return self.client._perform_json("DELETE", "/projects/%s/notebooks/" % self.project_key, params={'notebookName' : self.notebook_name, 'sessionId' : session_id})
29+
30+
def get_state(self):
31+
"""
32+
Get the status of the notebook
33+
"""
34+
if self.state is None:
35+
self.state = self.client._perform_json("GET", "/projects/%s/notebooks/" % self.project_key, params={'notebookName' : self.notebook_name})
36+
return self.state
37+
38+
def get_sessions(self):
39+
"""
40+
Get the list of the running sessions of this notebook
41+
"""
42+
state = self.get_state()
43+
if state is None:
44+
raise Exception("Notebook isn't running")
45+
if state.get('activeSessions', None) is None:
46+
raise Exception("Notebook isn't running")
47+
return state['activeSessions']

0 commit comments

Comments
 (0)