-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from cmd-ntrf/remote_port
Select singleserver port number on remote host
- Loading branch information
Showing
7 changed files
with
67 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .batchspawner import * | ||
from . import api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import json | ||
from tornado import web | ||
from jupyterhub.apihandlers import APIHandler, default_handlers | ||
|
||
class BatchSpawnerAPIHandler(APIHandler): | ||
@web.authenticated | ||
def post(self): | ||
"""POST set user's spawner port number""" | ||
user = self.get_current_user() | ||
data = self.get_json_body() | ||
port = int(data.get('port', 0)) | ||
user.spawner.current_port = port | ||
self.finish(json.dumps({"message": "BatchSpawner port configured"})) | ||
self.set_status(201) | ||
|
||
default_handlers.append((r"/api/batchspawner", BatchSpawnerAPIHandler)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from jupyterhub.singleuser import SingleUserNotebookApp | ||
from jupyterhub.utils import random_port, url_path_join | ||
from traitlets import default | ||
|
||
class BatchSingleUserNotebookApp(SingleUserNotebookApp): | ||
@default('port') | ||
def _port(self): | ||
return random_port() | ||
|
||
def start(self): | ||
# Send Notebook app's port number to remote Spawner | ||
self.hub_auth._api_request(method='POST', | ||
url=url_path_join(self.hub_api_url, 'batchspawner'), | ||
json={'port' : self.port}) | ||
super().start() | ||
|
||
def main(argv=None): | ||
return BatchSingleUserNotebookApp.launch_instance(argv) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from batchspawner.singleuser import main | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters