fix a name error

This commit is contained in:
zhongyehong 2016-05-09 11:56:12 +08:00
parent 6ca2180e02
commit e72968fda2
3 changed files with 33 additions and 5 deletions

View File

@ -156,13 +156,13 @@ class userManager:
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'}})
groups.append({'name':'foundation', 'quotas':{'cpu':'4', 'disk':'2000', 'data':'100', 'memory':'2000', 'image':'10', 'idletime':'24', 'vnode':'8'}})
groupfile.write(json.dumps(groups))
groupfile.close()
if not os.path.exists(fspath+"/global/sys/quotainfo"):
quotafile = open(fspath+"/global/sys/quotainfo",'w')
quotas = {}
quotas['default'] = 'fundation'
quotas['default'] = 'foundation'
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'})

View File

@ -1,7 +1,8 @@
#!/usr/bin/python3
import os, json, sys
sys.path.append("../src/")
from model import db, User
fspath="/opt/docklet"
def update_quotainfo():
@ -13,7 +14,7 @@ def update_quotainfo():
quotafile.close()
if type(quotas) is list:
new_quotas = {}
new_quotas['default'] = 'fundation'
new_quotas['default'] = 'foundation'
new_quotas['quotainfo'] = quotas
quotas = new_quotas
print("change the type of quotafile from list to dict")
@ -65,6 +66,31 @@ def update_quotainfo():
groupfile.close()
def name_error():
quotafile = open(fspath+"/global/sys/quotainfo", 'r')
quotas = json.loads(quotafile.read())
quotafile.close()
if quotas['default'] == 'fundation':
quotas['default'] = 'foundation'
quotafile = open(fspath+"/global/sys/quotainfo",'w')
quotafile.write(json.dumps(quotas))
quotafile.close()
groupfile = open(fspath+"/global/sys/quota", 'r')
groups = json.loads(groupfile.read())
groupfile.close()
for group in groups:
if group['name'] == 'fundation':
group['name'] = 'foundation'
groupfile = open(fspath+"/global/sys/quota",'w')
groupfile.write(json.dumps(groups))
groupfile.close()
users = User.query.filter_by(user_group = 'fundation').all()
for user in users:
user.user_group = 'foundation'
db.session.commit()
def allquota():
try:
@ -125,4 +151,6 @@ def enable_gluster_quota():
if __name__ == '__main__':
update_quotainfo()
if "fix-name-error" in sys.argv:
name_error()
# enable_gluster_quota()

View File

@ -153,7 +153,7 @@
<th> {{ group['quotas'][quota['name']] }} </th>
{% endfor %}
<th><a class="btn btn-xs btn-info" data-toggle="modal" data-target="#ModifyGroupModal_{{ group['name'] }}">Edit</a>&nbsp;
{% if group['name'] in [ "root", "primary", "admin", "fundation" ] %}
{% if group['name'] in [ "root", "primary", "admin", "foundation" ] %}
<a class="btn btn-xs btn-default" href="javascript:void(0)">Delete</a>&nbsp;
{% else %}
<a class="btn btn-xs btn-danger" href="/group/delete/{{group['name']}}">Delete</a>&nbsp;