Merge "usage: Categorize Limit Summary by service"

This commit is contained in:
Zuul 2018-05-08 08:23:47 +00:00 committed by Gerrit Code Review
commit 17ce74e4f0
3 changed files with 104 additions and 41 deletions

View File

@ -3,7 +3,9 @@
{% spaceless %}
<div class="quota-dynamic limit-summary">
<h3 class="quota-heading">{% trans "Limit Summary" %}</h3>
{% for chart in charts %}
{% for section in charts %}
<h4>{{ section.title }}</h4>
{% for chart in section.charts %}
{% if forloop.first or forloop.counter0|divisibleby:6 %}
<div class="row">
{% endif %}
@ -28,5 +30,6 @@
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
</div>
{% endspaceless %}

View File

@ -266,8 +266,40 @@ class UsageViewTests(test.TestCase):
return res
def test_usage_charts_created(self):
res = self._test_usage_charts()
res = self._test_usage_charts(
quota_usage_overrides={'floatingip': {'quota': -1, 'used': 1234}})
self.assertIn('charts', res.context)
charts = res.context['charts']
self.assertEqual(['Compute', 'Volume', 'Network'],
[c['title'] for c in charts])
compute_charts = [c for c in charts if c['title'] == 'Compute'][0]
chart_ram = [c for c in compute_charts['charts']
if c['type'] == 'ram'][0]
# Check mb_float_format filter is applied
self.assertEqual(10000, chart_ram['quota'])
self.assertEqual('9.8GB', chart_ram['quota_display'])
self.assertEqual(0, chart_ram['used'])
self.assertEqual('0Bytes', chart_ram['used_display'])
volume_charts = [c for c in charts if c['title'] == 'Volume'][0]
chart_gigabytes = [c for c in volume_charts['charts']
if c['type'] == 'gigabytes'][0]
# Check diskgbformat filter is applied
self.assertEqual(1000, chart_gigabytes['quota'])
self.assertEqual('1000GB', chart_gigabytes['quota_display'])
self.assertEqual(0, chart_gigabytes['used'])
self.assertEqual('0Bytes', chart_gigabytes['used_display'])
network_charts = [c for c in charts if c['title'] == 'Network'][0]
chart_fip = [c for c in network_charts['charts']
if c['type'] == 'floatingip'][0]
# Check intcomma default filter is applied
self.assertEqual(float('inf'), chart_fip['quota'])
self.assertEqual(float('inf'), chart_fip['quota_display'])
self.assertEqual(1234, chart_fip['used'])
self.assertEqual('1,234', chart_fip['used_display'])
def test_usage_charts_infinite_quota(self):
res = self._test_usage_charts(

View File

@ -100,22 +100,38 @@ ChartDef = collections.namedtuple(
# If None is specified, the default filter 'intcomma' will be applied.
# if you want to apply no filters, specify an empty tuple or list.
CHART_DEFS = [
{
'title': _("Compute"),
'charts': [
ChartDef("instances", _("Instances"), None, None),
ChartDef("cores", _("VCPUs"), None, None),
ChartDef("ram", _("RAM"), None, (sizeformat.mb_float_format,)),
]
},
{
'title': _("Volume"),
'charts': [
ChartDef("volumes", _("Volumes"), None, None),
ChartDef("snapshots", _("Volume Snapshots"), None, None),
ChartDef("gigabytes", _("Volume Storage"), None,
(sizeformat.diskgbformat,)),
]
},
{
'title': _("Network"),
'charts': [
ChartDef("floatingip", _("Floating IPs"),
pgettext_lazy('Label in the limit summary', "Allocated"),
None),
ChartDef("security_group", _("Security Groups"), None, None),
ChartDef("security_group_rule", _("Security Group Rules"), None, None),
ChartDef("security_group_rule", _("Security Group Rules"),
None, None),
ChartDef("network", _("Networks"), None, None),
ChartDef("port", _("Ports"), None, None),
ChartDef("router", _("Routers"), None, None),
]
},
]
def _apply_filters(value, filters):
@ -129,8 +145,18 @@ def _apply_filters(value, filters):
class ProjectUsageView(UsageView):
def _get_charts_data(self):
chart_sections = []
for section in CHART_DEFS:
chart_data = self._process_chart_section(section['charts'])
chart_sections.append({
'title': section['title'],
'charts': chart_data
})
return chart_sections
def _process_chart_section(self, chart_defs):
charts = []
for t in CHART_DEFS:
for t in chart_defs:
if t.quota_key not in self.usage.limits:
continue
key = t.quota_key
@ -149,6 +175,8 @@ class ProjectUsageView(UsageView):
quota_display = None
if quota != float('inf'):
quota_display = _apply_filters(quota, filters)
else:
quota_display = quota
charts.append({
'type': key,