@@ -4,11 +4,12 @@ class DSSNotebook(object):
44 """
55 A Python/R/Scala notebook on the DSS instance
66 """
7- def __init__ (self , client , project_key , notebook_name , state = None ):
7+ def __init__ (self , client , project_key , notebook_name , state = None , content = None ):
88 self .client = client
99 self .project_key = project_key
1010 self .notebook_name = notebook_name
1111 self .state = state
12+ self .content = content
1213 self .state_is_peek = True
1314
1415 def unload (self , session_id = None ):
@@ -27,14 +28,19 @@ def unload(self, session_id=None):
2728 raise Exception ("Several sessions of the notebook are running, choose one" )
2829 else :
2930 session_id = state ['activeSessions' ][0 ].get ('sessionId' , None )
30- return self .client ._perform_json ("DELETE" , "/projects/%s/notebooks/" % self .project_key , params = {'notebookName' : self .notebook_name , 'sessionId' : session_id })
31+ return self .client ._perform_json ("DELETE" ,
32+ "/projects/%s/jupyter-notebooks/%s/sessions/%s" % (self .project_key , self .notebook_name , session_id ))
3133
3234 def get_state (self ):
3335 """
3436 Get the status of the notebook
3537 """
36- if self .state is None :
37- self .state = self .client ._perform_json ("GET" , "/projects/%s/notebooks/" % self .project_key , params = {'notebookName' : self .notebook_name })
38+ notebook_list = self .client ._perform_json ("GET" ,
39+ "/projects/%s/jupyter-notebooks/" % self .project_key ,
40+ params = {"active" : False })
41+ for notebook in notebook_list :
42+ if notebook .get ("name" ) == self .notebook_name :
43+ self .state = notebook
3844 return self .state
3945
4046 def get_sessions (self ):
@@ -48,6 +54,30 @@ def get_sessions(self):
4854 raise Exception ("Notebook isn't running" )
4955 return state ['activeSessions' ]
5056
57+ def get_content (self ):
58+ """
59+ Get the content of this notebook (metadata, cells, nbformat)
60+ """
61+ if self .content is None :
62+ self .content = self .client ._perform_json ("GET" ,
63+ "/projects/%s/jupyter-notebooks/%s" % (self .project_key , self .notebook_name ))
64+ return self .content
65+
66+ def save (self ):
67+ """
68+ Save the content of this notebook
69+ """
70+ return self .client ._perform_json ("PUT" ,
71+ "/projects/%s/jupyter-notebooks/%s" % (self .project_key , self .notebook_name ),
72+ body = self .content )
73+
74+ def delete (self ):
75+ """
76+ Delete this jupyter notebook and stop all of its active sessions.
77+ """
78+ return self .client ._perform_json ("DELETE" ,
79+ "/projects/%s/jupyter-notebooks/%s" % (self .project_key , self .notebook_name ))
80+
5181 ########################################################
5282 # Discussions
5383 ########################################################
0 commit comments