Commit 9ac80a3f by Bence Dányi

one: share editing quota issues fixed

parent e9a240ed
......@@ -228,6 +228,9 @@ class Share(models.Model):
return u"%(group)s: %(tpl)s %(owner)s" % {
'group': self.group, 'tpl': self.template, 'owner': self.owner}
def get_used_quota(self):
return self.template.get_credits_per_instance() * self.instance_limit
class Disk(models.Model):
"""Virtual disks automatically synchronized with OpenNebula."""
name = models.CharField(max_length=100, unique=True,
......@@ -381,6 +384,9 @@ class Template(models.Model):
logger.info("Could not delete template. Instances still running!")
return False
def get_credits_per_instance(self):
return self.instance_type.credit
class Instance(models.Model):
"""Virtual machine instance."""
name = models.CharField(max_length=100,
......
......@@ -228,16 +228,21 @@ class AjaxShareEditWizard(View):
stype = request.POST['type']
if not stype in TYPES.keys():
raise PermissionDenied()
il = request.POST['instance_limit']
if det.get_weighted_share_count() + int(il)*share.template.instance_type.credit > det.share_quota:
instance_limit = int(request.POST['instance_limit'])
current_used_share_quota = det.get_weighted_share_count()
current_used_share_quota_without_current_share = current_used_share_quota - share.get_used_quota()
new_quota_for_current_share = instance_limit * share.template.get_credits_per_instance()
new_used_share_quota = current_used_share_quota_without_current_share + new_quota_for_current_share
allow_stype_modify = True if new_used_share_quota <= det.share_quota else False
if not allow_stype_modify:
messages.error(request, _('You do not have enough free share quota.'))
return redirect('/')
share.name=request.POST['name']
share.description=request.POST['description']
share.type=stype
share.instance_limit=il
share.per_user_limit=request.POST['per_user_limit']
share.owner=request.user
share.name = request.POST['name']
share.description = request.POST['description']
share.type = stype
share.instance_limit = instance_limit
share.per_user_limit = request.POST['per_user_limit']
share.owner = request.user
share.save()
messages.success(request, _('Successfully edited share %s.') % share)
return redirect(share.group)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment