Allow disabling quota management in regions

This improves and fixes some issues with the quota management
dashboard when quota management is disabled in a region
(either partially or fully).

* Ensure the Region Quota Details and Quota Size Details pages
  do not return an error when viewing regions that have
  quota management disabled.
* On the Quota Size Details page, if quotas for a resource are not
  managed in a region, set `-` for the current quota, usage and
  percentage values, instead of hiding the table row entirely.
* Make the title formatting nicer for the Region Quota Details and
  Quota Size Details pages.

Change-Id: I1ed74ba6bde647c9184f58278474cbc1cc80e289
This commit is contained in:
Callum Dickinson 2024-07-24 09:34:49 +12:00
parent 2bea2114fb
commit bab31ad14d
4 changed files with 27 additions and 21 deletions

View File

@ -625,20 +625,24 @@ def size_details_get(request, size, region=None):
resp = _get_quota_information(request, regions=region)
data = resp['quota_sizes'][size]
region_data = resp['regions'][0]['current_quota']
try:
region = resp['regions'][0]
except IndexError:
region = {}
current_quota = region.get('current_quota', {})
current_usage = region.get('current_usage', {})
for service, values in data.items():
if service not in resp['regions'][0]['current_usage']:
continue
for resource, value in values.items():
if _is_quota_hidden(service, resource):
continue
usage = resp['regions'][0]['current_usage'][service].get(
resource)
try:
percent = float(usage) / value
except (TypeError, ZeroDivisionError):
percent = '-'
quota = current_quota.get(service, {}).get(resource, '-')
usage = current_usage.get(service, {}).get(resource, '-')
percent = (
'-'
if not value or usage == '-'
else (usage / value)
)
quota_details.append(
SIZE_QUOTA_VALUE(
@ -646,7 +650,7 @@ def size_details_get(request, size, region=None):
name=resource,
service=service,
value=value,
current_quota=region_data[service][resource],
current_quota=quota,
current_usage=usage,
percent=percent
)
@ -659,7 +663,11 @@ def quota_details_get(request, region):
resp = _get_quota_information(request, regions=region)
data = resp['regions'][0]['current_quota']
try:
region = resp['regions'][0]
except IndexError:
region = {}
data = region.get('current_quota', {})
for service, values in data.items():
for name, value in values.items():

View File

@ -1,6 +1,6 @@
{% extends 'base.html' %}
{% load i18n %}
{% block title %} {% trans "Quota Details" %} {% endblock %}
{% block title %}{% blocktrans %}{{ region }} Quota Details{% endblocktrans %}{% endblock %}
{% block main %}
{{ table.render }}

View File

@ -1,10 +1,6 @@
{% extends 'base.html' %}
{% load i18n %}
{% block title %} {{title}} - Quota Details{% endblock %}
{% block page_header %}
{% include "horizon/common/_page_header.html" with title=title %}
{% endblock page_header %}
{% block title %}{% blocktrans %}{{ size_titlecase }} Quota Details{% endblocktrans %}{% endblock %}
{% block main %}
{{ table.render }}

View File

@ -57,7 +57,7 @@ class IndexView(horizon_tables.MultiTableView):
class RegionDetailView(horizon_tables.DataTableView):
table_class = quota_tables.RegionQuotaDetailTable
template_name = 'management/quota/region_detail.html'
page_title = _("'{{ region }}' Quota Details")
page_title = _("{{ region }} Quota Details")
def get_data(self):
try:
@ -76,7 +76,7 @@ class RegionDetailView(horizon_tables.DataTableView):
class QuotaSizeView(horizon_tables.DataTableView):
table_class = quota_tables.QuotaDetailUsageTable
template_name = 'management/quota/size_detail.html'
page_title = _("'{{ size }}' Quota Details")
page_title = _("{{ size | title }} Quota Details")
def get_data(self):
try:
@ -89,8 +89,10 @@ class QuotaSizeView(horizon_tables.DataTableView):
def get_context_data(self, **kwargs):
# request.user.services_region
context = super(QuotaSizeView, self).get_context_data(**kwargs)
context['title'] = _("%s - Quota Details") \
% self.kwargs['size'].title()
context['size'] = self.kwargs['size']
# NOTE(callumdickinson): Necessary because the title filter
# is overloaded in the title block.
context['size_titlecase'] = self.kwargs['size'].title()
return context