limit quota of vnode to 2^n -3

This commit is contained in:
zhuyj17 2017-11-24 15:01:33 +08:00
parent 1dcaf5863a
commit 8571498063
2 changed files with 19 additions and 3 deletions

View File

@ -9,7 +9,7 @@ Original author: Liu Peidong
from model import db, User, UserGroup, Notification, UserUsage
from functools import wraps
import os, subprocess
import os, subprocess, math
import hashlib
import pam
from base64 import b64encode
@ -755,7 +755,12 @@ class userManager:
if key == "groupname" or key == "token":
pass
else:
group['quotas'][key] = form.get(key)
if key == "vnode":
vnode = int(form['vnode'])
val = str(2**(round(math.log(vnode+3, 2))) - 3 )
group["quotas"][key] = val
else:
group['quotas'][key] = form.get(key)
groupfile = open(fspath+"/global/sys/quota",'w')
groupfile.write(json.dumps(groups))
groupfile.close()
@ -915,7 +920,12 @@ class userManager:
if key == "groupname" or key == "token":
pass
else:
group['quotas'][key] = form.get(key)
if key == "vnode":
vnode = int(form['vnode'])
val = str(2**(round(math.log(vnode+3, 2))) - 3 )
group['quotas'][key] = val
else:
group['quotas'][key] = form.get(key)
groups.append(group)
groupfile = open(fspath+"/global/sys/quota",'w')
groupfile.write(json.dumps(groups))

View File

@ -58,6 +58,9 @@
{% for quota in quotas %}
<div class="form-group">
<label>{{ quota['name'] }}</label>
{% if quota['name'] == 'vnode' %}
<small class="font-bold"> Only 2^n - 3 is legal. Any other value will be reset to the nearest 2^n - 3.</small>
{% endif %}
<input type="text" class="form-control" name={{ quota['name'] }} placeholder="{{quota['hint']}}" />
</div>
{% endfor %}
@ -181,6 +184,9 @@
{% for quota in quotas %}
<div class="form-group">
<label> {{ quota['name'] }}</label>
{% if quota['name'] == 'vnode' %}
<small class="font-bold"> Only 2^n - 3 is legal. Any other value will be reset to the nearest 2^n - 3.</small>
{% endif %}
<input type="text" placeholder="{{ quota['hint'] }}" class="form-control" name={{ quota['name'] }} value={{ group['quotas'][quota['name']] }} />
</div>
{% endfor %}