From 446346dc62b3e0bd4093a6fac92d667288cc6e3c Mon Sep 17 00:00:00 2001 From: Jiri Tomasek Date: Mon, 16 Dec 2013 13:22:10 +0100 Subject: [PATCH] List views for Nodes in Resources management Management Nodes, Resource nodes, Free nodes BaremetalNode.list() is currently used to get data for the lists. This should be modified once filtering by node type is available Change-Id: I8499469b2487486e488990658f4ed5a75ee6983b --- run_tests.sh | 2 +- test-requirements.txt | 1 + tuskar_ui/infrastructure/dashboard.py | 3 +- .../resources/{archived => free}/__init__.py | 0 .../resources/{archived => free}/panel.py | 8 +-- .../{unallocated/panel.py => free/tables.py} | 15 +++-- .../free/templates/resources.free/index.html | 12 ++++ .../infrastructure/resources/free/tests.py | 56 ++++++++++++++++++ .../{archived/views.py => free/urls.py} | 13 +++-- .../infrastructure/resources/free/views.py | 41 +++++++++++++ .../resources/management/tables.py | 26 +++++++++ .../templates/resources.management/index.html | 12 ++++ .../resources/management/tests.py | 57 +++++++++++++++++++ .../resources/management/urls.py | 23 ++++++++ .../resources/management/views.py | 29 +++++++++- .../views.py => overview/urls.py} | 13 +++-- .../resources/resource/tables.py | 26 +++++++++ .../templates/resources.resource/index.html | 12 ++++ .../resources/resource/tests.py | 57 +++++++++++++++++++ .../infrastructure/resources/resource/urls.py | 23 ++++++++ .../resources/resource/views.py | 29 +++++++++- tuskar_ui/infrastructure/resources/tables.py | 38 +++++++++++++ .../resources/unallocated/__init__.py | 0 .../infrastructure/base_nodes_table.html | 23 ++++++++ 24 files changed, 490 insertions(+), 29 deletions(-) rename tuskar_ui/infrastructure/resources/{archived => free}/__init__.py (100%) rename tuskar_ui/infrastructure/resources/{archived => free}/panel.py (82%) rename tuskar_ui/infrastructure/resources/{unallocated/panel.py => free/tables.py} (74%) create mode 100644 tuskar_ui/infrastructure/resources/free/templates/resources.free/index.html create mode 100644 tuskar_ui/infrastructure/resources/free/tests.py rename tuskar_ui/infrastructure/resources/{archived/views.py => free/urls.py} (69%) create mode 100644 tuskar_ui/infrastructure/resources/free/views.py create mode 100644 tuskar_ui/infrastructure/resources/management/tables.py create mode 100644 tuskar_ui/infrastructure/resources/management/templates/resources.management/index.html create mode 100644 tuskar_ui/infrastructure/resources/management/tests.py create mode 100644 tuskar_ui/infrastructure/resources/management/urls.py rename tuskar_ui/infrastructure/resources/{unallocated/views.py => overview/urls.py} (69%) create mode 100644 tuskar_ui/infrastructure/resources/resource/tables.py create mode 100644 tuskar_ui/infrastructure/resources/resource/templates/resources.resource/index.html create mode 100644 tuskar_ui/infrastructure/resources/resource/tests.py create mode 100644 tuskar_ui/infrastructure/resources/resource/urls.py create mode 100644 tuskar_ui/infrastructure/resources/tables.py delete mode 100644 tuskar_ui/infrastructure/resources/unallocated/__init__.py create mode 100644 tuskar_ui/infrastructure/templates/infrastructure/base_nodes_table.html diff --git a/run_tests.sh b/run_tests.sh index ecd3d208b..cfd48453c 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -6,7 +6,7 @@ set -o errexit # Increment me any time the environment should be rebuilt. # This includes dependncy changes, directory renames, etc. # Simple integer secuence: 1, 2, 3... -environment_version=40 +environment_version=41 #--------------------------------------------------------# function usage { diff --git a/test-requirements.txt b/test-requirements.txt index ade15e148..81782eaa7 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -6,6 +6,7 @@ hacking>=0.5.3,<0.6 # Testing Requirements coverage>=3.6 django-nose +mock>=1.0.1 mox>=0.5.3 nose nose-exclude diff --git a/tuskar_ui/infrastructure/dashboard.py b/tuskar_ui/infrastructure/dashboard.py index 0daa11d1e..389c699de 100644 --- a/tuskar_ui/infrastructure/dashboard.py +++ b/tuskar_ui/infrastructure/dashboard.py @@ -44,8 +44,7 @@ class Resources(horizon.PanelGroup): 'resources.overview', 'resources.resource', 'resources.management', - 'resources.unallocated', - 'resources.archived', + 'resources.free', ) diff --git a/tuskar_ui/infrastructure/resources/archived/__init__.py b/tuskar_ui/infrastructure/resources/free/__init__.py similarity index 100% rename from tuskar_ui/infrastructure/resources/archived/__init__.py rename to tuskar_ui/infrastructure/resources/free/__init__.py diff --git a/tuskar_ui/infrastructure/resources/archived/panel.py b/tuskar_ui/infrastructure/resources/free/panel.py similarity index 82% rename from tuskar_ui/infrastructure/resources/archived/panel.py rename to tuskar_ui/infrastructure/resources/free/panel.py index efe397c42..2e82087d7 100644 --- a/tuskar_ui/infrastructure/resources/archived/panel.py +++ b/tuskar_ui/infrastructure/resources/free/panel.py @@ -19,9 +19,9 @@ import horizon from tuskar_ui.infrastructure import dashboard -class ResourcesArchived(horizon.Panel): - name = _("Archived") - slug = "resources.archived" +class ResourcesFree(horizon.Panel): + name = _("Free Nodes") + slug = "resources.free" -dashboard.Infrastructure.register(ResourcesArchived) +dashboard.Infrastructure.register(ResourcesFree) diff --git a/tuskar_ui/infrastructure/resources/unallocated/panel.py b/tuskar_ui/infrastructure/resources/free/tables.py similarity index 74% rename from tuskar_ui/infrastructure/resources/unallocated/panel.py rename to tuskar_ui/infrastructure/resources/free/tables.py index 8f0e20616..1906c5b2c 100644 --- a/tuskar_ui/infrastructure/resources/unallocated/panel.py +++ b/tuskar_ui/infrastructure/resources/free/tables.py @@ -14,14 +14,13 @@ from django.utils.translation import ugettext_lazy as _ # noqa -import horizon - -from tuskar_ui.infrastructure import dashboard +from tuskar_ui.infrastructure.resources import tables -class ResourcesUnallocated(horizon.Panel): - name = _("Unallocated") - slug = "resources.unallocated" +class FreeNodesTable(tables.NodesTable): - -dashboard.Infrastructure.register(ResourcesUnallocated) + class Meta: + name = "free_nodes" + verbose_name = _("Free Nodes") + table_actions = () + row_actions = () diff --git a/tuskar_ui/infrastructure/resources/free/templates/resources.free/index.html b/tuskar_ui/infrastructure/resources/free/templates/resources.free/index.html new file mode 100644 index 000000000..5caa24f51 --- /dev/null +++ b/tuskar_ui/infrastructure/resources/free/templates/resources.free/index.html @@ -0,0 +1,12 @@ +{% extends 'infrastructure/base_nodes_table.html' %} +{% load i18n %} + +{% block title %}{% trans "Free Nodes" %}{% endblock %} + +{% block page_header %} + {% include "horizon/common/_page_header.html" with title=_("Free Nodes") %} +{% endblock page_header %} + +{% block name %} + {% trans "Free Nodes" %} +{% endblock %} diff --git a/tuskar_ui/infrastructure/resources/free/tests.py b/tuskar_ui/infrastructure/resources/free/tests.py new file mode 100644 index 000000000..9e15cd86f --- /dev/null +++ b/tuskar_ui/infrastructure/resources/free/tests.py @@ -0,0 +1,56 @@ +# -*- 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 # noqa + +from tuskar_ui.test import helpers as test + + +INDEX_URL = urlresolvers.reverse('horizon:infrastructure:resources.free' + ':index') +RESOURCES_OVERVIEW_URL = urlresolvers.reverse('horizon:infrastructure:' + 'resources.overview:index') + + +class FreeNodesTests(test.BaseAdminViewTests): + def setUp(self): + super(FreeNodesTests, self).setUp() + + def test_index(self): + free_nodes = self.baremetal_nodes.list() + + with patch('tuskar_ui.api.BaremetalNode', **{ + 'spec_set': ['list'], # Only allow these attributes + 'list.return_value': free_nodes, + }) as mock: + res = self.client.get(INDEX_URL) + self.assertEqual(mock.list.call_count, 1) + + self.maxDiff = None + self.assertTemplateUsed(res, + 'infrastructure/resources.free/index.html') + self.assertItemsEqual(res.context['free_nodes_table'].data, + free_nodes) + + def test_index_nodes_list_exception(self): + with patch('tuskar_ui.api.BaremetalNode', **{ + 'spec_set': ['list'], + 'list.side_effect': self.exceptions.tuskar, + }) as mock: + res = self.client.get(INDEX_URL) + self.assertEqual(mock.list.call_count, 1) + + self.assertRedirectsNoFollow(res, RESOURCES_OVERVIEW_URL) diff --git a/tuskar_ui/infrastructure/resources/archived/views.py b/tuskar_ui/infrastructure/resources/free/urls.py similarity index 69% rename from tuskar_ui/infrastructure/resources/archived/views.py rename to tuskar_ui/infrastructure/resources/free/urls.py index f046b626b..6b389b162 100644 --- a/tuskar_ui/infrastructure/resources/archived/views.py +++ b/tuskar_ui/infrastructure/resources/free/urls.py @@ -1,4 +1,4 @@ -# -*- coding: utf8 -*- +# vim: tabstop=4 shiftwidth=4 softtabstop=4 # # 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 @@ -11,8 +11,13 @@ # 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.views import generic + +from django.conf.urls import defaults + +from tuskar_ui.infrastructure.resources.free import views -class IndexView(generic.TemplateView): - template_name = 'infrastructure/base.html' +urlpatterns = defaults.patterns( + '', + defaults.url(r'^$', views.IndexView.as_view(), name='index'), +) diff --git a/tuskar_ui/infrastructure/resources/free/views.py b/tuskar_ui/infrastructure/resources/free/views.py new file mode 100644 index 000000000..a32494601 --- /dev/null +++ b/tuskar_ui/infrastructure/resources/free/views.py @@ -0,0 +1,41 @@ +# -*- 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 django.utils.translation import ugettext_lazy as _ # noqa + +from horizon import exceptions +from horizon import tables as horizon_tables + +from tuskar_ui import api as tuskar +from tuskar_ui.infrastructure.resources.free import tables + + +class IndexView(horizon_tables.DataTableView): + table_class = tables.FreeNodesTable + template_name = 'infrastructure/resources.free/index.html' + + def get_data(self): + try: + # TODO(Jiri Tomasek): needs update when filtering by node type is + # available + free_nodes = tuskar.BaremetalNode.list(self.request) + except Exception: + free_nodes = [] + redirect = urlresolvers.reverse( + 'horizon:infrastructure:resources.overview:index') + exceptions.handle(self.request, + _('Unable to retrieve free nodes.'), + redirect=redirect) + return free_nodes diff --git a/tuskar_ui/infrastructure/resources/management/tables.py b/tuskar_ui/infrastructure/resources/management/tables.py new file mode 100644 index 000000000..ce4fb5594 --- /dev/null +++ b/tuskar_ui/infrastructure/resources/management/tables.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 django.utils.translation import ugettext_lazy as _ # noqa + +from tuskar_ui.infrastructure.resources import tables + + +class ManagementNodesTable(tables.NodesTable): + + class Meta: + name = "management_nodes" + verbose_name = _("Management Nodes") + table_actions = () + row_actions = () diff --git a/tuskar_ui/infrastructure/resources/management/templates/resources.management/index.html b/tuskar_ui/infrastructure/resources/management/templates/resources.management/index.html new file mode 100644 index 000000000..0503648e7 --- /dev/null +++ b/tuskar_ui/infrastructure/resources/management/templates/resources.management/index.html @@ -0,0 +1,12 @@ +{% extends 'infrastructure/base_nodes_table.html' %} +{% load i18n %} + +{% block title %}{% trans "Management Nodes" %}{% endblock %} + +{% block page_header %} + {% include "horizon/common/_page_header.html" with title=_("Management Nodes") %} +{% endblock page_header %} + +{% block name %} + {% trans "Management Nodes" %} +{% endblock %} diff --git a/tuskar_ui/infrastructure/resources/management/tests.py b/tuskar_ui/infrastructure/resources/management/tests.py new file mode 100644 index 000000000..55f2d0a75 --- /dev/null +++ b/tuskar_ui/infrastructure/resources/management/tests.py @@ -0,0 +1,57 @@ +# -*- 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 # noqa + +from tuskar_ui.test import helpers as test + + +INDEX_URL = urlresolvers.reverse('horizon:infrastructure:resources.management' + ':index') +RESOURCES_OVERVIEW_URL = urlresolvers.reverse('horizon:infrastructure:' + 'resources.overview:index') + + +class ManagementNodesTests(test.BaseAdminViewTests): + def setUp(self): + super(ManagementNodesTests, self).setUp() + + def test_index(self): + management_nodes = self.baremetal_nodes.list() + + with patch('tuskar_ui.api.BaremetalNode', **{ + 'spec_set': ['list'], # Only allow these attributes + 'list.return_value': management_nodes, + }) as mock: + res = self.client.get(INDEX_URL) + self.assertEqual(mock.list.call_count, 1) + + self.maxDiff = None + self.assertTemplateUsed( + res, 'infrastructure/resources.management/index.html') + + self.assertItemsEqual(res.context['management_nodes_table'].data, + management_nodes) + + def test_index_nodes_list_exception(self): + with patch('tuskar_ui.api.BaremetalNode', **{ + 'spec_set': ['list'], + 'list.side_effect': self.exceptions.tuskar, + }) as mock: + res = self.client.get(INDEX_URL) + self.assertEqual(mock.list.call_count, 1) + + self.assertRedirectsNoFollow(res, RESOURCES_OVERVIEW_URL) diff --git a/tuskar_ui/infrastructure/resources/management/urls.py b/tuskar_ui/infrastructure/resources/management/urls.py new file mode 100644 index 000000000..6eff1ade3 --- /dev/null +++ b/tuskar_ui/infrastructure/resources/management/urls.py @@ -0,0 +1,23 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# +# 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 defaults + +from tuskar_ui.infrastructure.resources.management import views + + +urlpatterns = defaults.patterns( + '', + defaults.url(r'^$', views.IndexView.as_view(), name='index'), +) diff --git a/tuskar_ui/infrastructure/resources/management/views.py b/tuskar_ui/infrastructure/resources/management/views.py index f046b626b..c1b076f82 100644 --- a/tuskar_ui/infrastructure/resources/management/views.py +++ b/tuskar_ui/infrastructure/resources/management/views.py @@ -11,8 +11,31 @@ # 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.views import generic + +from django.core import urlresolvers +from django.utils.translation import ugettext_lazy as _ # noqa + +from horizon import exceptions +from horizon import tables as horizon_tables + +from tuskar_ui import api as tuskar +from tuskar_ui.infrastructure.resources.management import tables -class IndexView(generic.TemplateView): - template_name = 'infrastructure/base.html' +class IndexView(horizon_tables.DataTableView): + table_class = tables.ManagementNodesTable + template_name = 'infrastructure/resources.management/index.html' + + def get_data(self): + try: + # TODO(Jiri Tomasek): needs update when filtering by node type is + # available + management_nodes = tuskar.BaremetalNode.list(self.request) + except Exception: + management_nodes = [] + redirect = urlresolvers.reverse( + 'horizon:infrastructure:resources.overview:index') + exceptions.handle(self.request, + _('Unable to retrieve management nodes.'), + redirect=redirect) + return management_nodes diff --git a/tuskar_ui/infrastructure/resources/unallocated/views.py b/tuskar_ui/infrastructure/resources/overview/urls.py similarity index 69% rename from tuskar_ui/infrastructure/resources/unallocated/views.py rename to tuskar_ui/infrastructure/resources/overview/urls.py index f046b626b..e938c2c32 100644 --- a/tuskar_ui/infrastructure/resources/unallocated/views.py +++ b/tuskar_ui/infrastructure/resources/overview/urls.py @@ -1,4 +1,4 @@ -# -*- coding: utf8 -*- +# vim: tabstop=4 shiftwidth=4 softtabstop=4 # # 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 @@ -11,8 +11,13 @@ # 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.views import generic + +from django.conf.urls import defaults + +from tuskar_ui.infrastructure.resources.overview import views -class IndexView(generic.TemplateView): - template_name = 'infrastructure/base.html' +urlpatterns = defaults.patterns( + '', + defaults.url(r'^$', views.IndexView.as_view(), name='index'), +) diff --git a/tuskar_ui/infrastructure/resources/resource/tables.py b/tuskar_ui/infrastructure/resources/resource/tables.py new file mode 100644 index 000000000..fc18a050c --- /dev/null +++ b/tuskar_ui/infrastructure/resources/resource/tables.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 django.utils.translation import ugettext_lazy as _ # noqa + +from tuskar_ui.infrastructure.resources import tables + + +class ResourceNodesTable(tables.NodesTable): + + class Meta: + name = "resource_nodes" + verbose_name = _("Resource Nodes") + table_actions = () + row_actions = () diff --git a/tuskar_ui/infrastructure/resources/resource/templates/resources.resource/index.html b/tuskar_ui/infrastructure/resources/resource/templates/resources.resource/index.html new file mode 100644 index 000000000..b789ea368 --- /dev/null +++ b/tuskar_ui/infrastructure/resources/resource/templates/resources.resource/index.html @@ -0,0 +1,12 @@ +{% extends 'infrastructure/base_nodes_table.html' %} +{% load i18n %} + +{% block title %}{% trans "Resource Nodes" %}{% endblock %} + +{% block page_header %} + {% include "horizon/common/_page_header.html" with title=_("Resource Nodes") %} +{% endblock page_header %} + +{% block name %} + {% trans "Resource Nodes" %} +{% endblock %} diff --git a/tuskar_ui/infrastructure/resources/resource/tests.py b/tuskar_ui/infrastructure/resources/resource/tests.py new file mode 100644 index 000000000..16d042ad8 --- /dev/null +++ b/tuskar_ui/infrastructure/resources/resource/tests.py @@ -0,0 +1,57 @@ +# -*- 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 # noqa + +from tuskar_ui.test import helpers as test + + +INDEX_URL = urlresolvers.reverse('horizon:infrastructure:resources.resource' + ':index') +RESOURCES_OVERVIEW_URL = urlresolvers.reverse('horizon:infrastructure:' + 'resources.overview:index') + + +class ResourceNodesTests(test.BaseAdminViewTests): + def setUp(self): + super(ResourceNodesTests, self).setUp() + + def test_index(self): + resource_nodes = self.baremetal_nodes.list() + + with patch('tuskar_ui.api.BaremetalNode', **{ + 'spec_set': ['list'], # Only allow these attributes + 'list.return_value': resource_nodes, + }) as mock: + res = self.client.get(INDEX_URL) + self.assertEqual(mock.list.call_count, 1) + + self.maxDiff = None + self.assertTemplateUsed( + res, 'infrastructure/resources.resource/index.html') + + self.assertItemsEqual(res.context['resource_nodes_table'].data, + resource_nodes) + + def test_index_nodes_list_exception(self): + with patch('tuskar_ui.api.BaremetalNode', **{ + 'spec_set': ['list'], + 'list.side_effect': self.exceptions.tuskar, + }) as mock: + res = self.client.get(INDEX_URL) + self.assertEqual(mock.list.call_count, 1) + + self.assertRedirectsNoFollow(res, RESOURCES_OVERVIEW_URL) diff --git a/tuskar_ui/infrastructure/resources/resource/urls.py b/tuskar_ui/infrastructure/resources/resource/urls.py new file mode 100644 index 000000000..7f426a3d6 --- /dev/null +++ b/tuskar_ui/infrastructure/resources/resource/urls.py @@ -0,0 +1,23 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 +# +# 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 defaults + +from tuskar_ui.infrastructure.resources.resource import views + + +urlpatterns = defaults.patterns( + '', + defaults.url(r'^$', views.IndexView.as_view(), name='index'), +) diff --git a/tuskar_ui/infrastructure/resources/resource/views.py b/tuskar_ui/infrastructure/resources/resource/views.py index f046b626b..a23789c04 100644 --- a/tuskar_ui/infrastructure/resources/resource/views.py +++ b/tuskar_ui/infrastructure/resources/resource/views.py @@ -11,8 +11,31 @@ # 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.views import generic + +from django.core import urlresolvers +from django.utils.translation import ugettext_lazy as _ # noqa + +from horizon import exceptions +from horizon import tables as horizon_tables + +from tuskar_ui import api as tuskar +from tuskar_ui.infrastructure.resources.resource import tables -class IndexView(generic.TemplateView): - template_name = 'infrastructure/base.html' +class IndexView(horizon_tables.DataTableView): + table_class = tables.ResourceNodesTable + template_name = 'infrastructure/resources.resource/index.html' + + def get_data(self): + try: + # TODO(Jiri Tomasek): needs update when filtering by node type is + # available + resource_nodes = tuskar.BaremetalNode.list(self.request) + except Exception: + resource_nodes = [] + redirect = urlresolvers.reverse( + 'horizon:infrastructure:resources.overview:index') + exceptions.handle(self.request, + _('Unable to retrieve resource nodes.'), + redirect=redirect) + return resource_nodes diff --git a/tuskar_ui/infrastructure/resources/tables.py b/tuskar_ui/infrastructure/resources/tables.py new file mode 100644 index 000000000..e94eb279e --- /dev/null +++ b/tuskar_ui/infrastructure/resources/tables.py @@ -0,0 +1,38 @@ +# -*- 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 _ # noqa + +from horizon import tables + + +class NodesTable(tables.DataTable): + service_host = tables.Column( + "service_host", + verbose_name=_("Service Host"), + link=("horizon:infrastructure:resources.management:detail")) + mac_address = tables.Column("mac_address", verbose_name=_("MAC Address")) + pm_address = tables.Column("pm_address", + verbose_name=_("Management Address")) + status = tables.Column("status", verbose_name=_("Status")) + usage = tables.Column("usage", verbose_name=_("Usage")) + + class Meta: + name = "nodes_table" + verbose_name = _("Nodes") + table_actions = () + row_actions = () + + def get_object_display(self, datum): + return datum.service_host diff --git a/tuskar_ui/infrastructure/resources/unallocated/__init__.py b/tuskar_ui/infrastructure/resources/unallocated/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tuskar_ui/infrastructure/templates/infrastructure/base_nodes_table.html b/tuskar_ui/infrastructure/templates/infrastructure/base_nodes_table.html new file mode 100644 index 000000000..189bca0a2 --- /dev/null +++ b/tuskar_ui/infrastructure/templates/infrastructure/base_nodes_table.html @@ -0,0 +1,23 @@ +{% extends 'infrastructure/base.html' %} +{% load i18n %} + +{% block main %} +
+
+ + +

{% block name %}{% endblock %}

+
+
+ +
+
+ {{ table.render }} +
+
+{% endblock %}