default container cpu, memory and disk can be modify in admin page
This commit is contained in:
parent
64c228ea88
commit
8291643929
|
@ -608,6 +608,22 @@ def usageQuery_user(cur_user, user, form):
|
|||
result = G_usermgr.usageQuery(cur_user = cur_user)
|
||||
return json.dumps(result)
|
||||
|
||||
@app.route("/user/lxcsettingList/", methods=['POST'])
|
||||
@login_required
|
||||
def lxcsettingList_user(cur_user, user, form):
|
||||
global G_usermgr
|
||||
logger.info("handle request: user/lxcsettingList/")
|
||||
result = G_usermgr.lxcsettingList(cur_user = cur_user, form = form)
|
||||
return json.dumps(result)
|
||||
|
||||
@app.route("/user/chlxcsetting/", methods=['POST'])
|
||||
@login_required
|
||||
def chlxcsetting_user(cur_user, user, form):
|
||||
global G_usermgr
|
||||
logger.info("handle request: user/chlxcsetting/")
|
||||
result = G_usermgr.chlxcsetting(cur_user = cur_user, form = form)
|
||||
return json.dumps(result)
|
||||
|
||||
@app.route("/notification/list/", methods=['POST'])
|
||||
@login_required
|
||||
def list_notifications(cur_user, user, form):
|
||||
|
@ -861,6 +877,8 @@ if __name__ == '__main__':
|
|||
etcdclient.deldir("_lock")
|
||||
|
||||
G_usermgr = userManager.userManager('root')
|
||||
if mode == "new":
|
||||
G_usermgr.initUsage()
|
||||
G_notificationmgr = notificationmgr.NotificationMgr()
|
||||
|
||||
clusternet = env.getenv("CLUSTER_NET")
|
||||
|
|
|
@ -628,9 +628,9 @@ class userManager:
|
|||
return True
|
||||
|
||||
def initUsage(*args, **kwargs):
|
||||
"""
|
||||
init the usage info when start docklet with init mode
|
||||
"""
|
||||
"""
|
||||
init the usage info when start docklet with init mode
|
||||
"""
|
||||
usages = UserUsage.query.all()
|
||||
for usage in usages:
|
||||
usage.cpu = "0"
|
||||
|
@ -920,6 +920,25 @@ class userManager:
|
|||
groupfile.write(json.dumps(groups))
|
||||
groupfile.close()
|
||||
return {"success":'true'}
|
||||
|
||||
@administration_required
|
||||
def lxcsettingList(*args, **kwargs):
|
||||
lxcsettingfile = open(fspath+"/global/sys/lxc.default", 'r')
|
||||
lxcsetting = json.loads(lxcsettingfile.read())
|
||||
lxcsettingfile.close()
|
||||
return {"success": 'true', 'data':lxcsetting}
|
||||
|
||||
@administration_required
|
||||
def chlxcsetting(*args, **kwargs):
|
||||
form = kwargs['form']
|
||||
lxcsetting = {}
|
||||
lxcsetting['cpu'] = form['lxcCpu']
|
||||
lxcsetting['memory'] = form['lxcMemory']
|
||||
lxcsetting['disk'] = form['lxcDisk']
|
||||
lxcsettingfile = open(fspath+"/global/sys/lxc.default", 'w')
|
||||
lxcsettingfile.write(json.dumps(lxcsetting))
|
||||
lxcsettingfile.close()
|
||||
return {"success": 'true'}
|
||||
|
||||
def queryForDisplay(*args, **kwargs):
|
||||
'''
|
||||
|
|
|
@ -202,6 +202,42 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<div class="box box-info">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">Container Default Setting</h3>
|
||||
|
||||
<div class="box-tools pull-right">
|
||||
<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
|
||||
</button>
|
||||
<button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
<form id="chlxcsetting" class="form-horizontal" action="/quota/chlxcsetting/" method="POST">
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-2">CPU</label>
|
||||
<div class="col-sm-8"><input type="number" class="form-control" name="lxcCpu" id="lxcCpu" value={{lxcsetting['cpu']}} />CORE</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-2">MEMORY</label>
|
||||
<div class="col-sm-8"><input type="number" class="form-control" name="lxcMemory" id="lxcMemory" value={{lxcsetting['memory']}} />MB</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-2">DISK</label>
|
||||
<div class="col-sm-8"><input type="number" class="form-control" name="lxcDisk" id="lxcDisk" value={{lxcsetting['disk']}} />MB</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-sm-4 col-sm-offset-2"><button class="btn btn-primary" type="submit">Modify</button></div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% for field in ["docklet"] %}
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
|
|
|
@ -331,6 +331,11 @@ def quotaadd():
|
|||
def chdefault():
|
||||
return chdefaultView.as_view()
|
||||
|
||||
@app.route("/quota/chlxcsetting/", methods=['POST'])
|
||||
@administration_required
|
||||
def chlxcsetting():
|
||||
return chlxcsettingView.as_view()
|
||||
|
||||
@app.route("/group/add/", methods=['POST'])
|
||||
@administration_required
|
||||
def groupadd():
|
||||
|
|
|
@ -14,7 +14,8 @@ class adminView(normalView):
|
|||
quotas = result["quotas"]
|
||||
defaultgroup = result["default"]
|
||||
parms = dockletRequest.post('/system/parmList/')
|
||||
return self.render(self.template_path, groups = groups, quotas = quotas, defaultgroup = defaultgroup, parms = parms)
|
||||
lxcsetting = dockletRequest.post('/user/lxcsettingList/')['data']
|
||||
return self.render(self.template_path, groups = groups, quotas = quotas, defaultgroup = defaultgroup, parms = parms, lxcsetting = lxcsetting)
|
||||
|
||||
class groupaddView(normalView):
|
||||
@classmethod
|
||||
|
@ -64,6 +65,12 @@ class chdefaultView(normalView):
|
|||
dockletRequest.post('/user/chdefault/', request.form)
|
||||
return redirect('/admin/')
|
||||
|
||||
class chlxcsettingView(normalView):
|
||||
@classmethod
|
||||
def post(self):
|
||||
dockletRequest.post('/user/chlxcsetting/', request.form)
|
||||
return redirect('/admin/')
|
||||
|
||||
class groupdelView(normalView):
|
||||
@classmethod
|
||||
def post(self):
|
||||
|
|
|
@ -15,27 +15,31 @@ class addClusterView(normalView):
|
|||
result = dockletRequest.post("/user/usageQuery/")
|
||||
quota = result.get("quota")
|
||||
usage = result.get("usage")
|
||||
defaultcpu = int(quota['cpu']) - int(usage['cpu'])
|
||||
defaultmemory = int(quota['memory']) - int(usage['memory'])
|
||||
defaultdisk = int(quota['disk']) - int(usage['disk'])
|
||||
if defaultcpu >= 4:
|
||||
defaultcpu = "4"
|
||||
elif defaultcpu <= 0:
|
||||
default = result.get("default")
|
||||
restcpu = int(quota['cpu']) - int(usage['cpu'])
|
||||
restmemory = int(quota['memory']) - int(usage['memory'])
|
||||
restdisk = int(quota['disk']) - int(usage['disk'])
|
||||
if restcpu >= int(default['cpu']):
|
||||
defaultcpu = default['cpu']
|
||||
elif restcpu <= 0:
|
||||
defaultcpu = "0"
|
||||
else:
|
||||
defaultcpu = str(defaultcpu)
|
||||
if defaultmemory >= 2000:
|
||||
defaultmemory = "2000"
|
||||
elif defaultmemory <= 0:
|
||||
defaultcpu = str(restcpu)
|
||||
|
||||
if restmemory >= int(default['memory']):
|
||||
defaultmemory = default['memory']
|
||||
elif restmemory <= 0:
|
||||
defaultmemory = "0"
|
||||
else:
|
||||
defaultmemory = str(defaultmemory)
|
||||
if defaultdisk >= 2000:
|
||||
defaultdisk = "2000"
|
||||
elif defaultdisk <= 0:
|
||||
defaultmemory = str(restmemory)
|
||||
|
||||
if restdisk >= int(default['disk']):
|
||||
defaultdisk = default['disk']
|
||||
elif restdisk <= 0:
|
||||
defaultdisk = "0"
|
||||
else:
|
||||
defaultdisk = str(defaultdisk)
|
||||
defaultdisk = str(restdisk)
|
||||
|
||||
defaultsetting = {
|
||||
'cpu': defaultcpu,
|
||||
'memory': defaultmemory,
|
||||
|
@ -328,27 +332,31 @@ class configView(normalView):
|
|||
result = dockletRequest.post("/user/usageQuery/")
|
||||
quota = result.get("quota")
|
||||
usage = result.get("usage")
|
||||
defaultcpu = int(quota['cpu']) - int(usage['cpu'])
|
||||
defaultmemory = int(quota['memory']) - int(usage['memory'])
|
||||
defaultdisk = int(quota['disk']) - int(usage['disk'])
|
||||
if defaultcpu >= 4:
|
||||
defaultcpu = "4"
|
||||
elif defaultcpu <= 0:
|
||||
default = result.get("default")
|
||||
restcpu = int(quota['cpu']) - int(usage['cpu'])
|
||||
restmemory = int(quota['memory']) - int(usage['memory'])
|
||||
restdisk = int(quota['disk']) - int(usage['disk'])
|
||||
if restcpu >= int(default['cpu']):
|
||||
defaultcpu = default['cpu']
|
||||
elif restcpu <= 0:
|
||||
defaultcpu = "0"
|
||||
else:
|
||||
defaultcpu = str(defaultcpu)
|
||||
if defaultmemory >= 2000:
|
||||
defaultmemory = "2000"
|
||||
elif defaultmemory <= 0:
|
||||
defaultcpu = str(restcpu)
|
||||
|
||||
if restmemory >= int(default['memory']):
|
||||
defaultmemory = default['memory']
|
||||
elif restmemory <= 0:
|
||||
defaultmemory = "0"
|
||||
else:
|
||||
defaultmemory = str(defaultmemory)
|
||||
if defaultdisk >= 2000:
|
||||
defaultdisk = "2000"
|
||||
elif defaultdisk <= 0:
|
||||
defaultmemory = str(restmemory)
|
||||
|
||||
if restdisk >= int(default['disk']):
|
||||
defaultdisk = default['disk']
|
||||
elif restdisk <= 0:
|
||||
defaultdisk = "0"
|
||||
else:
|
||||
defaultdisk = str(defaultdisk)
|
||||
defaultdisk = str(restdisk)
|
||||
|
||||
defaultsetting = {
|
||||
'cpu': defaultcpu,
|
||||
'memory': defaultmemory,
|
||||
|
|
Loading…
Reference in New Issue