Add resources form
This commit is contained in:
parent
d60ea89761
commit
2678801d93
4 changed files with 127 additions and 3 deletions
|
@ -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/
|
||||
|
|
36
src/glicid_spawner/resources.py
Normal file
36
src/glicid_spawner/resources.py
Normal file
|
@ -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),
|
||||
]
|
|
@ -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
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<div class="form-horizontal">
|
||||
<div class="form-group">
|
||||
<label for="username" class="col-sm-3 control-label">Username:</label>
|
||||
<label class="col-sm-3 control-label">Username:</label>
|
||||
<div class="col-sm-9">
|
||||
<input class="form-control" name="username" type="text" placeholder="{{username}}" disabled>
|
||||
<div class="form-control-static">{{ username }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
@ -10,9 +10,69 @@
|
|||
<div class="col-sm-9">
|
||||
<select class="form-control" name="python-env">
|
||||
{%- for pyenv in python_envs -%}
|
||||
<option value="{{pyenv.path}}">{{pyenv.name}} ({{pyenv.scope | upper}})</option>
|
||||
<option value="{{ pyenv.path }}">{{ pyenv.name }} ({{ pyenv.scope | upper }})</option>
|
||||
{% endfor -%}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="cpu" class="col-sm-3 control-label">CPU:</label>
|
||||
<div class="col-sm-9">
|
||||
{%- for cpu in cpu_available -%}
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="cpu"
|
||||
value="cpu-{{loop.index0}}"
|
||||
data-max-duration="{{cpu.max_duration}}"
|
||||
{%- if loop.first -%}checked{%- endif -%}
|
||||
> {{ cpu.description }}
|
||||
</label>
|
||||
{% endfor -%}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="ram" class="col-sm-3 control-label">Memory:</label>
|
||||
<div class="col-sm-9">
|
||||
{%- for ram in ram_available -%}
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="ram"
|
||||
value="ram-{{loop.index0}}"
|
||||
data-max-duration="{{ram.max_duration}}"
|
||||
{%- if loop.first -%}checked{%- endif -%}
|
||||
> {{ ram.description }} GB
|
||||
</label>
|
||||
{% endfor -%}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="gpu" class="col-sm-3 control-label">GPU:</label>
|
||||
<div class="col-sm-9">
|
||||
{%- for gpu in gpu_available -%}
|
||||
<label class="radio-inline">
|
||||
<input type="radio" name="gpu"
|
||||
value="gpu-{{loop.index0}}"
|
||||
data-max-duration="{{gpu.max_duration}}"
|
||||
{%- if loop.first -%}checked{%- endif -%}
|
||||
> {{ gpu.description }}
|
||||
</label>
|
||||
{% endfor -%}
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-3 control-label">Session duration:</label>
|
||||
<div class="col-sm-9">
|
||||
<div class="form-control-static"><span id="time-max-duration">24</span> h</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var $reservations_dropdown = $("#time-max-duration");
|
||||
|
||||
$('input[type=radio]').change(function() {
|
||||
var cpu = $('input[name=cpu]:checked').data('max-duration');
|
||||
var ram = $('input[name=ram]:checked').data('max-duration');
|
||||
var gpu = $('input[name=gpu]:checked').data('max-duration');
|
||||
|
||||
$reservations_dropdown.text(Math.min(cpu, ram, gpu));
|
||||
})
|
||||
</script>
|
||||
|
|
Loading…
Add table
Reference in a new issue