diff --git a/src/httprest.py b/src/httprest.py index ff25afa..cffcc20 100755 --- a/src/httprest.py +++ b/src/httprest.py @@ -433,7 +433,7 @@ class DockletHttpHandler(http.server.BaseHTTPRequestHandler): result = G_usermgr.quotaadd(form = form, cur_user = cur_user) self.response(200, result) elif cmds[1] == 'chdefault': - result = G_usermgr.change_default_group(form = form) + result = G_usermgr.change_default_group(form = form, cur_user = cur_user) self.response(200, result) elif cmds[1] == 'groupdel': result = G_usermgr.groupdel(name = form.getvalue('name', None), cur_user = cur_user) diff --git a/src/userManager.py b/src/userManager.py index 7cf90ac..1137c61 100755 --- a/src/userManager.py +++ b/src/userManager.py @@ -149,14 +149,12 @@ class userManager: if not os.path.exists(fspath+"/global/sys/quota"): groupfile = open(fspath+"/global/sys/quota",'w') groups = [] - groups.append({'name':'root', 'quotas':{ 'cpu':'4', 'disk':'2000', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8' }}) - groups.append({'name':'admin', 'quotas':{'cpu':'4', 'disk':'2000', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8'}}) - groups.append({'name':'primary', 'quotas':{'cpu':'4', 'disk':'2000', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8'}}) - groups.append({'name':'fundation', 'quotas':{'cpu':'4', 'disk':'2000', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8'}}) + groups.append({'name':'root', 'quotas':{ 'cpu':'4', 'disk':'2000', 'data':'100', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8' }}) + groups.append({'name':'admin', 'quotas':{'cpu':'4', 'disk':'2000', 'data':'100', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8'}}) + groups.append({'name':'primary', 'quotas':{'cpu':'4', 'disk':'2000', 'data':'100', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8'}}) + groups.append({'name':'fundation', 'quotas':{'cpu':'4', 'disk':'2000', 'data':'100', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8'}}) groupfile.write(json.dumps(groups)) groupfile.close() - else: - pass if not os.path.exists(fspath+"/global/sys/quotainfo"): quotafile = open(fspath+"/global/sys/quotainfo",'w') quotas = {} @@ -165,22 +163,12 @@ class userManager: quotas['quotainfo'].append({'name':'cpu', 'hint':'the cpu quota, number of cores, e.g. 4'}) quotas['quotainfo'].append({'name':'memory', 'hint':'the memory quota, number of MB , e.g. 4000'}) quotas['quotainfo'].append({'name':'disk', 'hint':'the disk quota, number of MB, e.g. 4000'}) + quotas['quotainfo'].append({'name':'data', 'hint':'the quota of data space, number of GB, e.g. 100'}) quotas['quotainfo'].append({'name':'image', 'hint':'how many images the user can save, e.g. 10'}) quotas['quotainfo'].append({'name':'idletime', 'hint':'will stop cluster after idletime, number of hours, e.g. 24'}) quotas['quotainfo'].append({'name':'vnode', 'hint':'how many containers the user can have, e.g. 8'}) quotafile.write(json.dumps(quotas)) quotafile.close() - else: - quotafile = open(fspath+"/global/sys/quotainfo",'r') - quotas = json.loads(quotafile.read()) - quotafile.close() - if type(quotas) is list: - new_quotas = {} - new_quotas['default'] = 'fundation' - new_quotas['quotainfo'] = quotas - quotafile = open(fspath+"/global/sys/quotainfo",'w') - quotafile.write(json.dumps(new_quotas)) - quotafile.close() @@ -505,9 +493,10 @@ class userManager: quotas = json.loads(quotafile.read()) quotafile.close() quotas['default'] = default_group - quotafile = open(fspath+"/global/sys/quotainfo",'r') + quotafile = open(fspath+"/global/sys/quotainfo",'w') quotafile.write(json.dumps(quotas)) quotafile.close() + return { 'success':'true', 'action':'change default group' } @administration_required @@ -618,7 +607,10 @@ class userManager: call this method first, modify the return value which is a database row instance,then call self.register() ''' user_new = User('newuser', 'asdf1234') - user_new.user_group = 'primary' + quotafile = open(fspath+"/global/sys/quotainfo",'r') + quotas = json.loads(quotafile.read()) + quotafile.close() + user_new.user_group = quotas['default'] user_new.avatar = 'default.png' return user_new diff --git a/tools/upgrade.py b/tools/upgrade.py new file mode 100755 index 0000000..c1eeb37 --- /dev/null +++ b/tools/upgrade.py @@ -0,0 +1,43 @@ +#!/usr/bin/python3 + +import os, json + +fspath="/opt/docklet" + +def update_quotainfo(): + if not os.path.exists(fspath+"/global/sys/quotainfo"): + print("quotainfo file not exists, please run docklet to init it") + return False + quotafile = open(fspath+"/global/sys/quotainfo", 'r') + quotas = json.loads(quotafile.read()) + quotafile.close() + if type(quotas) is list: + new_quotas = {} + new_quotas['default'] = 'fundation' + new_quotas['quotainfo'] = quotas + quotas = new_quotas + print("change the type of quotafile from list to dict") + keys = [] + for quota in quotas['quotainfo']: + keys.append(quota['name']) + if 'cpu' not in keys: + quotas['quotainfo'].append({'name':'cpu', 'hint':'the cpu quota, number of cores, e.g. 4'}) + if 'memory' not in keys: + quotas['quotainfo'].append({'name':'memory', 'hint':'the memory quota, number of MB, e.g. 4000'}) + if 'disk' not in keys: + quotas['quotainfo'].append({'name':'disk', 'hint':'the disk quota, number of MB, e.g. 4000'}) + if 'data' not in keys: + quotas['quotainfo'].append({'name':'data', 'hint':'the quota of data space, number of GB, e.g. 100'}) + if 'image' not in keys: + quotas['quotainfo'].append({'name':'image', 'hint':'how many images the user can have, e.g. 8'}) + if 'idletime' not in keys: + quotas['quotainfo'].append({'name':'idletime', 'hint':'will stop cluster after idletime, number of hours, e.g. 24'}) + if 'vnode' not in keys: + quotas['quotainfo'].append({'name':'vnode', 'hint':'how many containers the user can have, e.g. 8'}) + print("quotainfo updated") + quotafile = open(fspath+"/global/sys/quotainfo", 'w') + quotafile.write(json.dumps(quotas)) + quotafile.close() + +if __name__ == '__main__': + update_quotainfo() diff --git a/web/templates/admin.html b/web/templates/admin.html index 80c728f..ab75328 100644 --- a/web/templates/admin.html +++ b/web/templates/admin.html @@ -106,7 +106,7 @@ - +
@@ -154,10 +154,14 @@ {% endfor %}