diff --git a/smaug_dashboard/protectionproviders/tabs.py b/smaug_dashboard/protectionproviders/tabs.py new file mode 100644 index 0000000..029cc14 --- /dev/null +++ b/smaug_dashboard/protectionproviders/tabs.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 tabs + +import simplejson as json +from smaug_dashboard.api import smaug as smaugclient + + +class OptionsSchemaTab(tabs.Tab): + name = _("Options Schema") + slug = "optionsschema" + template_name = "protectionproviders/_schema_contents.html" + + def get_context_data(self, request): + try: + provider_id = self.tab_group.kwargs['provider_id'] + provider = smaugclient.provider_get(request, provider_id) + + schema = {} + if provider is not None: + if 'options_schema' in provider.extended_info_schema: + schema = provider.extended_info_schema['options_schema'] + + return {"schema_contents": json.dumps(schema, indent=4)} + except Exception: + msg = _('Unable to retrieve provider contents.') + exceptions.handle(request, msg) + return None + + +class RestoreSchemaTab(tabs.Tab): + name = _("Restore Schema") + slug = "restoreschema" + template_name = "protectionproviders/_schema_contents.html" + + def get_context_data(self, request): + try: + provider_id = self.tab_group.kwargs['provider_id'] + provider = smaugclient.provider_get(request, provider_id) + + schema = {} + if provider is not None: + if 'restore_schema' in provider.extended_info_schema: + schema = provider.extended_info_schema['restore_schema'] + + return {"schema_contents": json.dumps(schema, indent=4)} + except Exception: + msg = _('Unable to retrieve provider contents.') + exceptions.handle(request, msg) + return None + + +class SavedInfoSchemaTab(tabs.Tab): + name = _("Saved Info Schema") + slug = "savedinfoschema" + template_name = "protectionproviders/_schema_contents.html" + + def get_context_data(self, request): + try: + provider_id = self.tab_group.kwargs['provider_id'] + provider = smaugclient.provider_get(request, provider_id) + schema = {} + if provider is not None: + if 'saved_info_schema' in provider.extended_info_schema: + schema = provider.extended_info_schema['saved_info_schema'] + + return {"schema_contents": json.dumps(schema, indent=4)} + except Exception: + msg = _('Unable to retrieve provider contents.') + exceptions.handle(request, msg) + return None + + +class ProviderDetailTabs(tabs.TabGroup): + slug = "provider_details" + tabs = (OptionsSchemaTab, RestoreSchemaTab, SavedInfoSchemaTab) diff --git a/smaug_dashboard/protectionproviders/urls.py b/smaug_dashboard/protectionproviders/urls.py index 3ba0b4a..7cd72e6 100644 --- a/smaug_dashboard/protectionproviders/urls.py +++ b/smaug_dashboard/protectionproviders/urls.py @@ -18,4 +18,6 @@ from smaug_dashboard.protectionproviders import views urlpatterns = [ url(r'^$', views.IndexView.as_view(), name='index'), + url(r'^(?P[^/]+)/detail/$', + views.DetailView.as_view(), name='detail'), ] diff --git a/smaug_dashboard/protectionproviders/views.py b/smaug_dashboard/protectionproviders/views.py index 09af5c5..cfb8e3a 100644 --- a/smaug_dashboard/protectionproviders/views.py +++ b/smaug_dashboard/protectionproviders/views.py @@ -12,13 +12,17 @@ # 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 horizon import tabs as horizon_tabs +from horizon.utils import memoized from smaug_dashboard.api import smaug as smaugclient from smaug_dashboard.protectionproviders import tables +from smaug_dashboard.protectionproviders import tabs class IndexView(horizon_tables.DataTableView): @@ -60,3 +64,31 @@ class IndexView(horizon_tables.DataTableView): self.request, _('Unable to retrieve protection providers list.')) return providers + + +class DetailView(horizon_tabs.TabView): + redirect_url = "horizon:smaug:protectionproviders:index" + tab_group_class = tabs.ProviderDetailTabs + template_name = 'protectionproviders/detail.html' + page_title = "{{ provider.name }}" + + def get_context_data(self, **kwargs): + context = super(DetailView, self).get_context_data(**kwargs) + context["provider"] = self.get_data() + return context + + @memoized.memoized_method + def get_data(self): + try: + provider_id = self.kwargs['provider_id'] + provider = smaugclient.provider_get(self.request, provider_id) + except Exception: + exceptions.handle( + self.request, + _('Unable to retrieve protection provider details.'), + redirect=reverse("horizon:smaug:protectionproviders:index")) + return provider + + def get_tabs(self, request, *args, **kwargs): + provider = self.get_data() + return self.tab_group_class(request, provider=provider, **kwargs) diff --git a/smaug_dashboard/templates/protectionproviders/_detail.html b/smaug_dashboard/templates/protectionproviders/_detail.html new file mode 100644 index 0000000..c38a59a --- /dev/null +++ b/smaug_dashboard/templates/protectionproviders/_detail.html @@ -0,0 +1,10 @@ +{% load i18n %} + +
+
+
{% trans "Provider Name" %}
+
{{ provider.name }}
+
{% trans "Provider Description" %}
+
{{ provider.description }}
+
+
diff --git a/smaug_dashboard/templates/protectionproviders/_schema_contents.html b/smaug_dashboard/templates/protectionproviders/_schema_contents.html new file mode 100644 index 0000000..a3b99b5 --- /dev/null +++ b/smaug_dashboard/templates/protectionproviders/_schema_contents.html @@ -0,0 +1,5 @@ +{% load i18n %} + +
+
{{ schema_contents }}
+
diff --git a/smaug_dashboard/templates/protectionproviders/detail.html b/smaug_dashboard/templates/protectionproviders/detail.html new file mode 100644 index 0000000..a7f218d --- /dev/null +++ b/smaug_dashboard/templates/protectionproviders/detail.html @@ -0,0 +1,24 @@ +{% extends 'base.html' %} +{% load i18n %} +{% load breadcrumb_nav %} + +{% block title %}{% trans "Protection Provider Details" %}{% endblock %} + +{% block page_header %} + +{% endblock %} + +{% block main %} +
+
+ {% include "protectionproviders/_detail.html" %} +
+
+
+
+ {{ tab_group.render }} +
+
+{% endblock %}