add upgrade.py to upgrade some configure file
add data space quota, but it doesn't work now add default quota group, can change it in admin page fix a bug when user first time to create image
This commit is contained in:
parent
961baf6ae2
commit
7b96837dfe
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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()
|
|
@ -106,7 +106,7 @@
|
|||
</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>
|
||||
<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">
|
||||
|
@ -130,7 +130,7 @@
|
|||
</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>
|
||||
<button type="button" class="btn btn-primary" onClick="javascript:sendChDefault();">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -154,10 +154,14 @@
|
|||
{% endfor %}
|
||||
<th><a class="btn btn-xs btn-info" data-toggle="modal" data-target="#ModifyGroupModal_{{ group['name'] }}">Edit</a>
|
||||
{% if group['name'] in [ "root", "primary", "admin", "fundation" ] %}
|
||||
<a class="btn btn-xs btn-default" href="javascript:void(0)">Delete</a></th>
|
||||
<a class="btn btn-xs btn-default" href="javascript:void(0)">Delete</a>
|
||||
{% else %}
|
||||
<a class="btn btn-xs btn-danger" href="/group/delete/{{group['name']}}">Delete</a></th>
|
||||
<a class="btn btn-xs btn-danger" href="/group/delete/{{group['name']}}">Delete</a>
|
||||
{% endif %}
|
||||
{% if group['name'] == defaultgroup %}
|
||||
<span class="glyphicon glyphicon-ok"></span>
|
||||
{% endif %}
|
||||
</th>
|
||||
<div class="modal inmodal" id="ModifyGroupModal_{{ group['name'] }}" tabindex="-1" role="dialog" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content animated fadeIn">
|
||||
|
|
Loading…
Reference in New Issue