fix a bug when create guest #49

add hint for quota #7
This commit is contained in:
zhongyehong 2016-04-14 17:26:30 +08:00
parent a55fcba862
commit 7cd40a48e0
4 changed files with 42 additions and 13 deletions

View File

@ -25,7 +25,7 @@ class Container(object):
logger.info("create container %s of %s for %s" %(lxc_name, clustername, username))
try:
user_info = json.loads(user_info)
cpu = user_info["data"]["groupinfo"]["cpu"]
cpu = int(user_info["data"]["groupinfo"]["cpu"]) * 100000
memory = user_info["data"]["groupinfo"]["memory"]
disk = user_info["data"]["groupinfo"]["disk"]
image = json.loads(image)

View File

@ -23,9 +23,11 @@ class Guest(object):
subprocess.getoutput(self.libpath+"/userinit.sh guest")
user_info = {}
user_info["data"] = {}
user_info["data"]["group"] = "primary"
user_info["data"]["groupinfo"] = {}
user_info["data"]["groupinfo"]["cpu"] = 100000
user_info["data"]["groupinfo"]["cpu"] = 4
user_info["data"]["groupinfo"]["memory"] = 2000
user_info["data"]["groupinfo"]["disk"] = 2000
user_info = json.dumps(user_info)
self.G_vclustermgr.create_cluster("guestspace", "guest", image, user_info)
while True:

View File

@ -149,12 +149,24 @@ 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':'100000', 'disk':'2000', 'memory':'2000', 'image':'10', 'idletime':'24', 'network':'8' }})
groups.append({'name':'admin', 'quotas':{'cpu':'100000', 'disk':'2000', 'memory':'2000', 'image':'10', 'idletime':'24', 'network':'8'}})
groups.append({'name':'primary', 'quotas':{'cpu':'100000', 'disk':'2000', 'memory':'2000', 'image':'10', 'idletime':'24', 'network':'8'}})
groups.append({'name':'fundation', 'quotas':{'cpu':'100000', 'disk':'2000', 'memory':'2000', 'image':'10', 'idletime':'24', 'network':'8'}})
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'}})
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.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'})
quotafile.write(json.dumps(quotas))
quotafile.close()
def auth_local(self, username, password):
password = hashlib.sha512(password.encode('utf-8')).hexdigest()
@ -458,10 +470,13 @@ class userManager:
groupfile = open(fspath+"/global/sys/quota",'r')
groups = json.loads(groupfile.read())
groupfile.close()
quotafile = open(fspath+"/global/sys/quotainfo",'r')
quotas = json.loads(quotafile.read())
quotafile.close()
result = {
"success": 'true',
"groups": groups,
"quotas": list(groups[0]['quotas'].keys()),
"quotas": quotas,
}
return result
@ -608,6 +623,7 @@ class userManager:
form = kwargs.get('form')
quotaname = form.getvalue("quotaname")
default_value = form.getvalue("default_value")
hint = form.getvalue("hint")
if (quotaname == None):
return { "success":'false', "reason": "Empty quota name"}
if (default_value == None):
@ -620,6 +636,13 @@ class userManager:
groupfile = open(fspath+"/global/sys/quota",'w')
groupfile.write(json.dumps(groups))
groupfile.close()
quotafile = open(fspath+"/global/sys/quotainfo",'r')
quotas = json.loads(quotafile.read())
quotafile.close()
quotas.append({'name':quotaname, 'hint':hint})
quotafile = open(fspath+"/global/sys/quotainfo",'w')
quotafile.write(json.dumps(quotas))
quotafile.close()
return {"success":'true'}
@administration_required

View File

@ -57,8 +57,8 @@
</div>
{% for quota in quotas %}
<div class="form-group">
<label>{{ quota }}</label>
<input type="text" placeholder="Enter {{ quota }}" class="form-control" name={{ quota }} />
<label>{{ quota['name'] }}</label>
<input type="text" class="form-control" name={{ quota['name'] }} placeholder="{{quota['hint']}}" />
</div>
{% endfor %}
</form>
@ -92,6 +92,10 @@
<label>Default Value</label>
<input type="text" placeholder="Enter Default Value" class="form-control" name="default_value"/>
</div>
<div class="form-group">
<label>Hint</label>
<input type="text" placeholder="Enter Hint" class="form-control" name="hint"/>
</div>
</form>
</div>
@ -107,7 +111,7 @@
<tr>
<th>Name</th>
{% for quota in quotas %}
<th> {{ quota }} </th>
<th> {{ quota['name'] }} </th>
{% endfor %}
<th>Command</th>
</tr>
@ -117,7 +121,7 @@
<tr>
<th>{{ group['name'] }}</th>
{% for quota in quotas %}
<th> {{ group['quotas'][quota] }} </th>
<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" ] %}
@ -142,8 +146,8 @@
</div>
{% for quota in quotas %}
<div class="form-group">
<label> {{ quota }}</label>
<input type="text" placeholder="Enter {{ quota }}" class="form-control" name={{ quota }} value={{ group['quotas'][quota] }} />
<label> {{ quota['name'] }}</label>
<input type="text" placeholder="{{ quota['hint'] }}" class="form-control" name={{ quota['name'] }} value={{ group['quotas'][quota['name']] }} />
</div>
{% endfor %}
</div>