Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show human readable value for mem and cpu limits #16

Merged
merged 2 commits into from
May 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ Just like on [Binder](https://mybinder.org), new environments can be added by cl

Once ready, the environments can be selected from the JupyterHub spawn page:

![select-env](https://user-images.githubusercontent.com/591645/80963143-abb9fa80-8e0e-11ea-94c1-ddd7962f7283.png)
![select-env](https://user-images.githubusercontent.com/591645/81152248-10e22d00-8f82-11ea-9b5f-5831d8f7d085.png)

### Extra documentation

18 changes: 16 additions & 2 deletions tljh_repo2docker/__init__.py
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
from dockerspawner import DockerSpawner
from jinja2 import Environment, BaseLoader
from jupyter_client.localinterfaces import public_ips
from jupyterhub.traitlets import ByteSpecification
from tljh.hooks import hookimpl
from tljh.configurer import load_config, CONFIG_FILE
from tornado.ioloop import IOLoop
@@ -109,10 +110,23 @@ async def get_options_form(self):
Override the default form to handle the case when there is only one image.
"""
images = await self.list_images()

# make default limits human readable
default_mem_limit = self.mem_limit
if isinstance(default_mem_limit, (float, int)):
# default memory unit is in GB
default_mem_limit /= ByteSpecification.UNIT_SUFFIXES['G']
if float(default_mem_limit).is_integer():
default_mem_limit = int(default_mem_limit)

default_cpu_limit = self.cpu_limit
if default_cpu_limit and float(default_cpu_limit).is_integer():
default_cpu_limit = int(default_cpu_limit)

# add memory and cpu limits
for image in images:
image['mem_limit'] = image['mem_limit'] or self.mem_limit
image['cpu_limit'] = image['cpu_limit'] or self.cpu_limit
image['mem_limit'] = image['mem_limit'] or default_mem_limit
image['cpu_limit'] = image['cpu_limit'] or default_cpu_limit

image_form_template = Environment(loader=BaseLoader).from_string(self.image_form_template)
return image_form_template.render(image_list=images)