Merge pull request #101 from zhongyehong/master

fix some error
This commit is contained in:
zhong yehong 2016-05-09 12:53:51 +08:00
commit aeacacb65e
5 changed files with 74 additions and 17 deletions

View File

@ -135,11 +135,13 @@
# default: ""
# ADMIN_EMAIL_ADDRESS=""
# DATA_QUOTA : whether enable the quota of data or not
# default: "NO"
# DATA_QUOTA=""
# DATA_QUOTA : whether enable the quota of data volume or not
# True or False, default: False
# DATA_QUOTA=False
# DATA_QUOTA_CMD : the cmd to set the data quota, the argument of it should be directory name
# and the quota value.
# DATA_QUOTA_CMD : the cmd to set the quota of a given directory. It accepts two arguments:
# arg1: the directory name, relative path from the data volume root, e.g, "/users/bob/data"
# arg2: the quota value in GB of string, e.g., "100"
# default: "gluster volume quota docklet-volume limit-usage %s %s"
# DATA_QUOTA_CMD=""
# DATA_QUOTA_CMD="gluster volume quota docklet-volume limit-usage %s %s"

View File

@ -51,7 +51,7 @@ def getenv(key):
elif key =="ADMIN_EMAIL_ADDRESS":
return os.environ.get("ADMIN_EMAIL_ADDRESS", "")
elif key =="DATA_QUOTA":
return os.environ.get("DATA_QUOTA", "NO")
return os.environ.get("DATA_QUOTA", "False")
elif key =="DATA_QUOTA_CMD":
return os.environ.get("DATA_QUOTA_CMD", "gluster volume quota docklet-volume limit-usage %s %s")
else:

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'})
@ -311,14 +311,14 @@ class userManager:
return user
def set_nfs_quota_bygroup(self,groupname, quota):
if not data_quota == "YES":
if not data_quota == "True":
return
users = User.query.filter_by(user_group = groupname).all()
for user in users:
self.set_nfs_quota(user.username, quota)
def set_nfs_quota(self, username, quota):
if not data_quota == "YES":
if not data_quota == "True":
return
nfspath = "/users/%s/data" % username
try:

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")
@ -38,6 +39,58 @@ def update_quotainfo():
quotafile = open(fspath+"/global/sys/quotainfo", 'w')
quotafile.write(json.dumps(quotas))
quotafile.close()
if not os.path.exists(fspath+"/global/sys/quota"):
print("quota file not exists, please run docklet to init it")
return False
groupfile = open(fspath+"/global/sys/quota",'r')
groups = json.loads(groupfile.read())
groupfile.close()
for group in groups:
if 'cpu' not in group['quotas'].keys():
group['quotas']['cpu'] = "4"
if 'memory' not in group['quotas'].keys():
group['quotas']['memory'] = "2000"
if 'disk' not in group['quotas'].keys():
group['quotas']['disk'] = "2000"
if 'data' not in group['quotas'].keys():
group['quotas']['data'] = "100"
if 'image' not in group['quotas'].keys():
group['quotas']['image'] = "10"
if 'idletime' not in group['quotas'].keys():
group['quotas']['idletime'] = "24"
if 'vnode' not in group['quotas'].keys():
group['quotas']['vnode'] = "8"
print("quota updated")
groupfile = open(fspath+"/global/sys/quota",'w')
groupfile.write(json.dumps(groups))
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:
@ -98,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

@ -154,7 +154,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;