Add delete backup operation in UI

Currently, there is no delete backup operation in freezer-web-ui, if
we want to delete a backup, we can only use the command line. This is
not convenient. This patch will add operation of deleting backup in
freezer web ui.

Change-Id: I31de6b8cafd7cba043ae050f9d4a83d697adb6c6
This commit is contained in:
howardlee 2017-07-11 10:54:53 +08:00 committed by howard lee
parent e779891638
commit 588b60044c
2 changed files with 43 additions and 3 deletions

View File

@ -571,3 +571,6 @@ class Backup(object):
}
job_id = self.client.jobs.create(job)
return Job(self.request).start(job_id)
def delete(self, backup_id):
return self.client.backups.delete(backup_id)

View File

@ -14,11 +14,14 @@
from django.core.urlresolvers import reverse
from django.utils import safestring
from django.utils.translation import ungettext_lazy
from django.utils.translation import ugettext_lazy as _
from horizon import tables
from horizon.utils import functions as utils
import disaster_recovery.api.api as freezer_api
from disaster_recovery.utils import shield
from disaster_recovery.utils import timestamp_to_string
@ -33,6 +36,37 @@ class Restore(tables.LinkAction):
kwargs={'backup_id': datum.id})
class DeleteBackup(tables.DeleteAction):
name = "delete"
classes = ("btn-danger",)
icon = "remove"
help_text = _("Delete backups is not recoverable.")
@staticmethod
def action_present(count):
return ungettext_lazy(
u"Delete Backup",
u"Delete Backups",
count
)
@staticmethod
def action_past(count):
return ungettext_lazy(
u"Deleted Backup",
u"Deleted Backups",
count
)
@shield("Unable to delete backup", redirect="backups:index")
def delete(self, request, backup_id):
return freezer_api.Backup(request).delete(backup_id)
class DeleteMultipleBackups(DeleteBackup):
name = "delete_multiple_backups"
class Filter(tables.FilterAction):
filter_type = "server"
filter_choices = (("exact", "Exact text", True),)
@ -100,9 +134,12 @@ class BackupsTable(tables.DataTable):
page_size = utils.get_page_size(self.request)
return "=".join(['offset', str(self.offset + page_size)])
def get_object_display_key(self, datum):
return 'backup_name'
class Meta:
name = "backups"
verbose_name = _("Backup History")
row_actions = (Restore,)
table_actions = (Filter,)
multi_select = False
row_actions = (Restore, DeleteBackup,)
table_actions = (Filter, DeleteMultipleBackups,)
multi_select = True