diff --git a/README.rst b/README.rst index 30e1cad..6d5e8a5 100644 --- a/README.rst +++ b/README.rst @@ -41,12 +41,7 @@ Install Karbor Dashboard with all dependencies in your virtual environment:: And enable it in Horizon:: - cp ../karbor-dashboard/karbor_dashboard/enabled/_6000_data_protection.py openstack_dashboard/local/enabled - cp ../karbor-dashboard/karbor_dashboard/enabled/_6010_data_protection_protection_plans_panel.py openstack_dashboard/local/enabled - cp ../karbor-dashboard/karbor_dashboard/enabled/_6020_data_protection_protection_providers_panel.py openstack_dashboard/local/enabled - cp ../karbor-dashboard/karbor_dashboard/enabled/_6030_data_protection_checkpoints_panel.py openstack_dashboard/local/enabled - cp ../karbor-dashboard/karbor_dashboard/enabled/_6040_data_protection_operation_logs_panel.py openstack_dashboard/local/enabled - cp ../karbor-dashboard/karbor_dashboard/enabled/_6050_data_protection_triggers_panel.py openstack_dashboard/local/enabled + cp ../karbor-dashboard/karbor_dashboard/enabled/* openstack_dashboard/local/enabled/ To run horizon with the newly enabled Karbor Dashboard plugin run:: diff --git a/karbor_dashboard/enabled/_6060_data_protection_restores_panel.py b/karbor_dashboard/enabled/_6060_data_protection_restores_panel.py new file mode 100644 index 0000000..85f6ff7 --- /dev/null +++ b/karbor_dashboard/enabled/_6060_data_protection_restores_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 = 'restores' +PANEL_GROUP = 'default' +PANEL_DASHBOARD = 'karbor' + +ADD_PANEL = \ + 'karbor_dashboard.restores.panel.Restores' diff --git a/karbor_dashboard/restores/__init__.py b/karbor_dashboard/restores/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/karbor_dashboard/restores/panel.py b/karbor_dashboard/restores/panel.py new file mode 100644 index 0000000..76f7ca4 --- /dev/null +++ b/karbor_dashboard/restores/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 Restores(horizon.Panel): + name = _("Restores") + slug = 'restores' + +dashboard.DataProtection.register(Restores) diff --git a/karbor_dashboard/restores/tables.py b/karbor_dashboard/restores/tables.py new file mode 100644 index 0000000..55355ed --- /dev/null +++ b/karbor_dashboard/restores/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 RestoresTable(tables.DataTable): + id = tables.Column( + 'id', + verbose_name=_('ID')) + name = tables.Column( + 'name', + verbose_name=_('Protection Plan')) + 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 = 'restores' + verbose_name = _('Restores') diff --git a/karbor_dashboard/restores/urls.py b/karbor_dashboard/restores/urls.py new file mode 100644 index 0000000..e6135a6 --- /dev/null +++ b/karbor_dashboard/restores/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.restores import views + + +urlpatterns = [ + url(r'^$', views.IndexView.as_view(), name='index'), +] diff --git a/karbor_dashboard/restores/views.py b/karbor_dashboard/restores/views.py new file mode 100644 index 0000000..801fb71 --- /dev/null +++ b/karbor_dashboard/restores/views.py @@ -0,0 +1,72 @@ +# 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.restores import tables + + +class IndexView(horizon_tables.DataTableView): + table_class = tables.RestoresTable + template_name = 'restores/index.html' + page_title = _("Restores") + + 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.RestoresTable._meta.prev_pagination_param, None) + + if prev_marker is not None: + marker = prev_marker + else: + marker = request.GET.get( + tables.RestoresTable._meta.pagination_param, None) + reversed_order = prev_marker is not None + restores = [] + try: + restores, self._more, self._prev = \ + karborclient.restore_list_paged( + self.request, + marker=marker, + paginate=True, + sort_dir='asc', + sort_key='id', + reversed_order=reversed_order) + + for restore in restores: + checkpoint = karborclient.checkpoint_get( + self.request, + restore.provider_id, + restore.checkpoint_id) + provider = karborclient.provider_get(self.request, + restore.provider_id) + setattr(restore, "name", checkpoint.protection_plan["name"]) + setattr(restore, "provider_name", provider.name) + + except Exception: + self._prev = False + self._more = False + exceptions.handle(self.request, + _('Unable to retrieve restore list.')) + return restores diff --git a/karbor_dashboard/templates/restores/index.html b/karbor_dashboard/templates/restores/index.html new file mode 100644 index 0000000..5cdd620 --- /dev/null +++ b/karbor_dashboard/templates/restores/index.html @@ -0,0 +1,10 @@ +{% extends 'base.html' %} +{% load i18n %} + +{% block title %} + {% trans "Restores" %} +{% endblock %} + +{% block main %} + {{ table.render }} +{% endblock %}