Reinit operation logs panel in Karbor dashboard

As we discussed the dashboard features in the IRC Meeting,
We need to reinit operation logs panel.

Change-Id: I5690d1afdfe083a8194fc2893e9868dda6cf54d3
This commit is contained in:
xiangxinyong 2016-09-24 11:23:03 +08:00
parent b83493d2c5
commit ed5c676157
5 changed files with 13 additions and 236 deletions

View File

@ -17,60 +17,24 @@ from django.utils.translation import ugettext_lazy as _
from horizon import tables
class OperationLogsProtectTable(tables.DataTable):
class OperationLogsTable(tables.DataTable):
id = tables.Column('id',
link="horizon:karbor:operationlogs:detail",
verbose_name=_('ID'))
name = tables.Column('name',
verbose_name=_('Name'))
type = tables.Column('type',
verbose_name=_('Type'))
status = tables.Column('status',
verbose_name=_('Status'))
class Meta(object):
name = 'operationlogs'
verbose_name = _('Operation Logs')
class OperationLogsRestoreTable(tables.DataTable):
id = tables.Column(
'id',
verbose_name=_('ID'))
name = tables.Column(
'name',
verbose_name=_('Protection Plan'))
type = tables.Column(
'type',
verbose_name=_('Type'))
status = tables.Column(
'status',
verbose_name=_('Status'))
restore_from_checkpoint = tables.Column(
'checkpoint_id',
verbose_name=_('Restore From Checkpoint'))
restore_target = tables.Column(
'restore_target',
verbose_name=_('Restore Target'))
protection_provider = tables.Column(
'provider_name',
verbose_name=_('Protection Provider'))
class Meta(object):
name = 'operationlogs'
verbose_name = _('Operation Logs')
class OperationLogsDeleteTable(tables.DataTable):
id = tables.Column('id',
link="horizon:karbor:operationlogs:detail",
verbose_name=_('ID'))
name = tables.Column('name',
verbose_name=_('Name'))
type = tables.Column('type',
verbose_name=_('Type'))
status = tables.Column('status',
verbose_name=_('Status'))
state = tables.Column('state',
verbose_name=_('State'))
expect_start_time = tables.Column(
'expect_start_time',
verbose_name=_('Expect Start Time'))
actual_start_time = tables.Column(
'actual_start_time',
verbose_name=_('Actual Start Time'))
end_time = tables.Column(
'end_time',
verbose_name=_('End Time'))
class Meta(object):
name = 'operationlogs'

View File

@ -1,39 +0,0 @@
# Copyright (c) 2016 Huawei, 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.
import collections
from django.utils.translation import ugettext_lazy as _
OPERATION_TYPE_FILTER = 'type_filter'
OPERATION_STATUS_FILTER = 'status_filter'
OPERATION_TYPE_PROTECT = 'Protect'
OPERATION_TYPE_RESTORE = 'Restore'
OPERATION_TYPE_DELETE = 'Delete'
OPERATION_TYPE_CHOICES = [(OPERATION_TYPE_PROTECT, _('Protect')),
(OPERATION_TYPE_RESTORE, _('Restore')),
(OPERATION_TYPE_DELETE, _('Delete'))]
OPERATION_TYPE_DICT = collections.OrderedDict(OPERATION_TYPE_CHOICES)
OPERATION_STATUS_COMMITED = 'commited'
OPERATION_STATUS_RUNNING = 'running'
OPERATION_STATUS_FINISHED = 'finished'
OPERATION_STATUS_FAILED = 'failed'
OPERATION_STATUS_CHOICES = [(OPERATION_STATUS_COMMITED, _('Commited')),
(OPERATION_STATUS_RUNNING, _('Running')),
(OPERATION_STATUS_FINISHED, _('Finished')),
(OPERATION_STATUS_FAILED, _('Failed'))]
OPERATION_STATUS_DICT = collections.OrderedDict(OPERATION_STATUS_CHOICES)

View File

@ -12,64 +12,18 @@
# License for the specific language governing permissions and limitations
# under the License.
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import tables as horizon_tables
from karbor_dashboard.api import karbor as karborclient
from karbor_dashboard.operationlogs import tables
from karbor_dashboard.operationlogs import utils
class IndexView(horizon_tables.DataTableView):
table_class = tables.OperationLogsProtectTable
table_class = tables.OperationLogsTable
template_name = 'operationlogs/index.html'
page_title = _("Operation Logs")
def get_table(self):
if not self.table_class:
raise AttributeError('You must specify a DataTable class for the '
'"table_class" attribute on %s.'
% self.__class__.__name__)
# Protect is the default operation type
type_filter = self.request.POST.get(utils.OPERATION_TYPE_FILTER,
utils.OPERATION_TYPE_PROTECT)
self.table_class = eval("tables.OperationLogs%sTable"
% str(type_filter))
if not hasattr(self, "table"):
self.table = self.table_class(self.request, **self.kwargs)
return self.table
def get_filter_list(self):
filters = {}
# Operation type
filters[utils.OPERATION_TYPE_FILTER] = \
self.request.POST.get(utils.OPERATION_TYPE_FILTER,
utils.OPERATION_TYPE_PROTECT)
# Operation status
filters[utils.OPERATION_STATUS_FILTER] = \
self.request.POST.get(utils.OPERATION_STATUS_FILTER, u"All")
return filters
def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
context["type_list"] = utils.OPERATION_TYPE_CHOICES
context["status_list"] = utils.OPERATION_STATUS_CHOICES
context["url"] = reverse("horizon:karbor:operationlogs:index")
context = dict(context, **self.get_filter_list())
return context
def get_search_opts(self):
search_opts = self.get_filter_list()
for key, val in search_opts.items():
if val == u"All":
search_opts.pop(key)
return search_opts
def has_prev_data(self, table):
return self._prev
@ -78,80 +32,4 @@ class IndexView(horizon_tables.DataTableView):
def get_data(self):
logs = []
try:
search_opts = self.get_search_opts()
search_type = search_opts.get(utils.OPERATION_TYPE_FILTER,
utils.OPERATION_TYPE_PROTECT)
if search_type == utils.OPERATION_TYPE_PROTECT:
logs = self.get_protect_data(search_opts)
elif search_type == utils.OPERATION_TYPE_RESTORE:
logs = self.get_restore_data(search_opts)
elif search_type == utils.OPERATION_TYPE_DELETE:
logs = self.get_delete_data(search_opts)
except Exception:
exceptions.handle(self.request,
_('Unable to retrieve operation log list.'))
return logs
def get_protect_data(self, search_opts):
# TODO(xiangxinyong) Get protect operation logs
logs, self._more, self._prev = ([], False, False)
return logs
def get_restore_data(self, search_opts):
prev_marker = self.request.GET.get(
tables.OperationLogsRestoreTable._meta.prev_pagination_param,
None)
if prev_marker is not None:
marker = prev_marker
else:
marker = self.request.GET.get(
tables.OperationLogsRestoreTable._meta.pagination_param,
None)
reversed_order = prev_marker is not None
logs = []
try:
# Get filter_opts
filter_opts = None
status = search_opts.get(utils.OPERATION_STATUS_FILTER, None)
if status is not None:
filter_opts = {"status": status}
# Get restore operation logs
logs, self._more, self._prev = \
karborclient.restore_list_paged(
self.request,
search_opts=filter_opts,
marker=marker,
paginate=True,
sort_dir='asc',
sort_key='id',
reversed_order=reversed_order)
for log in logs:
checkpoint = karborclient.checkpoint_get(self.request,
log.provider_id,
log.checkpoint_id)
provider = karborclient.provider_get(self.request,
log.provider_id)
setattr(log, "name", checkpoint.protection_plan["name"])
setattr(log, "type",
utils.OPERATION_TYPE_DICT[
utils.OPERATION_TYPE_RESTORE])
setattr(log, "provider_name", provider.name)
except Exception:
self._prev = False
self._more = False
exceptions.handle(self.request,
_('Unable to retrieve restore list.'))
return logs
def get_delete_data(self, search_opts):
# TODO(xiangxinyong) Get delete operation logs
logs, self._more, self._prev = ([], False, False)
return logs

View File

@ -1,25 +0,0 @@
{% load i18n %}
<form action="{{ url }}" method="post" class="pristine ng-valid">
{% csrf_token %}
<caption>
<div class="table_actions clearfix">
<div class="table_search">
<span style="font-size: 13px;vertical-align: middle">By Type:</span>
<select class="form-control" name="type_filter" style="width: auto;min-width: 160px">
{% for type in type_list %}
<option value={{ type.0 }} {% ifequal type_filter type.0 %} selected {% endifequal %}>{{ type.1 }}</option>
{% endfor %}
</select>
<span style="font-size: 13px;vertical-align: middle">By Status:</span>
<select class="form-control" name="status_filter" style="width: auto;min-width: 160px">
<option {% ifequal status_filter "All" %} selected {% endifequal %}>All</option>
{% for status in status_list %}
<option value={{ status.0 }} {% ifequal status_filter status.0 %} selected {% endifequal %}>{{ status.1 }}</option>
{% endfor %}
</select>
<button type="submit" class="btn btn-default" id="operation_logs_list_action_filter">Filter</button>
</div>
</div>
</caption>
</form>

View File

@ -6,6 +6,5 @@
{% endblock %}
{% block main %}
{% include "operationlogs/_index.html" %}
{{ table.render }}
{% endblock %}