can remove quota group from web page

can add quota with just one click
This commit is contained in:
zhong 2016-04-06 14:43:16 +08:00
parent 402fcf8c91
commit d409d2358e
5 changed files with 62 additions and 6 deletions

View File

@ -422,7 +422,10 @@ class DockletHttpHandler(http.server.BaseHTTPRequestHandler):
result = G_usermgr.register(user = user, cur_user = cur_user) result = G_usermgr.register(user = user, cur_user = cur_user)
self.response(200, result) self.response(200, result)
elif cmds[1] == 'groupadd': 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) self.response(200, result)
elif cmds[1] == 'data': elif cmds[1] == 'data':
logger.info("handle request: user/data") logger.info("handle request: user/data")

View File

@ -663,8 +663,8 @@ class userManager:
@administration_required @administration_required
def groupadd(*args, **kwargs): def groupadd(*args, **kwargs):
name = kwargs.get('name', None) form = kwargs.get('form')
if (name == None): if (form.getvalue("name") == None):
return {"success":'false', "reason": "Empty group name"} return {"success":'false', "reason": "Empty group name"}
#group_new = UserGroup(name) #group_new = UserGroup(name)
#db.session.add(group_new) #db.session.add(group_new)
@ -672,7 +672,24 @@ class userManager:
groupfile = open(fspath+"/global/group",'r') groupfile = open(fspath+"/global/group",'r')
groups = json.loads(groupfile.read()) groups = json.loads(groupfile.read())
groupfile.close() 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 = open(fspath+"/global/group",'w')
groupfile.write(json.dumps(groups)) groupfile.write(json.dumps(groups))
groupfile.close() groupfile.close()

View File

@ -52,6 +52,22 @@
<label>Group Name</label> <label>Group Name</label>
<input type = "text" placeholder="Enter GroupName" class="form-control" name="name" id="mymyname"> <input type = "text" placeholder="Enter GroupName" class="form-control" name="name" id="mymyname">
</div> </div>
<div class="form-group">
<label>CPU Quota</label>
<input type = "text" placeholder="Enter CPU Quota" class="form-control" name="cpu" id="myCpu" value="100000">
</div>
<div class="form-group">
<label>Memory Quota</label>
<input type="text" placeholder="Enter Memory Quota" class="form-control" name="memory" id="myMemory" value="2000">
</div>
<div class="form-group">
<label>Image Quantity</label>
<input type = "text" placeholder="Enter Image Quantity" class="form-control" name="image" id="myImage" value="10">
</div>
<div class="form-group">
<label>Life Cycle</label>
<input type = "text" placeholder="Enter Life Cycle" class="form-control" name="lifecycle" id="myLifecycle" value="24">
</div>
</form> </form>
@ -140,7 +156,8 @@
"columnDefs": [ "columnDefs": [
{ {
"render": function ( data, type, row ) { "render": function ( data, type, row ) {
return '<a class="btn btn-info btn-sm" data-toggle="modal" data-target="#ModifyGroupModal" onClick="javascript:setFormGroup('+ "'" + row[0] + "'" + ');">' + 'Edit' + '</a>'; return '<a class="btn btn-info btn-sm" data-toggle="modal" data-target="#ModifyGroupModal" onClick="javascript:setFormGroup('+ "'" + row[0] + "'" + ');">' + 'Edit' + '</a>'
+ '<a class="btn btn-danger btn-sm" href="/group/delete/' + row[0] +'">' + 'Delete' + '</a>';
}, },
"targets": 5 "targets": 5
}, },

View File

@ -20,7 +20,7 @@ from webViews.log import logger
from flask import Flask, request, session, render_template, redirect, send_from_directory, make_response, url_for, abort from flask import Flask, request, session, render_template, redirect, send_from_directory, make_response, url_for, abort
from webViews.dashboard import dashboardView from webViews.dashboard import dashboardView
from webViews.user.userlist import userlistView, useraddView, usermodifyView, groupaddView, userdataView, userqueryView from webViews.user.userlist import userlistView, useraddView, usermodifyView, groupaddView, groupdelView, userdataView, userqueryView
from webViews.user.userinfo import userinfoView from webViews.user.userinfo import userinfoView
from webViews.user.userActivate import userActivateView from webViews.user.userActivate import userActivateView
from webViews.user.grouplist import grouplistView, groupqueryView, groupdetailView, groupmodifyView from webViews.user.grouplist import grouplistView, groupqueryView, groupdetailView, groupmodifyView
@ -328,6 +328,12 @@ def usermodify():
def groupadd(): def groupadd():
return groupaddView.as_view() return groupaddView.as_view()
@app.route("/group/delete/<groupname>/", methods=['POST', 'GET'])
@administration_required
def groupdel(groupname):
groupdelView.groupname = groupname
return groupdelView.as_view()
@app.route("/user/info/", methods=['GET', 'POST']) @app.route("/user/info/", methods=['GET', 'POST'])
@login_required @login_required
def userinfo(): def userinfo():

View File

@ -54,3 +54,16 @@ class groupaddView(normalView):
def post(self): def post(self):
dockletRequest.post('/user/groupadd', request.form) dockletRequest.post('/user/groupadd', request.form)
return redirect('/admin/') return redirect('/admin/')
class groupdelView(normalView):
@classmethod
def post(self):
data = {
"name" : self.groupname,
}
dockletRequest.post('/user/groupdel', data)
return redirect('/admin/')
@classmethod
def get(self):
return self.post()