diff --git a/src/httprest.py b/src/httprest.py index 31f5eb1..56d6898 100755 --- a/src/httprest.py +++ b/src/httprest.py @@ -422,7 +422,10 @@ class DockletHttpHandler(http.server.BaseHTTPRequestHandler): result = G_usermgr.register(user = user, cur_user = cur_user) self.response(200, result) elif cmds[1] == 'groupadd': - result = G_usermgr.groupadd(name = form.getvalue('name', None), cur_user = cur_user) + result = G_usermgr.groupadd(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) self.response(200, result) elif cmds[1] == 'data': logger.info("handle request: user/data") diff --git a/src/userManager.py b/src/userManager.py index c04f740..c1d69b8 100755 --- a/src/userManager.py +++ b/src/userManager.py @@ -663,8 +663,8 @@ class userManager: @administration_required def groupadd(*args, **kwargs): - name = kwargs.get('name', None) - if (name == None): + form = kwargs.get('form') + if (form.getvalue("name") == None): return {"success":'false', "reason": "Empty group name"} #group_new = UserGroup(name) #db.session.add(group_new) @@ -672,7 +672,24 @@ class userManager: groupfile = open(fspath+"/global/group",'r') groups = json.loads(groupfile.read()) groupfile.close() - groups.append({'name':name, 'cpu':'100000', 'memory':'2000', 'imageQuantity':'10', 'lifeCycle':'24'}) + groups.append({'name':form.getvalue("name"), 'cpu':form.getvalue("cpu"), 'memory':form.getvalue("memory"), 'imageQuantity':form.getvalue("image"), 'lifeCycle':form.getvalue("lifecycle")}) + groupfile = open(fspath+"/global/group",'w') + groupfile.write(json.dumps(groups)) + groupfile.close() + return {"success":'true'} + + @administration_required + def groupdel(*args, **kwargs): + name = kwargs.get('name', None) + if (name == None): + return {"success":'false', "reason": "Empty group name"} + groupfile = open(fspath+"/global/group",'r') + groups = json.loads(groupfile.read()) + groupfile.close() + for group in groups: + if group['name'] == name: + groups.remove(group) + break groupfile = open(fspath+"/global/group",'w') groupfile.write(json.dumps(groups)) groupfile.close() diff --git a/web/templates/admin.html b/web/templates/admin.html index baddae8..19c016f 100644 --- a/web/templates/admin.html +++ b/web/templates/admin.html @@ -52,6 +52,22 @@ +