From f163e8b9618024b1a041d431f6029230e26dcf18 Mon Sep 17 00:00:00 2001 From: Tzu-Mainn Chen Date: Fri, 1 Aug 2014 23:21:44 +0200 Subject: [PATCH] Added Images panel Change-Id: Icf80250df8af0fc4cf9b7d6a19a116734f786653 --- tuskar_ui/infrastructure/dashboard.py | 1 + tuskar_ui/infrastructure/images/__init__.py | 0 tuskar_ui/infrastructure/images/panel.py | 27 +++++++++++++++ tuskar_ui/infrastructure/images/tables.py | 32 ++++++++++++++++++ .../images/templates/images/index.html | 17 ++++++++++ tuskar_ui/infrastructure/images/tests.py | 33 +++++++++++++++++++ tuskar_ui/infrastructure/images/urls.py | 23 +++++++++++++ tuskar_ui/infrastructure/images/views.py | 26 +++++++++++++++ 8 files changed, 159 insertions(+) create mode 100644 tuskar_ui/infrastructure/images/__init__.py create mode 100644 tuskar_ui/infrastructure/images/panel.py create mode 100644 tuskar_ui/infrastructure/images/tables.py create mode 100644 tuskar_ui/infrastructure/images/templates/images/index.html create mode 100644 tuskar_ui/infrastructure/images/tests.py create mode 100644 tuskar_ui/infrastructure/images/urls.py create mode 100644 tuskar_ui/infrastructure/images/views.py diff --git a/tuskar_ui/infrastructure/dashboard.py b/tuskar_ui/infrastructure/dashboard.py index b63e3f558..e31e92562 100644 --- a/tuskar_ui/infrastructure/dashboard.py +++ b/tuskar_ui/infrastructure/dashboard.py @@ -24,6 +24,7 @@ class BasePanels(horizon.PanelGroup): 'plans', 'nodes', 'flavors', + 'images', 'history', ) diff --git a/tuskar_ui/infrastructure/images/__init__.py b/tuskar_ui/infrastructure/images/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tuskar_ui/infrastructure/images/panel.py b/tuskar_ui/infrastructure/images/panel.py new file mode 100644 index 000000000..a897d14f5 --- /dev/null +++ b/tuskar_ui/infrastructure/images/panel.py @@ -0,0 +1,27 @@ +# -*- coding: utf8 -*- +# +# 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 tuskar_ui.infrastructure import dashboard + + +class Images(horizon.Panel): + name = _("Provisioning Images") + slug = "images" + + +dashboard.Infrastructure.register(Images) diff --git a/tuskar_ui/infrastructure/images/tables.py b/tuskar_ui/infrastructure/images/tables.py new file mode 100644 index 000000000..7451521a9 --- /dev/null +++ b/tuskar_ui/infrastructure/images/tables.py @@ -0,0 +1,32 @@ +# -*- coding: utf8 -*- +# +# 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 ImagesTable(tables.DataTable): + + name = tables.Column('name', + verbose_name=_("Image Name")) + disk_format = tables.Column('disk_format', + verbose_name=_("Format")) + + class Meta: + name = "images" + verbose_name = _("Provisioning Images") + multi_select = False + table_actions = () + row_actions = () diff --git a/tuskar_ui/infrastructure/images/templates/images/index.html b/tuskar_ui/infrastructure/images/templates/images/index.html new file mode 100644 index 000000000..5b92090b2 --- /dev/null +++ b/tuskar_ui/infrastructure/images/templates/images/index.html @@ -0,0 +1,17 @@ +{% extends 'infrastructure/base.html' %} +{% load i18n %} +{% block title %}{% trans 'Provisioning Images' %}{% endblock %} + +{% block page_header %} + {% include 'horizon/common/_page_header.html' with title=_('Provisioning Images') %} +{% endblock page_header %} + +{% block main %} +
+
+

{% trans "Provisioning Images" %}

+ {{ table.render }} +
+
+ +{% endblock %} diff --git a/tuskar_ui/infrastructure/images/tests.py b/tuskar_ui/infrastructure/images/tests.py new file mode 100644 index 000000000..979de6bb9 --- /dev/null +++ b/tuskar_ui/infrastructure/images/tests.py @@ -0,0 +1,33 @@ +# -*- coding: utf8 -*- +# +# 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.core import urlresolvers + +from mock import patch, call # noqa + +from tuskar_ui.test import helpers as test + + +INDEX_URL = urlresolvers.reverse( + 'horizon:infrastructure:images:index') + + +class ImagesTest(test.BaseAdminViewTests): + + def test_index(self): + with patch('openstack_dashboard.api.glance.image_list_detailed', + return_value=[self.images.list(), False, False]): + res = self.client.get(INDEX_URL) + + self.assertTemplateUsed(res, 'infrastructure/images/index.html') diff --git a/tuskar_ui/infrastructure/images/urls.py b/tuskar_ui/infrastructure/images/urls.py new file mode 100644 index 000000000..a9cf83663 --- /dev/null +++ b/tuskar_ui/infrastructure/images/urls.py @@ -0,0 +1,23 @@ +# -*- coding: utf8 -*- +# +# 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 import urls + +from tuskar_ui.infrastructure.images import views + + +urlpatterns = urls.patterns( + '', + urls.url(r'^$', views.IndexView.as_view(), name='index'), +) diff --git a/tuskar_ui/infrastructure/images/views.py b/tuskar_ui/infrastructure/images/views.py new file mode 100644 index 000000000..6f5ff421c --- /dev/null +++ b/tuskar_ui/infrastructure/images/views.py @@ -0,0 +1,26 @@ +# -*- coding: utf8 -*- +# +# 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 horizon import tables as horizon_tables + +from openstack_dashboard.api import glance +from tuskar_ui.infrastructure.images import tables + + +class IndexView(horizon_tables.DataTableView): + table_class = tables.ImagesTable + template_name = "infrastructure/images/index.html" + + def get_data(self): + return glance.image_list_detailed(self.request)[0]