Commit 2dea86ba by tarokkk

one: Added Share quota

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