diff --git a/frontend/src/environments/LogDialog.tsx b/frontend/src/environments/LogDialog.tsx index dad5cc3..cddae13 100644 --- a/frontend/src/environments/LogDialog.tsx +++ b/frontend/src/environments/LogDialog.tsx @@ -34,8 +34,12 @@ function _EnvironmentLogButton(props: IEnvironmentLogButton) { const handleOpen = () => { setOpen(true); if (divRef.current) { - terminalRef.current.terminal.open(divRef.current); - terminalRef.current.fitAddon.fit(); + const {terminal, fitAddon} = terminalFactory() + terminalRef.current.terminal = terminal + terminalRef.current.fitAddon = fitAddon + + terminal.open(divRef.current); + fitAddon.fit(); const jhData = (window as any).jhdata; const baseUrl = jhData.base_url; const xsrfToken = jhData.xsrf_token; @@ -65,8 +69,8 @@ function _EnvironmentLogButton(props: IEnvironmentLogButton) { setBuilt(true); return; } - terminalRef.current.terminal.write(data.message); - terminalRef.current.fitAddon.fit(); + terminal.write(data.message); + fitAddon.fit(); }; } }; diff --git a/jupyterhub_config.py b/jupyterhub_config.py index b4aa3ab..fb63b68 100644 --- a/jupyterhub_config.py +++ b/jupyterhub_config.py @@ -23,3 +23,5 @@ user = getpass.getuser() c.Authenticator.admin_users = {user, "alice"} +c.JupyterHub.allow_named_servers = True +c.JupyterHub.ip = '0.0.0.0' \ No newline at end of file diff --git a/tljh_repo2docker/__init__.py b/tljh_repo2docker/__init__.py index 787d073..4e64338 100644 --- a/tljh_repo2docker/__init__.py +++ b/tljh_repo2docker/__init__.py @@ -13,7 +13,7 @@ from .builder import BuildHandler from .docker import list_images -from .imagesOld import ImagesHandlerOld +from .servers import ServersHandler from .images import ImagesHandler from .logs import LogsHandler @@ -197,7 +197,7 @@ def tljh_custom_jupyterhub_config(c): # register the handlers to manage the user images c.JupyterHub.extra_handlers.extend( [ - (r"environments-old", ImagesHandlerOld), + (r"servers", ServersHandler), (r"environments", ImagesHandler), (r"api/environments", BuildHandler), (r"api/environments/([^/]+)/logs", LogsHandler), diff --git a/tljh_repo2docker/imagesOld.py b/tljh_repo2docker/imagesOld.py deleted file mode 100644 index 11b91b3..0000000 --- a/tljh_repo2docker/imagesOld.py +++ /dev/null @@ -1,28 +0,0 @@ -from inspect import isawaitable -from jupyterhub.handlers.base import BaseHandler -from jupyterhub.utils import admin_only -from tornado import web - -from .docker import list_containers, list_images - - -class ImagesHandlerOld(BaseHandler): - """ - Handler to show the list of environments as Docker images - """ - - @web.authenticated - @admin_only - async def get(self): - images = await list_images() - containers = await list_containers() - result = self.render_template( - "images-old.html", - images=images + containers, - default_mem_limit=self.settings.get("default_mem_limit"), - default_cpu_limit=self.settings.get("default_cpu_limit"), - ) - if isawaitable(result): - self.write(await result) - else: - self.write(result) diff --git a/tljh_repo2docker/servers.py b/tljh_repo2docker/servers.py new file mode 100644 index 0000000..4934d14 --- /dev/null +++ b/tljh_repo2docker/servers.py @@ -0,0 +1,37 @@ +from inspect import isawaitable +from jupyterhub.handlers.base import BaseHandler +from jupyterhub.utils import admin_only +from tornado import web + +from .docker import list_containers, list_images + + +class ServersHandler(BaseHandler): + """ + Handler to show the list of servers available + """ + + @web.authenticated + async def get(self): + images = await list_images() + user = self.current_user + if user.running: + # trigger poll_and_notify event in case of a server that died + await user.spawner.poll_and_notify() + auth_state = await user.get_auth_state() + print('########', auth_state) + + result = self.render_template( + "servers.html", + images=images, + allow_named_servers=self.allow_named_servers, + named_server_limit_per_user=await self.get_current_user_named_server_limit(), + spawners=user.orm_user._orm_spawners, + default_server=user.spawner, + auth_state=auth_state + ) + + if isawaitable(result): + self.write(await result) + else: + self.write(result) diff --git a/tljh_repo2docker/templates/images-old.html b/tljh_repo2docker/templates/images-old.html deleted file mode 100644 index 848e341..0000000 --- a/tljh_repo2docker/templates/images-old.html +++ /dev/null @@ -1,170 +0,0 @@ -{% extends "page.html" %} - -{% block stylesheet %} -{{ super() }} - - -{% endblock %} - -{% block main %} - -
- - - - - - - - - - - - - - {% for image in images %} - - - - - - - - - - {% endfor %} - -
NamessRepository URLReferenceMem. Limit (GB)CPU LimitStatusAdd New
- {{ image.display_name }} - - {{ image.repo }} - - {{ image.ref }} - - {% if image.mem_limit | length %} - {{ image.mem_limit | replace("G", "") }} - {% else %} - {{ default_mem_limit | replace("G", "") }} - {%- endif %} - - {% if image.cpu_limit | length %} - {{ image.cpu_limit | replace("G", "") }} - {% else %} - {{ default_cpu_limit | replace("G", "") }} - {%- endif %} - - {% if image.status == 'building' %} - - Logs - {%- elif image.status == 'built' %} - - {%- endif %} - - {% if image.status == 'built' %} - - Remove - - {% else %} -

- The environment is under construction. This can take several minutes to complete.
- Click here to refresh. -

- {%- endif %} -
-
- -{% call modal('Adding Environment', btn_label='OK', btn_class='btn-primary adding-button') %} -
-

-
-{% endcall %} - -{% call modal('Removing Environment', btn_label='OK', btn_class='btn-primary removing-button') %} -
-

-
-{% endcall %} - -{% call modal('Remove Environment', btn_label='Remove', btn_class='btn-danger remove-button') %} - Are you sure you want to remove the following environment? -
ENV
-{% endcall %} - -{% call modal('Show Logs', btn_label='Close', btn_class='btn-primary') %} -
-{% endcall %} - -{% macro environment_modal(name, multi=False) %} -{% call modal(name, btn_class='btn-primary save-button') %} -
-
- -
- -
-
-
- -
- -
-
-
- -
- -

Example: course-python-101-B37

-

If empty, a name will be generated from the repo URL

-
-
-
- -
- -
-
-
- -
- -
-
-
- > Advanced -
- -
- -
-
-
-
- > Credentials (optional) -
- -
- -
-
-
- -
- -
-
-
-
-{% endcall %} -{% endmacro %} - -{{ environment_modal('Create Environment') }} - -{% endblock %} - -{% block script %} -{{ super() }} - -{% endblock %} diff --git a/tljh_repo2docker/templates/page.html b/tljh_repo2docker/templates/page.html index 00728c5..42cba50 100644 --- a/tljh_repo2docker/templates/page.html +++ b/tljh_repo2docker/templates/page.html @@ -2,11 +2,12 @@ {% block nav_bar_left_items %}
  • Home
  • +
  • Servers
  • Token
  • {% if user.admin %}
  • Admin
  • Environments
  • -
  • Environments Old
  • + {% if services %} {% for service in services %}
  • {{service.name}}
  • diff --git a/tljh_repo2docker/templates/servers.html b/tljh_repo2docker/templates/servers.html new file mode 100644 index 0000000..defce36 --- /dev/null +++ b/tljh_repo2docker/templates/servers.html @@ -0,0 +1,13 @@ +{% extends "page.html" %} {% block main %} +
    + +
    +{% endblock %}