From ed586a0355fb99a5b1fbeadfc0625f0ceffe8b72 Mon Sep 17 00:00:00 2001 From: Sergio Cazzolato Date: Tue, 18 Mar 2014 11:04:50 -0300 Subject: [PATCH] Remove the update default quotas feature The default quota panel has been moved to a tab in the system info panel. The update default quotas feature has been removed. The cinder quota-class methods have been removed to keep consistency. The test cases and the apis for nova and cinder have been modified according the change. This change is done to support the change: I1110022d6f628d03aaf363da707f2d2ef1600437 Change-Id: I193c7209d9681b6d69afe0d996153ac86850d243 Closes-Bug: #1292589 --- doc/source/topics/settings.rst | 8 +- openstack_dashboard/api/cinder.py | 4 - openstack_dashboard/api/nova.py | 4 - openstack_dashboard/conf/cinder_policy.json | 1 - openstack_dashboard/conf/nova_policy.json | 2 - .../dashboards/admin/dashboard.py | 2 +- .../dashboards/admin/defaults/__init__.py | 0 .../dashboards/admin/defaults/panel.py | 29 ---- .../dashboards/admin/defaults/tables.py | 77 ---------- .../dashboards/admin/defaults/tabs.py | 46 ------ .../defaults/templates/defaults/index.html | 15 -- .../dashboards/admin/defaults/tests.py | 139 ------------------ .../dashboards/admin/defaults/urls.py | 26 ---- .../dashboards/admin/defaults/views.py | 49 ------ .../dashboards/admin/defaults/workflows.py | 101 ------------- .../dashboards/admin/info/tables.py | 51 +++++++ .../dashboards/admin/info/tabs.py | 19 ++- .../dashboards/admin/info/tests.py | 79 +++++++++- .../_70_admin_default_panel.py.example | 4 +- .../panel_config/_30_admin_default_panel.py | 4 +- .../test/test_plugins/panel_tests.py | 2 +- 21 files changed, 156 insertions(+), 506 deletions(-) delete mode 100644 openstack_dashboard/dashboards/admin/defaults/__init__.py delete mode 100644 openstack_dashboard/dashboards/admin/defaults/panel.py delete mode 100644 openstack_dashboard/dashboards/admin/defaults/tables.py delete mode 100644 openstack_dashboard/dashboards/admin/defaults/tabs.py delete mode 100644 openstack_dashboard/dashboards/admin/defaults/templates/defaults/index.html delete mode 100644 openstack_dashboard/dashboards/admin/defaults/tests.py delete mode 100644 openstack_dashboard/dashboards/admin/defaults/urls.py delete mode 100644 openstack_dashboard/dashboards/admin/defaults/views.py delete mode 100644 openstack_dashboard/dashboards/admin/defaults/workflows.py diff --git a/doc/source/topics/settings.rst b/doc/source/topics/settings.rst index 5ec9a2a6b5..38d82c294d 100644 --- a/doc/source/topics/settings.rst +++ b/doc/source/topics/settings.rst @@ -584,7 +584,7 @@ Examples -------- To add a new panel to the Admin panel group in Admin dashboard, create a file -``openstack_dashboard/local/enabled/_60_admin_add_panel.py`` with the follwing +``openstack_dashboard/local/enabled/_60_admin_add_panel.py`` with the following content:: PANEL = 'plugin_panel' @@ -601,11 +601,11 @@ the following content:: PANEL_GROUP = 'admin' REMOVE_PANEL = True -To change the default panel of Admin dashboard to Defaults panel, create a file +To change the default panel of Admin dashboard to Instances panel, create a file ``openstack_dashboard/local/enabled/_80_admin_default_panel.py`` with the following content:: - PANEL = 'defaults' + PANEL = 'instances' PANEL_DASHBOARD = 'admin' PANEL_GROUP = 'admin' - DEFAULT_PANEL = 'defaults' + DEFAULT_PANEL = 'instances' diff --git a/openstack_dashboard/api/cinder.py b/openstack_dashboard/api/cinder.py index 7b123c94fd..1860a6d449 100644 --- a/openstack_dashboard/api/cinder.py +++ b/openstack_dashboard/api/cinder.py @@ -237,10 +237,6 @@ def default_quota_get(request, tenant_id): return base.QuotaSet(cinderclient(request).quotas.defaults(tenant_id)) -def default_quota_update(request, **kwargs): - cinderclient(request).quota_classes.update(DEFAULT_QUOTA_NAME, **kwargs) - - def volume_type_list(request): return cinderclient(request).volume_types.list() diff --git a/openstack_dashboard/api/nova.py b/openstack_dashboard/api/nova.py index cb22a87819..a17bde9501 100644 --- a/openstack_dashboard/api/nova.py +++ b/openstack_dashboard/api/nova.py @@ -622,10 +622,6 @@ def default_quota_get(request, tenant_id): return base.QuotaSet(novaclient(request).quotas.defaults(tenant_id)) -def default_quota_update(request, **kwargs): - novaclient(request).quota_classes.update(DEFAULT_QUOTA_NAME, **kwargs) - - def usage_get(request, tenant_id, start, end): return NovaUsage(novaclient(request).usage.get(tenant_id, start, end)) diff --git a/openstack_dashboard/conf/cinder_policy.json b/openstack_dashboard/conf/cinder_policy.json index 726f3052db..4c1e140b9d 100644 --- a/openstack_dashboard/conf/cinder_policy.json +++ b/openstack_dashboard/conf/cinder_policy.json @@ -28,7 +28,6 @@ "volume_extension:quotas:show": [], "volume_extension:quotas:update": [["rule:admin_api"]], - "volume_extension:quota_classes": [], "volume_extension:volume_admin_actions:reset_status": [["rule:admin_api"]], "volume_extension:snapshot_admin_actions:reset_status": [["rule:admin_api"]], diff --git a/openstack_dashboard/conf/nova_policy.json b/openstack_dashboard/conf/nova_policy.json index 487e46c118..f53c1b2582 100644 --- a/openstack_dashboard/conf/nova_policy.json +++ b/openstack_dashboard/conf/nova_policy.json @@ -166,8 +166,6 @@ "compute_extension:v3:os-quota-sets:show": "", "compute_extension:v3:os-quota-sets:update": "rule:admin_api", "compute_extension:v3:os-quota-sets:delete": "rule:admin_api", - "compute_extension:quota_classes": "", - "compute_extension:v3:os-quota-class-sets": "", "compute_extension:rescue": "", "compute_extension:v3:os-rescue": "", "compute_extension:security_group_default_rules": "rule:admin_api", diff --git a/openstack_dashboard/dashboards/admin/dashboard.py b/openstack_dashboard/dashboards/admin/dashboard.py index a4ad7a588f..264813f776 100644 --- a/openstack_dashboard/dashboards/admin/dashboard.py +++ b/openstack_dashboard/dashboards/admin/dashboard.py @@ -24,7 +24,7 @@ class SystemPanels(horizon.PanelGroup): name = _("System Panel") panels = ('overview', 'metering', 'hypervisors', 'aggregates', 'instances', 'volumes', 'flavors', 'images', - 'networks', 'routers', 'defaults', 'info') + 'networks', 'routers', 'info') class IdentityPanels(horizon.PanelGroup): diff --git a/openstack_dashboard/dashboards/admin/defaults/__init__.py b/openstack_dashboard/dashboards/admin/defaults/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/openstack_dashboard/dashboards/admin/defaults/panel.py b/openstack_dashboard/dashboards/admin/defaults/panel.py deleted file mode 100644 index fd4b0923e2..0000000000 --- a/openstack_dashboard/dashboards/admin/defaults/panel.py +++ /dev/null @@ -1,29 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# 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 _ - -import horizon - -from openstack_dashboard.dashboards.admin import dashboard - - -class Defaults(horizon.Panel): - name = _("Defaults") - slug = 'defaults' - - -dashboard.Admin.register(Defaults) diff --git a/openstack_dashboard/dashboards/admin/defaults/tables.py b/openstack_dashboard/dashboards/admin/defaults/tables.py deleted file mode 100644 index 6cc3633067..0000000000 --- a/openstack_dashboard/dashboards/admin/defaults/tables.py +++ /dev/null @@ -1,77 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# 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': _('Injected File Path Bytes'), - 'metadata_items': _('Metadata Items'), - 'cores': _('VCPUs'), - 'instances': _('Instances'), - 'injected_files': _('Injected Files'), - 'volumes': _('Volumes'), - '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 Volumes Snapshots'), - 'gigabytes_volume_luks': _('LUKS Volumes Size (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: - name = "quotas" - verbose_name = _("Quotas") - table_actions = (QuotaFilterAction, UpdateDefaultQuotas) - multi_select = False diff --git a/openstack_dashboard/dashboards/admin/defaults/tabs.py b/openstack_dashboard/dashboards/admin/defaults/tabs.py deleted file mode 100644 index fb966fd3ea..0000000000 --- a/openstack_dashboard/dashboards/admin/defaults/tabs.py +++ /dev/null @@ -1,46 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# 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 exceptions -from horizon import tabs - -from openstack_dashboard.usage import quotas - -from openstack_dashboard.dashboards.admin.defaults import tables - - -class DefaultQuotasTab(tabs.TableTab): - table_classes = (tables.QuotasTable,) - name = _("Default Quotas") - slug = "quotas" - template_name = ("horizon/common/_detail_table.html") - - def get_quotas_data(self): - request = self.tab_group.request - try: - data = quotas.get_default_quota_data(request) - except Exception: - data = [] - exceptions.handle(self.request, _('Unable to get quota info.')) - return data - - -class DefaultsTabs(tabs.TabGroup): - slug = "defaults" - tabs = (DefaultQuotasTab,) - sticky = True diff --git a/openstack_dashboard/dashboards/admin/defaults/templates/defaults/index.html b/openstack_dashboard/dashboards/admin/defaults/templates/defaults/index.html deleted file mode 100644 index aee673ae28..0000000000 --- a/openstack_dashboard/dashboards/admin/defaults/templates/defaults/index.html +++ /dev/null @@ -1,15 +0,0 @@ -{% extends 'base.html' %} -{% load i18n %} -{% block title %}{% trans "Defaults" %}{% endblock %} - -{% block page_header %} - {% include "horizon/common/_page_header.html" with title=_("Defaults")%} -{% endblock page_header %} - -{% block main %} -
-
- {{ tab_group.render }} -
-
-{% endblock %} diff --git a/openstack_dashboard/dashboards/admin/defaults/tests.py b/openstack_dashboard/dashboards/admin/defaults/tests.py deleted file mode 100644 index dc0634dfa2..0000000000 --- a/openstack_dashboard/dashboards/admin/defaults/tests.py +++ /dev/null @@ -1,139 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# 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.core.urlresolvers import reverse -from django import http -from mox import IsA # noqa - -from openstack_dashboard import api -from openstack_dashboard.test import helpers as test -from openstack_dashboard.usage import quotas - -INDEX_URL = reverse('horizon:admin:defaults:index') - - -class ServicesViewTests(test.BaseAdminViewTests): - def test_index(self): - self._test_index(neutron_enabled=True) - - def test_index_with_neutron_disabled(self): - self._test_index(neutron_enabled=False) - - def test_index_with_neutron_sg_disabled(self): - self._test_index(neutron_enabled=True, - neutron_sg_enabled=False) - - def _test_index(self, neutron_enabled=True, neutron_sg_enabled=True): - # Neutron does not have an API for getting default system - # quotas. When not using Neutron, the floating ips quotas - # should be in the list. - self.mox.StubOutWithMock(api.nova, 'default_quota_get') - self.mox.StubOutWithMock(api.cinder, 'default_quota_get') - self.mox.StubOutWithMock(api.base, 'is_service_enabled') - if neutron_enabled: - self.mox.StubOutWithMock(api.neutron, 'is_extension_supported') - - api.base.is_service_enabled(IsA(http.HttpRequest), 'volume') \ - .AndReturn(True) - api.base.is_service_enabled(IsA(http.HttpRequest), 'network') \ - .MultipleTimes().AndReturn(neutron_enabled) - - api.nova.default_quota_get(IsA(http.HttpRequest), - self.tenant.id).AndReturn(self.quotas.nova) - api.cinder.default_quota_get(IsA(http.HttpRequest), self.tenant.id) \ - .AndReturn(self.cinder_quotas.first()) - if neutron_enabled: - api.neutron.is_extension_supported( - IsA(http.HttpRequest), - 'security-group').AndReturn(neutron_sg_enabled) - - self.mox.ReplayAll() - - res = self.client.get(INDEX_URL) - - self.assertTemplateUsed(res, 'admin/defaults/index.html') - - quotas_tab = res.context['tab_group'].get_tab('quotas') - expected_tabs = ['', - '', - '', - '', - '', - '', - '', - '', - '', - '', - '', - '', - ''] - if neutron_enabled: - expected_tabs.remove('') - expected_tabs.remove('') - if neutron_sg_enabled: - expected_tabs.remove('') - expected_tabs.remove('') - - self.assertQuerysetEqual(quotas_tab._tables['quotas'].data, - expected_tabs, - ordered=False) - - -class UpdateDefaultQuotasTests(test.BaseAdminViewTests): - def _get_quota_info(self, quota): - quota_data = {} - for field in (quotas.QUOTA_FIELDS + quotas.MISSING_QUOTA_FIELDS): - if field != 'fixed_ips': - limit = quota.get(field).limit or 10 - quota_data[field] = int(limit) - return quota_data - - @test.create_stubs({api.nova: ('default_quota_update', ), - api.cinder: ('default_quota_update', ), - quotas: ('get_default_quota_data', - 'get_disabled_quotas')}) - def test_update_default_quotas(self): - quota = self.quotas.first() - - # init - quotas.get_disabled_quotas(IsA(http.HttpRequest)) \ - .AndReturn(self.disabled_quotas.first()) - quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota) - - # update some fields - quota[0].limit = 123 - quota[1].limit = -1 - updated_quota = self._get_quota_info(quota) - - # handle - nova_fields = quotas.NOVA_QUOTA_FIELDS + quotas.MISSING_QUOTA_FIELDS - nova_updated_quota = dict([(key, updated_quota[key]) for key in - nova_fields if key != 'fixed_ips']) - api.nova.default_quota_update(IsA(http.HttpRequest), - **nova_updated_quota) - - cinder_updated_quota = dict([(key, updated_quota[key]) for key in - quotas.CINDER_QUOTA_FIELDS]) - api.cinder.default_quota_update(IsA(http.HttpRequest), - **cinder_updated_quota) - - self.mox.ReplayAll() - - url = reverse('horizon:admin:defaults:update_defaults') - res = self.client.post(url, updated_quota) - - self.assertNoFormErrors(res) - self.assertRedirectsNoFollow(res, INDEX_URL) diff --git a/openstack_dashboard/dashboards/admin/defaults/urls.py b/openstack_dashboard/dashboards/admin/defaults/urls.py deleted file mode 100644 index 405e744864..0000000000 --- a/openstack_dashboard/dashboards/admin/defaults/urls.py +++ /dev/null @@ -1,26 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# 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.conf.urls import patterns # noqa -from django.conf.urls import url # noqa - -from openstack_dashboard.dashboards.admin.defaults import views - - -urlpatterns = patterns('openstack_dashboard.dashboards.admin.defaults.views', - url(r'^$', views.IndexView.as_view(), name='index'), - url(r'^update_defaults$', - views.UpdateDefaultQuotasView.as_view(), name='update_defaults')) diff --git a/openstack_dashboard/dashboards/admin/defaults/views.py b/openstack_dashboard/dashboards/admin/defaults/views.py deleted file mode 100644 index 6ef3ab6798..0000000000 --- a/openstack_dashboard/dashboards/admin/defaults/views.py +++ /dev/null @@ -1,49 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# 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 tabs -from horizon import workflows - -from openstack_dashboard.dashboards.admin.defaults import tabs as project_tabs -from openstack_dashboard.dashboards.admin.defaults import workflows as \ - project_workflows -from openstack_dashboard.usage import quotas - - -class IndexView(tabs.TabbedTableView): - tab_group_class = project_tabs.DefaultsTabs - template_name = 'admin/defaults/index.html' - - -class UpdateDefaultQuotasView(workflows.WorkflowView): - workflow_class = project_workflows.UpdateDefaultQuotas - - def get_initial(self): - initial = super(UpdateDefaultQuotasView, self).get_initial() - - # get initial quota defaults - try: - quota_defaults = quotas.get_default_quota_data(self.request) - for field in (quotas.QUOTA_FIELDS + quotas.MISSING_QUOTA_FIELDS): - initial[field] = quota_defaults.get(field).limit - - except Exception: - error_msg = _('Unable to retrieve default quota values.') - self.add_error_to_step(error_msg, 'update_default_quotas') - - return initial diff --git a/openstack_dashboard/dashboards/admin/defaults/workflows.py b/openstack_dashboard/dashboards/admin/defaults/workflows.py deleted file mode 100644 index b1ffe2215c..0000000000 --- a/openstack_dashboard/dashboards/admin/defaults/workflows.py +++ /dev/null @@ -1,101 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# 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 exceptions -from horizon import forms -from horizon import workflows - -from openstack_dashboard.api import base -from openstack_dashboard.api import cinder -from openstack_dashboard.api import nova -from openstack_dashboard.usage import quotas - -ALL_NOVA_QUOTA_FIELDS = quotas.NOVA_QUOTA_FIELDS + quotas.MISSING_QUOTA_FIELDS - - -class UpdateDefaultQuotasAction(workflows.Action): - ifcb_label = _("Injected File Content Bytes") - ifpb_label = _("Injected File Path Bytes") - injected_file_content_bytes = forms.IntegerField(min_value=-1, - label=ifcb_label) - metadata_items = forms.IntegerField(min_value=-1, - label=_("Metadata Items")) - ram = forms.IntegerField(min_value=-1, label=_("RAM (MB)")) - floating_ips = forms.IntegerField(min_value=-1, label=_("Floating IPs")) - key_pairs = forms.IntegerField(min_value=-1, label=_("Key Pairs")) - injected_file_path_bytes = forms.IntegerField(min_value=-1, - label=ifpb_label) - instances = forms.IntegerField(min_value=-1, label=_("Instances")) - security_group_rules = forms.IntegerField(min_value=-1, - label=_("Security Group Rules")) - injected_files = forms.IntegerField(min_value=-1, - label=_("Injected Files")) - cores = forms.IntegerField(min_value=-1, label=_("VCPUs")) - security_groups = forms.IntegerField(min_value=-1, - label=_("Security Groups")) - gigabytes = forms.IntegerField(min_value=-1, label=_("Gigabytes")) - snapshots = forms.IntegerField(min_value=-1, label=_("Snapshots")) - volumes = forms.IntegerField(min_value=-1, label=_("Volumes")) - - def __init__(self, request, *args, **kwargs): - super(UpdateDefaultQuotasAction, self).__init__(request, - *args, - **kwargs) - disabled_quotas = quotas.get_disabled_quotas(request) - for field in disabled_quotas: - if field in self.fields: - self.fields[field].required = False - self.fields[field].widget = forms.HiddenInput() - - class Meta: - name = _("Default Quotas") - slug = 'update_default_quotas' - help_text = _("From here you can update the default quotas " - "(max limits).") - - -class UpdateDefaultQuotasStep(workflows.Step): - action_class = UpdateDefaultQuotasAction - contributes = (quotas.QUOTA_FIELDS + quotas.MISSING_QUOTA_FIELDS) - - -class UpdateDefaultQuotas(workflows.Workflow): - slug = "update_default_quotas" - name = _("Update Default Quotas") - finalize_button_name = _("Update Defaults") - success_message = _('Default quotas updated.') - failure_message = _('Unable to update default quotas.') - success_url = "horizon:admin:defaults:index" - default_steps = (UpdateDefaultQuotasStep,) - - def handle(self, request, data): - # Update the default quotas. - # `fixed_ips` update for quota class is not supported by novaclient - nova_data = dict([(key, data[key]) for key in ALL_NOVA_QUOTA_FIELDS - if key != 'fixed_ips']) - try: - nova.default_quota_update(request, **nova_data) - - if base.is_service_enabled(request, 'volume'): - cinder_data = dict([(key, data[key]) for key in - quotas.CINDER_QUOTA_FIELDS]) - cinder.default_quota_update(request, **cinder_data) - except Exception: - exceptions.handle(request, _('Unable to update default quotas.')) - return True diff --git a/openstack_dashboard/dashboards/admin/info/tables.py b/openstack_dashboard/dashboards/admin/info/tables.py index 3250395adc..672b313bfb 100644 --- a/openstack_dashboard/dashboards/admin/info/tables.py +++ b/openstack_dashboard/dashboards/admin/info/tables.py @@ -144,3 +144,54 @@ class NetworkAgentsTable(tables.DataTable): verbose_name = _("Network Agents") table_actions = (NetworkAgentsFilterAction,) multi_select = False + + +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) + + +def get_quota_name(quota): + QUOTA_NAMES = { + 'injected_file_content_bytes': _('Injected File Content Bytes'), + 'injected_file_path_bytes': _('Injected File Path Bytes'), + 'metadata_items': _('Metadata Items'), + 'cores': _('VCPUs'), + 'instances': _('Instances'), + 'injected_files': _('Injected Files'), + 'volumes': _('Volumes'), + '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 Volumes Snapshots'), + 'gigabytes_volume_luks': _('LUKS Volumes Size (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: + name = "quotas" + verbose_name = _("Quotas") + table_actions = (QuotaFilterAction,) + multi_select = False diff --git a/openstack_dashboard/dashboards/admin/info/tabs.py b/openstack_dashboard/dashboards/admin/info/tabs.py index e33b1536c8..c3e23009dc 100644 --- a/openstack_dashboard/dashboards/admin/info/tabs.py +++ b/openstack_dashboard/dashboards/admin/info/tabs.py @@ -21,6 +21,7 @@ from openstack_dashboard.api import base from openstack_dashboard.api import keystone from openstack_dashboard.api import neutron from openstack_dashboard.api import nova +from openstack_dashboard.usage import quotas from openstack_dashboard.dashboards.admin.info import constants from openstack_dashboard.dashboards.admin.info import tables @@ -79,8 +80,24 @@ class NetworkAgentsTab(tabs.TableTab): return agents +class DefaultQuotasTab(tabs.TableTab): + table_classes = (tables.QuotasTable,) + name = _("Default Quotas") + slug = "quotas" + template_name = constants.INFO_DETAIL_TEMPLATE_NAME + + def get_quotas_data(self): + request = self.tab_group.request + try: + data = quotas.get_default_quota_data(request) + except Exception: + data = [] + exceptions.handle(self.request, _('Unable to get quota info.')) + return data + + class SystemInfoTabs(tabs.TabGroup): slug = "system_info" tabs = (ServicesTab, NovaServicesTab, - NetworkAgentsTab) + NetworkAgentsTab, DefaultQuotasTab) sticky = True diff --git a/openstack_dashboard/dashboards/admin/info/tests.py b/openstack_dashboard/dashboards/admin/info/tests.py index 655ecd4e64..2c1a9d2c19 100644 --- a/openstack_dashboard/dashboards/admin/info/tests.py +++ b/openstack_dashboard/dashboards/admin/info/tests.py @@ -16,6 +16,7 @@ from django.core.urlresolvers import reverse from django import http +from mox import IgnoreArg # noqa from mox import IsA # noqa from openstack_dashboard import api @@ -26,14 +27,22 @@ INDEX_URL = reverse('horizon:admin:info:index') class SystemInfoViewTests(test.BaseAdminViewTests): - @test.create_stubs({api.nova: ('service_list',), - api.neutron: ('agent_list',)}) + @test.create_stubs({api.base: ('is_service_enabled',), + api.nova: ('default_quota_get', 'service_list'), + api.neutron: ('agent_list', 'is_extension_supported')}) def test_index(self): services = self.services.list() api.nova.service_list(IsA(http.HttpRequest)).AndReturn(services) agents = self.agents.list() api.neutron.agent_list(IsA(http.HttpRequest)).AndReturn(agents) + api.base.is_service_enabled(IsA(http.HttpRequest), IgnoreArg()) \ + .MultipleTimes().AndReturn(True) + api.nova.default_quota_get(IsA(http.HttpRequest), + IgnoreArg()).AndReturn({}) + api.neutron.is_extension_supported(IsA(http.HttpRequest), + 'security-group').AndReturn(True) + self.mox.ReplayAll() res = self.client.get(INDEX_URL) @@ -58,3 +67,69 @@ class SystemInfoViewTests(test.BaseAdminViewTests): network_agents_tab._tables['network_agents'].data, [agent.__repr__() for agent in self.agents.list()] ) + + def test_default_quotas_index(self): + self._test_default_quotas_index(neutron_enabled=True) + + def test_default_quotas_index_with_neutron_disabled(self): + self._test_default_quotas_index(neutron_enabled=False) + + def test_default_quotas_index_with_neutron_sg_disabled(self): + self._test_default_quotas_index(neutron_enabled=True, + neutron_sg_enabled=False) + + @test.create_stubs({api.base: ('is_service_enabled',), + api.nova: ('default_quota_get', 'service_list'), + api.cinder: ('default_quota_get',)}) + def _test_default_quotas_index(self, neutron_enabled=True, + neutron_sg_enabled=True): + # Neutron does not have an API for getting default system + # quotas. When not using Neutron, the floating ips quotas + # should be in the list. + api.base.is_service_enabled(IsA(http.HttpRequest), 'volume') \ + .MultipleTimes().AndReturn(True) + api.base.is_service_enabled(IsA(http.HttpRequest), 'network') \ + .MultipleTimes().AndReturn(neutron_enabled) + + api.nova.service_list(IsA(http.HttpRequest)).AndReturn([]) + api.nova.default_quota_get(IsA(http.HttpRequest), + self.tenant.id).AndReturn(self.quotas.nova) + api.cinder.default_quota_get(IsA(http.HttpRequest), self.tenant.id)\ + .AndReturn(self.cinder_quotas.first()) + + if neutron_enabled: + self.mox.StubOutWithMock(api.neutron, 'agent_list') + api.neutron.agent_list(IsA(http.HttpRequest)).AndReturn([]) + + self.mox.StubOutWithMock(api.neutron, 'is_extension_supported') + api.neutron.is_extension_supported(IsA(http.HttpRequest), + 'security-group').AndReturn(neutron_sg_enabled) + + self.mox.ReplayAll() + + res = self.client.get(INDEX_URL) + + quotas_tab = res.context['tab_group'].get_tab('quotas') + expected_tabs = ['', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + '', + ''] + if neutron_enabled: + expected_tabs.remove('') + expected_tabs.remove('') + if neutron_sg_enabled: + expected_tabs.remove('') + expected_tabs.remove('') + + self.assertQuerysetEqual(quotas_tab._tables['quotas'].data, + expected_tabs, + ordered=False) diff --git a/openstack_dashboard/enabled/_70_admin_default_panel.py.example b/openstack_dashboard/enabled/_70_admin_default_panel.py.example index b38ebdaf89..23d3773ab1 100644 --- a/openstack_dashboard/enabled/_70_admin_default_panel.py.example +++ b/openstack_dashboard/enabled/_70_admin_default_panel.py.example @@ -1,9 +1,9 @@ # The name of the panel to be added to HORIZON_CONFIG. Required. -PANEL = 'defaults' +PANEL = 'instances' # The name of the dashboard the PANEL associated with. Required. PANEL_DASHBOARD = 'admin' # The name of the panel group the PANEL is associated with. PANEL_GROUP = 'admin' # If set, it will update the default panel of the PANEL_DASHBOARD. -DEFAULT_PANEL = 'defaults' +DEFAULT_PANEL = 'instances' diff --git a/openstack_dashboard/test/test_plugins/panel_config/_30_admin_default_panel.py b/openstack_dashboard/test/test_plugins/panel_config/_30_admin_default_panel.py index b38ebdaf89..23d3773ab1 100644 --- a/openstack_dashboard/test/test_plugins/panel_config/_30_admin_default_panel.py +++ b/openstack_dashboard/test/test_plugins/panel_config/_30_admin_default_panel.py @@ -1,9 +1,9 @@ # The name of the panel to be added to HORIZON_CONFIG. Required. -PANEL = 'defaults' +PANEL = 'instances' # The name of the dashboard the PANEL associated with. Required. PANEL_DASHBOARD = 'admin' # The name of the panel group the PANEL is associated with. PANEL_GROUP = 'admin' # If set, it will update the default panel of the PANEL_DASHBOARD. -DEFAULT_PANEL = 'defaults' +DEFAULT_PANEL = 'instances' diff --git a/openstack_dashboard/test/test_plugins/panel_tests.py b/openstack_dashboard/test/test_plugins/panel_tests.py index a042be6498..525485464c 100644 --- a/openstack_dashboard/test/test_plugins/panel_tests.py +++ b/openstack_dashboard/test/test_plugins/panel_tests.py @@ -83,4 +83,4 @@ class PanelPluginTests(test.TestCase): def test_default_panel(self): dashboard = horizon.get_dashboard("admin") - self.assertEqual(dashboard.default_panel, 'defaults') + self.assertEqual('instances', dashboard.default_panel)