From cd24b909eeab247d8491fcc9a2330e7bbc15b50c Mon Sep 17 00:00:00 2001 From: xiangxinyong Date: Thu, 22 Sep 2016 20:26:51 +0800 Subject: [PATCH] Add separate scheduled operations panel in Karbor dashboard As we discussed the dashboard features in the IRC Meeting, We need to add scheduled operations panel. Change-Id: I0733ce16354b97b1d31906d44c6fcc13fa82110c --- ...a_protection_scheduled_operations_panel.py | 21 +++++ .../scheduledoperations/__init__.py | 0 karbor_dashboard/scheduledoperations/panel.py | 25 +++++ .../scheduledoperations/tables.py | 42 +++++++++ karbor_dashboard/scheduledoperations/urls.py | 21 +++++ karbor_dashboard/scheduledoperations/views.py | 91 +++++++++++++++++++ .../templates/scheduledoperations/index.html | 10 ++ 7 files changed, 210 insertions(+) create mode 100644 karbor_dashboard/enabled/_6070_data_protection_scheduled_operations_panel.py create mode 100644 karbor_dashboard/scheduledoperations/__init__.py create mode 100644 karbor_dashboard/scheduledoperations/panel.py create mode 100644 karbor_dashboard/scheduledoperations/tables.py create mode 100644 karbor_dashboard/scheduledoperations/urls.py create mode 100644 karbor_dashboard/scheduledoperations/views.py create mode 100644 karbor_dashboard/templates/scheduledoperations/index.html diff --git a/karbor_dashboard/enabled/_6070_data_protection_scheduled_operations_panel.py b/karbor_dashboard/enabled/_6070_data_protection_scheduled_operations_panel.py new file mode 100644 index 0000000..f1d5e0c --- /dev/null +++ b/karbor_dashboard/enabled/_6070_data_protection_scheduled_operations_panel.py @@ -0,0 +1,21 @@ +# 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. + + +PANEL = 'scheduledoperations' +PANEL_GROUP = 'default' +PANEL_DASHBOARD = 'karbor' + +ADD_PANEL = \ + 'karbor_dashboard.scheduledoperations.panel.ScheduledOperations' diff --git a/karbor_dashboard/scheduledoperations/__init__.py b/karbor_dashboard/scheduledoperations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/karbor_dashboard/scheduledoperations/panel.py b/karbor_dashboard/scheduledoperations/panel.py new file mode 100644 index 0000000..2d7fefe --- /dev/null +++ b/karbor_dashboard/scheduledoperations/panel.py @@ -0,0 +1,25 @@ +# 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. + +from django.utils.translation import ugettext_lazy as _ +import horizon + +from karbor_dashboard import dashboard + + +class ScheduledOperations(horizon.Panel): + name = _("Scheduled Operations") + slug = 'scheduledoperations' + +dashboard.DataProtection.register(ScheduledOperations) diff --git a/karbor_dashboard/scheduledoperations/tables.py b/karbor_dashboard/scheduledoperations/tables.py new file mode 100644 index 0000000..148bdb4 --- /dev/null +++ b/karbor_dashboard/scheduledoperations/tables.py @@ -0,0 +1,42 @@ +# 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. + +from django.utils.translation import ugettext_lazy as _ + +from horizon import tables + + +class ScheduledOperationsTable(tables.DataTable): + id = tables.Column( + 'id', + verbose_name=_('ID')) + name = tables.Column( + 'name', + verbose_name=_('Name')) + operation_type = tables.Column( + 'operation_type', + verbose_name=_('Operation Type')) + plan_name = tables.Column( + 'plan_name', + verbose_name=_('Protection Plan')) + provider_name = tables.Column( + 'provider_name', + verbose_name=_('Protection Provider')) + trigger_name = tables.Column( + 'trigger_name', + verbose_name=_('Trigger')) + + class Meta(object): + name = 'scheduledoperations' + verbose_name = _('Scheduled Operations') diff --git a/karbor_dashboard/scheduledoperations/urls.py b/karbor_dashboard/scheduledoperations/urls.py new file mode 100644 index 0000000..09662fc --- /dev/null +++ b/karbor_dashboard/scheduledoperations/urls.py @@ -0,0 +1,21 @@ +# 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. + +from django.conf.urls import url +from karbor_dashboard.scheduledoperations import views + + +urlpatterns = [ + url(r'^$', views.IndexView.as_view(), name='index'), +] diff --git a/karbor_dashboard/scheduledoperations/views.py b/karbor_dashboard/scheduledoperations/views.py new file mode 100644 index 0000000..19a619d --- /dev/null +++ b/karbor_dashboard/scheduledoperations/views.py @@ -0,0 +1,91 @@ +# 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. + +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.scheduledoperations import tables + + +class IndexView(horizon_tables.DataTableView): + table_class = tables.ScheduledOperationsTable + template_name = 'scheduledoperations/index.html' + page_title = _("Scheduled Operations") + + def has_prev_data(self, table): + return self._prev + + def has_more_data(self, table): + return self._more + + def get_data(self): + request = self.request + prev_marker = request.GET.get( + tables.ScheduledOperationsTable._meta.prev_pagination_param, None) + + if prev_marker is not None: + marker = prev_marker + else: + marker = request.GET.get( + tables.ScheduledOperationsTable._meta.pagination_param, None) + reversed_order = prev_marker is not None + scheduledoperations = [] + try: + scheduledoperations, self._more, self._prev = \ + karborclient.scheduled_operation_list_paged( + self.request, + marker=marker, + paginate=True, + sort_dir='asc', + sort_key='name', + reversed_order=reversed_order) + + for scheduledoperation in scheduledoperations: + plan_name, provider_name, trigger_name = '' + operation_definition = scheduledoperation.operation_definition + + if "plan_id" in operation_definition.keys(): + plan = karborclient.plan_get( + self.request, + operation_definition["plan_id"]) + if plan: + plan_name = plan.name + + if "provider_id" in operation_definition.keys(): + provider = karborclient.provider_get( + self.request, + operation_definition["provider_id"]) + if provider: + provider_name = provider.name + + trigger = karborclient.trigger_get( + self.request, + scheduledoperation.trigger_id) + if trigger: + trigger_name = trigger.name + + setattr(scheduledoperation, "plan_name", plan_name) + setattr(scheduledoperation, "provider_name", provider_name) + setattr(scheduledoperation, "trigger_name", trigger_name) + + except Exception: + self._prev = False + self._more = False + exceptions.handle( + self.request, + _('Unable to retrieve scheduled operation list.')) + return scheduledoperations diff --git a/karbor_dashboard/templates/scheduledoperations/index.html b/karbor_dashboard/templates/scheduledoperations/index.html new file mode 100644 index 0000000..e9c5cef --- /dev/null +++ b/karbor_dashboard/templates/scheduledoperations/index.html @@ -0,0 +1,10 @@ +{% extends 'base.html' %} +{% load i18n %} + +{% block title %} + {% trans "Scheduled Operations" %} +{% endblock %} + +{% block main %} + {{ table.render }} +{% endblock %}