From fb25e8f2f146c0e2bbd8895304b722f36a892005 Mon Sep 17 00:00:00 2001 From: RobinFrcd Date: Fri, 20 Oct 2017 20:16:33 +0200 Subject: [PATCH 1/3] Add user specific quotas user_without_quotas will overwrite mem_limit/cpu_limit. Users in this list will have unlimited RAM and CPU. special_user_quotas will overwrite mem_limit and cpu_limit for a specific user. It is possible to set mem_limit OR/AND cpu_limit. user_without_quotas is stronger than special_user_quotas. --- systemdspawner/systemdspawner.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/systemdspawner/systemdspawner.py b/systemdspawner/systemdspawner.py index 2f4ada1..455cace 100644 --- a/systemdspawner/systemdspawner.py +++ b/systemdspawner/systemdspawner.py @@ -3,7 +3,7 @@ import time import subprocess import shlex -from traitlets import Bool, Int, Unicode, List +from traitlets import Bool, Int, Unicode, List, Dict, Set from tornado import gen from jupyterhub.spawner import Spawner @@ -70,6 +70,21 @@ class SystemdSpawner(Spawner): """ ).tag(config=True) + users_without_quotas = Set( + None, + allow_none=True, + help=''' + Set of users that will have unlimited mem_limit and cpu_limit, it will overwrite special_user_quotas even if + it's set for the user. + ''' + ).tag(config=True) + + special_user_quotas = Dict( + None, + allow_none=True, + help='Dict with users as key and cpu_limit/mem_limit as value. It will overwrite mem_limit/cpu_limit.' + ).tag(config=True) + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # All traitlets configurables are configured by now @@ -180,6 +195,17 @@ def start(self): cmd.append('--setenv=SHELL={shell}'.format(shell=self.default_shell)) + if self.users_without_quotas and self.user.name in self.users_without_quotas: + # If users_without_quotas is set for the user, it will overwrite mem_limit and cpu_limit + self.mem_limit = None + self.cpu_limit = None + elif self.special_user_quotas and self.user.name in self.special_user_quotas: + # If the user has a specific value for mem_limit or cpu_limit, it will overwrite the default value + if 'mem_limit' in self.special_user_quotas[self.user.name]: + self.mem_limit = self.special_user_quotas[self.user.name]['mem_limit'] + if 'cpu_limit' in self.special_user_quotas[self.user.name]: + self.cpu_limit = self.special_user_quotas[self.user.name]['cpu_limit'] + if self.mem_limit is not None: # FIXME: Detect & use proper properties for v1 vs v2 cgroups cmd.extend([ From 7a145cabda2833a076614d32ae80277b76434ecc Mon Sep 17 00:00:00 2001 From: Robin Fourcade Date: Mon, 23 Oct 2017 11:04:27 +0200 Subject: [PATCH 2/3] Remove unused imports --- systemdspawner/systemdspawner.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/systemdspawner/systemdspawner.py b/systemdspawner/systemdspawner.py index 455cace..460ad6f 100644 --- a/systemdspawner/systemdspawner.py +++ b/systemdspawner/systemdspawner.py @@ -1,9 +1,8 @@ import os import pwd -import time import subprocess import shlex -from traitlets import Bool, Int, Unicode, List, Dict, Set +from traitlets import Bool, Unicode, List, Dict, Set from tornado import gen from jupyterhub.spawner import Spawner From 0e292724e176fcd60384297375aafa52c031bb26 Mon Sep 17 00:00:00 2001 From: Robin Fourcade Date: Mon, 23 Oct 2017 11:05:10 +0200 Subject: [PATCH 3/3] Remove blank line --- systemdspawner/systemdspawner.py | 1 - 1 file changed, 1 deletion(-) diff --git a/systemdspawner/systemdspawner.py b/systemdspawner/systemdspawner.py index 460ad6f..2559dd6 100644 --- a/systemdspawner/systemdspawner.py +++ b/systemdspawner/systemdspawner.py @@ -97,7 +97,6 @@ def __init__(self, *args, **kwargs): self.log.debug('user:%s Initialized spawner with unit %s', self.user.name, self.unit_name) - def _expand_user_vars(self, string): """ Expand user related variables in a given string