summaryrefslogtreecommitdiff
path: root/openstack_dashboard/usage/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'openstack_dashboard/usage/views.py')
-rw-r--r--openstack_dashboard/usage/views.py33
1 files changed, 25 insertions, 8 deletions
diff --git a/openstack_dashboard/usage/views.py b/openstack_dashboard/usage/views.py
index 5d1ea8f20..d88b56088 100644
--- a/openstack_dashboard/usage/views.py
+++ b/openstack_dashboard/usage/views.py
@@ -87,6 +87,10 @@ class UsageView(tables.DataTableView):
return resp
+def _check_network_allowed(request):
+ return api.neutron.is_quotas_extension_supported(request)
+
+
ChartDef = collections.namedtuple(
'ChartDef',
('quota_key', 'label', 'used_phrase', 'filters'))
@@ -99,6 +103,10 @@ ChartDef = collections.namedtuple(
# - filters to be applied to the value
# If None is specified, the default filter 'intcomma' will be applied.
# if you want to apply no filters, specify an empty tuple or list.
+# - allowed:
+# An optional argument used to determine if the chart section should be
+# displayed. Can be a static value or a function, which is called dynamically
+# with the request as it's first parameter.
CHART_DEFS = [
{
'title': _("Compute"),
@@ -106,7 +114,7 @@ CHART_DEFS = [
ChartDef("instances", _("Instances"), None, None),
ChartDef("cores", _("VCPUs"), None, None),
ChartDef("ram", _("RAM"), None, (sizeformat.mb_float_format,)),
- ]
+ ],
},
{
'title': _("Volume"),
@@ -115,7 +123,7 @@ CHART_DEFS = [
ChartDef("snapshots", _("Volume Snapshots"), None, None),
ChartDef("gigabytes", _("Volume Storage"), None,
(sizeformat.diskgbformat,)),
- ]
+ ],
},
{
'title': _("Network"),
@@ -129,7 +137,8 @@ CHART_DEFS = [
ChartDef("network", _("Networks"), None, None),
ChartDef("port", _("Ports"), None, None),
ChartDef("router", _("Routers"), None, None),
- ]
+ ],
+ 'allowed': _check_network_allowed,
},
]
@@ -147,13 +156,21 @@ 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
- })
+ if self._check_chart_allowed(section):
+ chart_data = self._process_chart_section(section['charts'])
+ chart_sections.append({
+ 'title': section['title'],
+ 'charts': chart_data
+ })
return chart_sections
+ def _check_chart_allowed(self, chart_def):
+ result = True
+ if 'allowed' in chart_def:
+ allowed = chart_def['allowed']
+ result = allowed(self.request) if callable(allowed) else allowed
+ return result
+
def _process_chart_section(self, chart_defs):
charts = []
for t in chart_defs: