Commit 2dea86ba by tarokkk

one: Added Share quota

parent 82dccc14
......@@ -169,6 +169,12 @@ class Share(models.Model):
per_user_limit = models.IntegerField(verbose_name=_('per user limit'),
help_text=_('Maximal count of instances launchable by a single user.'))
def get_running_or_stopped(self):
return Instance.objects.all().exclude(state='DONE').filter(share=self).count()
def get_running(self):
return Instance.objects.all().exclude(state='DONE').exclude(state='STOPPED').filter(share=self).count()
def get_instance_pc(self):
return float(self.get_running()) / self.instance_limit * 100
"""
Virtual disks automatically synchronized with OpenNebula.
"""
......@@ -417,10 +423,10 @@ class Instance(models.Model):
Submit a new instance to OpenNebula.
"""
@classmethod
def submit(cls, template, owner, extra=""):
def submit(cls, template, owner, extra="", share=None):
from django.template.defaultfilters import escape
out = ""
inst = Instance(pw=pwgen(), template=template, owner=owner)
inst = Instance(pw=pwgen(), template=template, owner=owner, share=share)
inst.save()
with tempfile.NamedTemporaryFile(delete=False) as f:
os.chmod(f.name, stat.S_IRUSR|stat.S_IWUSR|stat.S_IRGRP|stat.S_IROTH)
......
......@@ -26,11 +26,11 @@
<li class="wm">
<div class="summary">
<div class="quota">
<div class="used" style="width: 40%"></div>
<div class="used" style="width: {{ s.get_instance_pc }}%"></div>
</div>
<div class="name wm-on">{{s.name}}</div>
<div class="status">
3/10
{{s.get_running}}/{{s.instance_limit}}
</div>
<div class="clear"></div>
</div>
......
......@@ -210,7 +210,7 @@ def vm_new(request, template=None, share=None):
t.save()
base = t
try:
i = Instance.submit(base, request.user, extra="<RECONTEXT>YES</RECONTEXT>")
i = Instance.submit(base, request.user, extra="<RECONTEXT>YES</RECONTEXT>", share=share)
return redirect(i)
except Exception as e:
logger.error('Failed to create virtual machine.' + unicode(e))
......
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