add disk quota

This commit is contained in:
zhongyehong 2016-04-27 16:31:46 +08:00
parent eb6e0f4793
commit 961baf6ae2
7 changed files with 90 additions and 12 deletions

View File

@ -76,7 +76,8 @@ pre_start_master () {
[ ! -d $FS_PREFIX/local ] && mkdir -p $FS_PREFIX/local
[ ! -d $FS_PREFIX/global/users ] && mkdir -p $FS_PREFIX/global/users
[ ! -d $FS_PREFIX/global/sys ] && mkdir -p $FS_PREFIX/global/sys
[ ! -d $FS_PREFIX/global/images ] && mkdir -p $FS_PREFIX/global/images
[ ! -d $FS_PREFIX/global/images/private ] && mkdir -p $FS_PREFIX/global/images/private
[ ! -d $FS_PREFIX/global/images/public ] && mkdir -p $FS_PREFIX/global/images/public
[ ! -d $FS_PREFIX/local/volume ] && mkdir -p $FS_PREFIX/local/volume
[ ! -d $FS_PREFIX/local/temp ] && mkdir -p $FS_PREFIX/local/temp
[ ! -d $FS_PREFIX/local/run ] && mkdir -p $FS_PREFIX/local/run

View File

@ -432,6 +432,9 @@ class DockletHttpHandler(http.server.BaseHTTPRequestHandler):
elif cmds[1] == 'quotaadd':
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)
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)

View File

@ -63,7 +63,7 @@ class ImageMgr():
fspath = self.NFS_PREFIX + "/local/volume/" + lxc
imgpath = self.imgpath + "private/" + user + "/"
if not os.path.exists(imgpath+image):
if not os.path.exists(imgpath+image) and os.path.exists(imgpath):
cur_imagenum = 0
for filename in os.listdir(imgpath):
if os.path.isdir(imgpath+filename):

View File

@ -155,17 +155,33 @@ class userManager:
groups.append({'name':'fundation', 'quotas':{'cpu':'4', 'disk':'2000', '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 = []
quotas.append({'name':'cpu', 'hint':'the cpu quota, number of cores, e.g. 4'})
quotas.append({'name':'memory', 'hint':'the memory quota, number of MB , e.g. 4000'})
quotas.append({'name':'disk', 'hint':'the disk quota, number of MB, e.g. 4000'})
quotas.append({'name':'image', 'hint':'how many images the user can save, e.g. 10'})
quotas.append({'name':'idletime', 'hint':'will stop cluster after idletime, number of hours, e.g. 24'})
quotas.append({'name':'vnode', 'hint':'how many containers the user can have, e.g. 8'})
quotas = {}
quotas['default'] = 'fundation'
quotas['quotainfo'] = []
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':'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()
def auth_local(self, username, password):
@ -476,10 +492,24 @@ class userManager:
result = {
"success": 'true',
"groups": groups,
"quotas": quotas,
"quotas": quotas['quotainfo'],
"default": quotas['default'],
}
return result
@administration_required
def change_default_group(*args, **kwargs):
form = kwargs['form']
default_group = form.getvalue('defaultgroup')
quotafile = open(fspath+"/global/sys/quotainfo",'r')
quotas = json.loads(quotafile.read())
quotafile.close()
quotas['default'] = default_group
quotafile = open(fspath+"/global/sys/quotainfo",'r')
quotafile.write(json.dumps(quotas))
quotafile.close()
@administration_required
def groupQuery(*args, **kwargs):
'''
@ -639,7 +669,7 @@ class userManager:
quotafile = open(fspath+"/global/sys/quotainfo",'r')
quotas = json.loads(quotafile.read())
quotafile.close()
quotas.append({'name':quotaname, 'hint':hint})
quotas['quotainfo'].append({'name':quotaname, 'hint':hint})
quotafile = open(fspath+"/global/sys/quotainfo",'w')
quotafile.write(json.dumps(quotas))
quotafile.close()

View File

@ -106,6 +106,35 @@
</div>
</div>
</div>
<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#ChangeDefaultModal"><i class="fa fa-plus"></i>Change Default</button>
<div class="modal inmodal" id="ChangeDefaultModal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content animated fadeIn">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
<i class="fa fa-laptop modal-icon"></i>
<h4 class="modal-title">Change Default</h4>
<small class="font-bold">Change Default Quota Group</small>
</div>
<div class="modal-body">
<form action="/quota/chdefault/" method="POST" id="chDefaultForm">
<div class="form-group">
<label>Default Group</label>
<select class="form-control" name="defaultgroup" value={{ defaultgroup }} />
{% for group in groups %}
<option>{{ group['name'] }}</option>
{% endfor %}
</select>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-white" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" onClick="javascript:sendchDefault();">Submit</button>
</div>
</div>
</div>
</div>
<table id="myGroupTable" class="table table-striped table-bordered">
<thead>
<tr>
@ -182,6 +211,9 @@
function sendAddQuota(){
document.getElementById("addQuotaForm").submit();
}
function sendChDefault(){
document.getElementById("chDefaultForm").submit();
}
function setFormGroup(arg){
$.post("/group/query/",
{

View File

@ -328,6 +328,11 @@ def usermodify():
def quotaadd():
return quotaaddView.as_view()
@app.route("/quota/chdefault/", methods=['POST'])
@administration_required
def chdefault():
return chdefaultView.as_view()
@app.route("/group/add/", methods=['POST'])
@administration_required
def groupadd():

View File

@ -12,7 +12,8 @@ class adminView(normalView):
result = dockletRequest.post('/user/groupList/')
groups = result["groups"]
quotas = result["quotas"]
return self.render(self.template_path, groups = groups, quotas = quotas)
defaultgroup = result["default"]
return self.render(self.template_path, groups = groups, quotas = quotas, defaultgroup = defaultgroup)
class groupaddView(normalView):
@classmethod
@ -26,6 +27,12 @@ class quotaaddView(normalView):
dockletRequest.post('/user/quotaadd', request.form)
return redirect('/admin/')
class chdefaultView(normalView):
@classmethod
def post(self):
dockletRequest.post('/user/chdefault', request.form)
return redirect('/admin/')
class groupdelView(normalView):
@classmethod
def post(self):