diff --git a/README.md b/README.md index 35694c6..f654550 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,6 @@ External ressources - https://gitlab.com/ifb-elixirfr/cluster/utils/slurmspawner/ - https://gitlab.com/idris-cnrs/jupyter/jupyter-jeanzay-spawner/ - https://github.com/jupyterhub/batchspawner +- https://jupyterhub.readthedocs.io/en/stable/reference/spawners.html +- https://getbootstrap.com/docs/3.4/css/ +- https://getbootstrap.com/docs/3.4/components/ diff --git a/src/glicid_spawner/resources.py b/src/glicid_spawner/resources.py new file mode 100644 index 0000000..6d833d4 --- /dev/null +++ b/src/glicid_spawner/resources.py @@ -0,0 +1,36 @@ +"""Resources module.""" + +from dataclasses import dataclass + + +@dataclass +class Resource: + """Cluster generic resource.""" + + description: str + max_duration: int + + +CPU = [ + Resource('1', 24), + Resource('2', 12), + Resource('4', 6), + Resource('8', 3), + Resource('12', 2), + Resource('24', 1), +] + +RAM = [ + Resource('4', 24), + Resource('8', 12), + Resource('16', 6), + Resource('32', 3), + Resource('48', 2), + Resource('96', 1), +] + +GPU = [ + Resource('no', 24), + Resource('A40', 2), + Resource('A100', 1), +] diff --git a/src/glicid_spawner/spawner.py b/src/glicid_spawner/spawner.py index 1d516a4..eb3cfdf 100644 --- a/src/glicid_spawner/spawner.py +++ b/src/glicid_spawner/spawner.py @@ -4,6 +4,7 @@ from batchspawner import SlurmSpawner from jinja2 import Environment, PackageLoader, select_autoescape from .pyenv import get_pyenv +from .resources import CPU, GPU, RAM class GlicidSpawner(SlurmSpawner): @@ -20,9 +21,33 @@ class GlicidSpawner(SlurmSpawner): return template.render( username=self.user.name, python_envs=get_pyenv(self.user.name), + cpu_available=CPU, + ram_available=RAM, + gpu_available=GPU, ) def options_from_form(self, formdata) -> dict: options = {} options['pyenv'] = formdata['python-env'][0] + + # Index of user resources choices + i_cpu = int(formdata['cpu'][0]) + i_ram = int(formdata['ram'][0]) + i_gpu = int(formdata['gpu'][0]) + + duration = min( + CPU[i_cpu].max_duration, + RAM[i_ram].max_duration, + GPU[i_gpu].max_duration, + ) + + # Export options + options['cpus-per-task'] = CPU[i_cpu].description + options['mem'] = RAM[i_ram] + 'GB' + + if i_gpu: + options['gres'] = 'gpu:' + GPU[i_gpu] + + options['time'] = f'{duration:02d}:00:00' + return options diff --git a/src/glicid_spawner/templates/interactive.html b/src/glicid_spawner/templates/interactive.html index 89f3003..0519d75 100644 --- a/src/glicid_spawner/templates/interactive.html +++ b/src/glicid_spawner/templates/interactive.html @@ -1,8 +1,8 @@
- +
- +
{{ username }}
@@ -10,9 +10,69 @@
+
+ +
+ {%- for cpu in cpu_available -%} + + {% endfor -%} +
+
+
+ +
+ {%- for ram in ram_available -%} + + {% endfor -%} +
+
+
+ +
+ {%- for gpu in gpu_available -%} + + {% endfor -%} +
+
+
+ +
+
24 h
+
+
+ +