Skip to content

Commit

Permalink
Don't choke on unlimited quotas. Fixes bug 971937.
Browse files Browse the repository at this point in the history
Change-Id: Icc8b6a4189197c9d750163b1246173ca1a00afbe
  • Loading branch information
gabrielhurley authored and ttx committed Apr 3, 2012
1 parent 039cd95 commit 6da7f69
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
11 changes: 8 additions & 3 deletions horizon/api/nova.py
Expand Up @@ -67,7 +67,8 @@ def __init__(self, apiresource):
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)
Expand Down Expand Up @@ -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

Expand Down
Expand Up @@ -20,7 +20,7 @@ <h3>{% trans "Description:" %}</h3>
<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>
Expand Down
Expand Up @@ -21,28 +21,28 @@ <h3>{% trans "Project Quotas" %}</h3>

<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>
Expand Down
2 changes: 1 addition & 1 deletion horizon/dashboards/syspanel/projects/views.py
Expand Up @@ -172,7 +172,7 @@ def get_initial(self):
'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,
Expand Down
11 changes: 4 additions & 7 deletions horizon/dashboards/syspanel/quotas/views.py
Expand Up @@ -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

Expand All @@ -40,9 +40,6 @@ def get_data(self):
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
11 changes: 11 additions & 0 deletions horizon/templatetags/horizon.py
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 6da7f69

Please sign in to comment.