From a266b4bed558d9da71f371eb88c2d356dbdff70e Mon Sep 17 00:00:00 2001 From: Ivan Kolodyazhny Date: Wed, 2 Dec 2020 19:56:49 +0000 Subject: [PATCH] Add Backup Strategies table Commit 2c13af259a39c15e749580ee83598d90cd7f193c has missed files wich are added now. Change-Id: I1b692d7765bfd92dd255e0545b10e7325758935b --- .../content/backup_strategies/panel.py | 28 +++++++++ .../content/backup_strategies/tables.py | 59 +++++++++++++++++++ .../templates/backup_strategies/index.html | 7 +++ .../content/backup_strategies/urls.py | 21 +++++++ .../content/backup_strategies/views.py | 39 ++++++++++++ 5 files changed, 154 insertions(+) create mode 100644 trove_dashboard/content/backup_strategies/panel.py create mode 100644 trove_dashboard/content/backup_strategies/tables.py create mode 100644 trove_dashboard/content/backup_strategies/templates/backup_strategies/index.html create mode 100644 trove_dashboard/content/backup_strategies/urls.py create mode 100644 trove_dashboard/content/backup_strategies/views.py diff --git a/trove_dashboard/content/backup_strategies/panel.py b/trove_dashboard/content/backup_strategies/panel.py new file mode 100644 index 00000000..8d684dfd --- /dev/null +++ b/trove_dashboard/content/backup_strategies/panel.py @@ -0,0 +1,28 @@ +# Copyright 2013 Rackspace Hosting +# +# 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.project import dashboard + + +class BackupStrategies(horizon.Panel): + name = _("Backup Strategies") + slug = 'backup_strategies' + permissions = ('openstack.services.database', + 'openstack.services.object-store',) + + +dashboard.Project.register(BackupStrategies) diff --git a/trove_dashboard/content/backup_strategies/tables.py b/trove_dashboard/content/backup_strategies/tables.py new file mode 100644 index 00000000..e4563b80 --- /dev/null +++ b/trove_dashboard/content/backup_strategies/tables.py @@ -0,0 +1,59 @@ +# Copyright 2013 Rackspace Hosting +# +# 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 django.utils.translation import ungettext_lazy + +from horizon import tables + +from trove_dashboard import api + + +class DeleteBackupStrategy(tables.DeleteAction): + @staticmethod + def action_present(count): + return ungettext_lazy( + u"Delete Backup Strategy", + u"Delete Backup Strategies", + count + ) + + @staticmethod + def action_past(count): + return ungettext_lazy( + u"Backup Strategy Deleted", + u"Backup Strategies Deleted", + count + ) + + def delete(self, request, obj_id): + api.trove.backup_strategy_delete(request, project_id=obj_id) + + +class BackupStrategiesTable(tables.DataTable): + backend = tables.Column("backend", verbose_name=_("Backend")) + instance_id = tables.Column("instance_id", + verbose_name=_("instance_id")) + project_id = tables.Column("project_id", + verbose_name=_("Project")) + swift_container = tables.Column("swift_container", + verbose_name=_("Swift Container")) + + class Meta(object): + name = "backup_strategies" + verbose_name = _("Backup Strategies") + table_actions = (DeleteBackupStrategy,) + + def get_object_id(self, datum): + return datum.project_id diff --git a/trove_dashboard/content/backup_strategies/templates/backup_strategies/index.html b/trove_dashboard/content/backup_strategies/templates/backup_strategies/index.html new file mode 100644 index 00000000..5d3c0b96 --- /dev/null +++ b/trove_dashboard/content/backup_strategies/templates/backup_strategies/index.html @@ -0,0 +1,7 @@ +{% extends 'base.html' %} +{% load i18n %} +{% block title %}{% trans "Backup Strategies" %}{% endblock %} + +{% block main %} + {{ table.render }} +{% endblock %} diff --git a/trove_dashboard/content/backup_strategies/urls.py b/trove_dashboard/content/backup_strategies/urls.py new file mode 100644 index 00000000..cc90889a --- /dev/null +++ b/trove_dashboard/content/backup_strategies/urls.py @@ -0,0 +1,21 @@ +# Copyright 2013 Rackspace Hosting +# +# 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 url + +from trove_dashboard.content.backup_strategies import views + +urlpatterns = [ + url(r'^$', views.IndexView.as_view(), name='index'), +] diff --git a/trove_dashboard/content/backup_strategies/views.py b/trove_dashboard/content/backup_strategies/views.py new file mode 100644 index 00000000..4162a90f --- /dev/null +++ b/trove_dashboard/content/backup_strategies/views.py @@ -0,0 +1,39 @@ +# Copyright 2013 Rackspace Hosting +# +# 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. + +""" +Views for displaying database backups. +""" +from django.utils.translation import ugettext_lazy as _ + +from horizon import exceptions +from horizon import tables as horizon_tables + +from trove_dashboard import api +from trove_dashboard.content.backup_strategies import tables + + +class IndexView(horizon_tables.DataTableView): + table_class = tables.BackupStrategiesTable + template_name = 'project/backup_strategies/index.html' + page_title = _("Backup Strategies") + + def get_data(self): + try: + backups = api.trove.backup_strategy_list(self.request) + except Exception: + backups = [] + msg = _('Error getting backup strategies list.') + exceptions.handle(self.request, msg) + return backups