Hello everyone,
I am a newbie in using Jupyterhub, and I am trying to understand how to parse parameters to the Spawner. More specifically, I would like to read cpu_lim
and mem_lim
through parameters parsed from options_form
.
I came out with a test configuration file, where I am trying to parse only mem_lim
:
import shlex
from dockerspawner import DockerSpawner
c = get_config()
class DemoFormSpawner(DockerSpawner):
default_memo_lim = "1G"
def _options_form_default(self):
return """
<div class="form-group">
<label for="args">Extra notebook CLI arguments</label>
<input name="args" class="form-control"
placeholder="e.g. --debug"></input>
</div>
<div class="form-group">
<label for="memo_lim">Memory Limit:</label>
<input type="text" id="memo_lim" name="memo_lim"></input>
</div>
"""
def options_from_form(self, formdata):
self.log.debug("Executing options_from_form")
options = {}
memo_lim = formdata.get('memo_lim', [''])[0].strip()
options["memo_lim"] = shlex.split(memo_lim) if memo_lim else []
print("MEM Limit:", options["memo_lim"])
arg_s = formdata.get('args', [''])[0].strip()
if arg_s:
options['argv'] = shlex.split(arg_s)
print("Extra CLI Arguments:", options['argv'])
return options
def get_args(self):
"""Return arguments to pass to the notebook server"""
print(self.user_options)
argv = super().get_args()
if self.user_options.get('argv'):
argv.extend(self.user_options['argv'])
return argv
def get_memo(self):
memo_lim = self.default_memo_lim
if self.user_options.get('memo_lim'):
memo_lim.update(self.user_options['memo_lim'])
return memo_lim
c.JupyterHub.spawner_class = DemoFormSpawner
spawner_instance = c.JupyterHub.spawner_class()
memo_limit = spawner_instance.get_mem_limit()
When running the script, I am noticing that spawner_instance.get_mem_limit()
is called before options_from_form
.
Few questions:
- Is it actually possible to perform these tasks using the DockerSpawner?
- If it is possible, how can I parse
memo_lim
fromCustoDockerSpawner
to the variable calledmemory_limit
? - Are there alternative way that I am not aware of?
Thanks in advance for any feedback!