mirror of
https://github.com/retspen/webvirtcloud
synced 2024-12-24 23:25:24 +00:00
clone check_user_quota correct application logic
This commit is contained in:
parent
027bbbc776
commit
c51e986b8c
1 changed files with 9 additions and 7 deletions
|
@ -218,15 +218,17 @@ def instance(request, compute_id, vname):
|
||||||
return free_names
|
return free_names
|
||||||
|
|
||||||
def check_user_quota():
|
def check_user_quota():
|
||||||
|
# TODO: count cpus, memory correctly
|
||||||
userinstances = UserInstance.objects.filter(user__id=request.user.id)
|
userinstances = UserInstance.objects.filter(user__id=request.user.id)
|
||||||
instances_count = len(userinstances)
|
instances_count = len(userinstances)
|
||||||
cpus_count = instances_count
|
cpus_count = instances_count
|
||||||
memory_count = instances_count * 2048
|
memory_count = instances_count * 2048
|
||||||
if request.user.userattributes.max_instances > 0 and instances_count > request.user.userattributes.max_instances:
|
ua = request.user.userattributes
|
||||||
|
if ua.max_instances > 0 and instances_count > ua.max_instances:
|
||||||
return "instance"
|
return "instance"
|
||||||
if request.user.userattributes.max_cpus > 0 and cpus_count > request.user.userattributes.max_cpus:
|
if ua.max_cpus > 0 and cpus_count > ua.max_cpus:
|
||||||
return "cpu"
|
return "cpu"
|
||||||
if request.user.userattributes.max_memory > 0 and memory_count > request.user.userattributes.max_memory:
|
if ua.max_memory > 0 and memory_count > ua.max_memory:
|
||||||
return "memory"
|
return "memory"
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
@ -555,12 +557,12 @@ def instance(request, compute_id, vname):
|
||||||
clone_data['name'] = request.POST.get('name', '')
|
clone_data['name'] = request.POST.get('name', '')
|
||||||
|
|
||||||
quota_msg = check_user_quota()
|
quota_msg = check_user_quota()
|
||||||
if quota_msg:
|
check_instance = Instance.objects.filter(name=clone_data['name'])
|
||||||
|
|
||||||
|
if not request.user.is_superuser and quota_msg:
|
||||||
msg = _("User %s quota reached, cannot create '%s'!" % (quota_msg, clone_data['name']))
|
msg = _("User %s quota reached, cannot create '%s'!" % (quota_msg, clone_data['name']))
|
||||||
error_messages.append(msg)
|
error_messages.append(msg)
|
||||||
|
elif check_instance:
|
||||||
check_instance = Instance.objects.filter(name=clone_data['name'])
|
|
||||||
if check_instance:
|
|
||||||
msg = _("Instance '%s' already exists!" % clone_data['name'])
|
msg = _("Instance '%s' already exists!" % clone_data['name'])
|
||||||
error_messages.append(msg)
|
error_messages.append(msg)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue