Don't choke on unlimited quotas. Fixes bug 971937.
Change-Id: Icc8b6a4189197c9d750163b1246173ca1a00afbe
This commit is contained in:
parent
44a428785a
commit
c55567354b
@ -67,7 +67,8 @@ class QuotaSet(object):
|
||||
for k in apiresource._info.keys():
|
||||
if k in ['id']:
|
||||
continue
|
||||
v = int(apiresource._info[k])
|
||||
limit = apiresource._info[k]
|
||||
v = int(limit) if limit is not None else limit
|
||||
q = Quota(k, v)
|
||||
self.items.append(q)
|
||||
setattr(self, k, v)
|
||||
@ -421,8 +422,12 @@ def tenant_quota_usages(request):
|
||||
usages[usage]['used'] += getattr(
|
||||
flavors[instance.flavor['id']], flavor_field, 0)
|
||||
usages[usage]['quota'] = getattr(quotas, usage)
|
||||
usages[usage]['available'] = usages[usage]['quota'] - \
|
||||
usages[usage]['used']
|
||||
if usages[usage]['quota'] is None:
|
||||
usages[usage]['quota'] = float("inf")
|
||||
usages[usage]['available'] = float("inf")
|
||||
else:
|
||||
usages[usage]['available'] = usages[usage]['quota'] - \
|
||||
usages[usage]['used']
|
||||
|
||||
return usages
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
<h3>{% trans "Project Quotas" %}</h3>
|
||||
<div class="quota_title">
|
||||
<strong>{% trans "Floating IP" %} <span>({{ usages.floating_ips.used }})</span></strong>
|
||||
<p>{{ usages.floating_ips.available }} {% trans "Available" %}</p>
|
||||
<p>{{ usages.floating_ips.available|quota }}</p>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
<div class="quota_bar">{% horizon_progress_bar usages.floating_ips.used usages.floating_ips.quota %}</div>
|
||||
|
@ -21,28 +21,28 @@
|
||||
|
||||
<div class="quota_title">
|
||||
<strong>{% trans "Instance Count" %} <span>({{ usages.instances.used }})</span></strong>
|
||||
<p>{{ usages.instances.available }} {% trans "Available" %}</p>
|
||||
<p>{{ usages.instances.available|quota }}</p>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
<div class="quota_bar">{% horizon_progress_bar usages.instances.used usages.instances.quota %}</div>
|
||||
|
||||
<div class="quota_title">
|
||||
<strong>{% trans "VCPUs" %} <span>({{ usages.cores.used }})</span></strong>
|
||||
<p>{{ usages.cores.available }} {% trans "Available" %}</p>
|
||||
<p>{{ usages.cores.available|quota }}</p>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
<div class="quota_bar">{% horizon_progress_bar usages.cores.used usages.cores.quota %}</div>
|
||||
|
||||
<div class="quota_title">
|
||||
<strong>{% trans "Disk" %} <span>({{ usages.gigabytes.used }} {% trans "GB" %})</span></strong>
|
||||
<p>{{ usages.gigabytes.available }} {% trans "GB" %} {% trans "Available" %}</p>
|
||||
<p>{{ usages.gigabytes.available|quota:"GB" }}</p>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
<div class="quota_bar">{% horizon_progress_bar usages.gigabytes.used usages.gigabytes.quota %}</div>
|
||||
|
||||
<div class="quota_title">
|
||||
<strong>{% trans "Memory" %} <span>({{ usages.ram.used }} {% trans "MB" %})</span></strong>
|
||||
<p>{{ usages.ram.available }} {% trans "MB" %} {% trans "Available" %}</p>
|
||||
<p>{{ usages.ram.available|quota:"MB" }}</p>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
<div class="quota_bar">{% horizon_progress_bar usages.ram.used usages.ram.quota %}</div>
|
||||
|
@ -172,7 +172,7 @@ class QuotasView(forms.ModalFormView):
|
||||
'injected_file_content_bytes': quotas.injected_file_content_bytes,
|
||||
'volumes': quotas.volumes,
|
||||
'gigabytes': quotas.gigabytes,
|
||||
'ram': int(quotas.ram),
|
||||
'ram': quotas.ram,
|
||||
'floating_ips': quotas.floating_ips,
|
||||
'instances': quotas.instances,
|
||||
'injected_files': quotas.injected_files,
|
||||
|
@ -20,10 +20,10 @@
|
||||
|
||||
import logging
|
||||
|
||||
from django import shortcuts
|
||||
from django.contrib import messages
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from horizon import api
|
||||
from horizon import exceptions
|
||||
from horizon import tables
|
||||
from .tables import QuotasTable
|
||||
|
||||
@ -40,9 +40,6 @@ class IndexView(tables.DataTableView):
|
||||
quota_set = api.tenant_quota_defaults(self.request,
|
||||
self.request.user.tenant_id)
|
||||
data = quota_set.items
|
||||
except Exception, e:
|
||||
data = []
|
||||
LOG.exception('Exception while getting quota info')
|
||||
messages.error(self.request,
|
||||
_('Unable to get quota info: %s') % e)
|
||||
except:
|
||||
exceptions.handle(self.request, _('Unable to get quota info.'))
|
||||
return data
|
||||
|
@ -17,6 +17,7 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django import template
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils.datastructures import SortedDict
|
||||
|
||||
from horizon.base import Horizon
|
||||
@ -114,6 +115,16 @@ def horizon_progress_bar(current_val, max_val):
|
||||
'max_val': max_val}
|
||||
|
||||
|
||||
@register.filter
|
||||
def quota(val, units=None):
|
||||
if val == float("inf"):
|
||||
return _("No Limit")
|
||||
elif units is not None:
|
||||
return "%s %s %s" % (val, units, _("Available"))
|
||||
else:
|
||||
return "%s %s" % (val, _("Available"))
|
||||
|
||||
|
||||
class JSTemplateNode(template.Node):
|
||||
""" Helper node for the ``jstemplate`` template tag. """
|
||||
def __init__(self, nodelist):
|
||||
|
Loading…
x
Reference in New Issue
Block a user