Enable full quota, overview functionality
Enable manila quotas on the following pages: - Admin/System/Defaults/Update Defaults - Identity/Projects/CreateProject - Identity/Projects/Modify Quotas Incorporate manila pie charts into project overview panel
This commit is contained in:
parent
d2a50c6859
commit
45ed4ed108
@ -2,3 +2,5 @@ PANEL_DASHBOARD = 'project'
|
||||
PANEL_GROUP = 'compute'
|
||||
PANEL = 'shares'
|
||||
ADD_PANEL = 'manila_ui.dashboards.project.shares.panel.Shares'
|
||||
# ADD_INSTALLED_APPS enables using html templates from within the plugin
|
||||
ADD_INSTALLED_APPS = ['manila_ui.dashboards.project']
|
||||
|
@ -1,78 +0,0 @@
|
||||
# Copyright 2013 Kylin, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from horizon import tables
|
||||
|
||||
|
||||
class QuotaFilterAction(tables.FilterAction):
|
||||
def filter(self, table, tenants, filter_string):
|
||||
q = filter_string.lower()
|
||||
|
||||
def comp(tenant):
|
||||
if q in tenant.name.lower():
|
||||
return True
|
||||
return False
|
||||
|
||||
return filter(comp, tenants)
|
||||
|
||||
|
||||
class UpdateDefaultQuotas(tables.LinkAction):
|
||||
name = "update_defaults"
|
||||
verbose_name = _("Update Defaults")
|
||||
url = "horizon:admin:defaults:update_defaults"
|
||||
classes = ("ajax-modal", "btn-edit")
|
||||
|
||||
|
||||
def get_quota_name(quota):
|
||||
QUOTA_NAMES = {
|
||||
'injected_file_content_bytes': _('Injected File Content Bytes'),
|
||||
'injected_file_path_bytes': _('Length of Injected File Path'),
|
||||
'metadata_items': _('Metadata Items'),
|
||||
'cores': _('VCPUs'),
|
||||
'instances': _('Instances'),
|
||||
'injected_files': _('Injected Files'),
|
||||
'volumes': _('Volumes'),
|
||||
'shares': _('Shares'),
|
||||
'share_networks': _('Share Networks'),
|
||||
'snapshots': _('Snapshots'),
|
||||
'gigabytes': _('Gigabytes'),
|
||||
'ram': _('RAM (MB)'),
|
||||
'floating_ips': _('Floating IPs'),
|
||||
'security_groups': _('Security Groups'),
|
||||
'security_group_rules': _('Security Group Rules'),
|
||||
'key_pairs': _('Key Pairs'),
|
||||
'fixed_ips': _('Fixed IPs'),
|
||||
'volumes_volume_luks': _('LUKS Volumes'),
|
||||
'snapshots_volume_luks': _('LUKS Volume Snapshots'),
|
||||
'gigabytes_volume_luks':
|
||||
_('Total Size of LUKS Volumes and Snapshots (GB)'),
|
||||
'dm-crypt': _('dm-crypt'),
|
||||
}
|
||||
return QUOTA_NAMES.get(quota.name, quota.name.replace("_", " ").title())
|
||||
|
||||
|
||||
class QuotasTable(tables.DataTable):
|
||||
name = tables.Column(get_quota_name, verbose_name=_('Quota Name'))
|
||||
limit = tables.Column("limit", verbose_name=_('Limit'))
|
||||
|
||||
def get_object_id(self, obj):
|
||||
return obj.name
|
||||
|
||||
class Meta(object):
|
||||
name = "quotas"
|
||||
verbose_name = _("Quotas")
|
||||
table_actions = (QuotaFilterAction, UpdateDefaultQuotas)
|
||||
multi_select = False
|
12
manila_ui/dashboards/project/templates/usage.html
Normal file
12
manila_ui/dashboards/project/templates/usage.html
Normal file
@ -0,0 +1,12 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load i18n %}
|
||||
{% block title %}{% trans "Instance Overview" %}{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
{% include "_limit_summary.html" %}
|
||||
|
||||
{% if simple_tenant_usage_enabled %}
|
||||
{% include "horizon/common/_usage_summary.html" %}
|
||||
{{ table.render }}
|
||||
{% endif %}
|
||||
{% endblock %}
|
@ -1,12 +1,26 @@
|
||||
import functools
|
||||
import sys
|
||||
|
||||
from horizon import exceptions
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
import horizon
|
||||
|
||||
from manila_ui.api import manila
|
||||
|
||||
from openstack_dashboard.usage import quotas
|
||||
from openstack_dashboard.api import base
|
||||
from openstack_dashboard.dashboards.admin.defaults import tables as quota_tbl
|
||||
from openstack_dashboard.dashboards.admin.defaults import views \
|
||||
as default_views
|
||||
from openstack_dashboard.dashboards.admin.defaults import workflows \
|
||||
as default_workflows
|
||||
from openstack_dashboard.dashboards.identity.projects import workflows \
|
||||
as project_workflows
|
||||
from openstack_dashboard.dashboards.identity.projects import views \
|
||||
as project_views
|
||||
from openstack_dashboard.dashboards.project.overview import views \
|
||||
as overview_views
|
||||
from openstack_dashboard.usage import base as usage_base
|
||||
from openstack_dashboard.usage import quotas
|
||||
|
||||
|
||||
def wrap(orig_func):
|
||||
@ -47,9 +61,14 @@ MANILA_QUOTA_FIELDS = (
|
||||
"gigabytes",
|
||||
"share_networks",
|
||||
)
|
||||
MANILA_QUOTA_NAMES = {
|
||||
'shares': _('Shares'),
|
||||
'share_networks': _('Shares Networks'),
|
||||
}
|
||||
|
||||
quotas.QUOTA_FIELDS = quotas.QUOTA_FIELDS + MANILA_QUOTA_FIELDS
|
||||
|
||||
|
||||
def _get_manila_disabled_quotas(request):
|
||||
disabled_quotas = []
|
||||
if not base.is_service_enabled(request, 'share'):
|
||||
@ -62,11 +81,14 @@ def _get_manila_quota_data(request, method_name, disabled_quotas=None,
|
||||
tenant_id=None):
|
||||
if not tenant_id:
|
||||
tenant_id = request.user.tenant_id
|
||||
if disabled_quotas is None:
|
||||
disabled_quotas = _get_manila_disabled_quotas(request)
|
||||
if 'shares' not in disabled_quotas:
|
||||
return getattr(manila, method_name)(request, tenant_id)
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
@wrap(quotas.get_default_quota_data)
|
||||
def get_default_quota_data(f, request, disabled_quotas=None, tenant_id=None):
|
||||
qs = f(request, disabled_quotas, tenant_id)
|
||||
@ -132,6 +154,167 @@ def tenant_limit_usages(f, request):
|
||||
limits['totalSnapshotsUsed'] = len(snapshots)
|
||||
except Exception:
|
||||
msg = _("Unable to retrieve share limit information.")
|
||||
exceptions.handle(request, msg)
|
||||
horizon.exceptions.handle(request, msg)
|
||||
|
||||
return limits
|
||||
|
||||
|
||||
@wrap(quota_tbl.get_quota_name)
|
||||
def get_quota_name(f, quota):
|
||||
if quota.name in MANILA_QUOTA_NAMES:
|
||||
return MANILA_QUOTA_NAMES.get(quota.name)
|
||||
else:
|
||||
return f(quota)
|
||||
|
||||
|
||||
#
|
||||
# Add manila fields to Admin/Defaults/Update Defaults
|
||||
#
|
||||
|
||||
|
||||
class ManilaUpdateDefaultQuotaAction(
|
||||
default_workflows.UpdateDefaultQuotasAction):
|
||||
shares = horizon.forms.IntegerField(min_value=-1, label=_("Shares"))
|
||||
share_networks = horizon.forms.IntegerField(min_value=-1,
|
||||
label=_("Share Networks"))
|
||||
|
||||
class Meta(object):
|
||||
name = _("Default Quota")
|
||||
slug = 'update_default_quotas'
|
||||
help_text = _("From here you can update the default quotas "
|
||||
"(max limits).")
|
||||
|
||||
|
||||
class ManilaUpdateDefaultQuotasStep(default_workflows.UpdateDefaultQuotasStep):
|
||||
action_class = ManilaUpdateDefaultQuotaAction
|
||||
contributes = quotas.QUOTA_FIELDS
|
||||
|
||||
|
||||
class ManilaUpdateDefaultQuotas(default_workflows.UpdateDefaultQuotas):
|
||||
default_steps = (ManilaUpdateDefaultQuotasStep,)
|
||||
|
||||
def handle(self, request, data):
|
||||
try:
|
||||
super(ManilaUpdateDefaultQuotas, self).handle(request, data)
|
||||
|
||||
if base.is_service_enabled(request, 'share'):
|
||||
manila_data = dict([(key, data[key]) for key in
|
||||
MANILA_QUOTA_FIELDS])
|
||||
manila.default_quota_update(request, **manila_data)
|
||||
|
||||
except Exception:
|
||||
horizon.exceptions.handle(request,
|
||||
_('Unable to update default quotas.'))
|
||||
|
||||
return True
|
||||
|
||||
|
||||
default_views.UpdateDefaultQuotasView.workflow_class = \
|
||||
ManilaUpdateDefaultQuotas
|
||||
|
||||
#
|
||||
# Add manila fields to Identity/Projects/Modify Quotas
|
||||
#
|
||||
|
||||
|
||||
class ManilaUpdateProjectQuotaAction(
|
||||
project_workflows.UpdateProjectQuotaAction):
|
||||
shares = horizon.forms.IntegerField(min_value=-1, label=_("Shares"))
|
||||
share_networks = horizon.forms.IntegerField(min_value=-1,
|
||||
label=_("Share Networks"))
|
||||
|
||||
class Meta(object):
|
||||
name = _("Quota")
|
||||
slug = 'update_quotas'
|
||||
help_text = _("Set maximum quotas for the project.")
|
||||
|
||||
project_workflows.UpdateProjectQuota.action_class = \
|
||||
ManilaUpdateProjectQuotaAction
|
||||
project_workflows.UpdateProjectQuota.contributes = quotas.QUOTA_FIELDS
|
||||
|
||||
|
||||
class ManilaUpdateProject(project_workflows.UpdateProject):
|
||||
def handle(self, request, data):
|
||||
try:
|
||||
super(ManilaUpdateProject, self).handle(request, data)
|
||||
|
||||
if base.is_service_enabled(request, 'share'):
|
||||
manila_data = dict([(key, data[key]) for key in
|
||||
MANILA_QUOTA_FIELDS])
|
||||
manila.tenant_quota_update(request,
|
||||
data['project_id'],
|
||||
**manila_data)
|
||||
|
||||
except Exception:
|
||||
horizon.exceptions.handle(request,
|
||||
_('Modified project information and '
|
||||
'members, but unable to modify '
|
||||
'project quotas.'))
|
||||
return True
|
||||
|
||||
project_views.UpdateProjectView.workflow_class = ManilaUpdateProject
|
||||
|
||||
#
|
||||
# Add manila fields to Identity/Projects/Create Project
|
||||
#
|
||||
|
||||
|
||||
class ManilaCreateProjectQuotaAction(
|
||||
project_workflows.CreateProjectQuotaAction):
|
||||
shares = horizon.forms.IntegerField(min_value=-1, label=_("Shares"))
|
||||
share_networks = horizon.forms.IntegerField(min_value=-1,
|
||||
label=_("Share Networks"))
|
||||
|
||||
class Meta(object):
|
||||
name = _("Quota")
|
||||
slug = 'create_quotas'
|
||||
help_text = _("Set maximum quotas for the project.")
|
||||
|
||||
project_workflows.CreateProjectQuota.action_class = \
|
||||
ManilaCreateProjectQuotaAction
|
||||
project_workflows.CreateProjectQuota.contributes = quotas.QUOTA_FIELDS
|
||||
|
||||
|
||||
class ManilaCreateProject(project_workflows.CreateProject):
|
||||
def handle(self, request, data):
|
||||
try:
|
||||
super(ManilaCreateProject, self).handle(request, data)
|
||||
|
||||
if base.is_service_enabled(request, 'share'):
|
||||
manila_data = dict([(key, data[key]) for key in
|
||||
MANILA_QUOTA_FIELDS])
|
||||
manila.tenant_quota_update(request,
|
||||
self.object.id,
|
||||
**manila_data)
|
||||
|
||||
except Exception:
|
||||
horizon.exceptions.handle(request,
|
||||
_('Unable to set project quotas.'))
|
||||
return True
|
||||
|
||||
project_views.CreateProjectView.workflow_class = ManilaCreateProject
|
||||
|
||||
#
|
||||
# Add extra pie charts to Project/Compute Overview
|
||||
#
|
||||
|
||||
|
||||
class ManilaBaseUsage(usage_base.BaseUsage):
|
||||
|
||||
def get_manila_limits(self):
|
||||
"""Get share limits if manila is enabled."""
|
||||
if not base.is_service_enabled(self.request, 'share'):
|
||||
return
|
||||
try:
|
||||
self.limits.update(manila.tenant_absolute_limits(self.request))
|
||||
except Exception:
|
||||
msg = _("Unable to retrieve share limit information.")
|
||||
horizon.exceptions.handle(self.request, msg)
|
||||
return
|
||||
|
||||
def get_limits(self):
|
||||
super(ManilaBaseUsage, self).get_limits()
|
||||
self.get_manila_limits()
|
||||
|
||||
overview_views.ProjectOverview.template_name = "usage.html"
|
||||
overview_views.ProjectOverview.usage_class = ManilaBaseUsage
|
||||
|
Loading…
x
Reference in New Issue
Block a user