Files
tuskar-ui/tuskar_ui/infrastructure/nodes/views.py
Jiri Tomasek 2b664755a2 Updated Nodes Overview page
Displays node counts, mocked Health Status table,
defined template structure to resemble wireframes

Change-Id: Ia042bf414d48eaf0254df92db2b1557b9ab63ea3
2014-02-05 14:19:28 -05:00

95 lines
3.3 KiB
Python

# -*- 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.urlresolvers import reverse_lazy
from django.utils.translation import ugettext_lazy as _
from horizon import exceptions
from horizon import forms as horizon_forms
from horizon import tabs as horizon_tabs
from horizon import views as horizon_views
from tuskar_ui import api
from tuskar_ui.infrastructure.nodes import forms
from tuskar_ui.infrastructure.nodes import tabs
class IndexView(horizon_tabs.TabbedTableView):
tab_group_class = tabs.NodeTabs
template_name = 'infrastructure/nodes/index.html'
def get_free_nodes_count(self):
try:
free_nodes_count = len(api.Node.list(self.request,
associated=False))
except Exception:
free_nodes_count = 0
exceptions.handle(self.request,
_('Unable to retrieve free nodes.'))
return free_nodes_count
def get_deployed_nodes_count(self):
try:
deployed_nodes_count = len(api.Node.list(self.request,
associated=True))
except Exception:
deployed_nodes_count = 0
exceptions.handle(self.request,
_('Unable to retrieve deployed nodes.'))
return deployed_nodes_count
def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs)
context['free_nodes_count'] = self.get_free_nodes_count()
context['deployed_nodes_count'] = self.get_deployed_nodes_count()
context['nodes_count'] = (context['free_nodes_count'] +
context['deployed_nodes_count'])
return context
class RegisterView(horizon_forms.ModalFormView):
form_class = forms.NodeFormset
form_prefix = 'register_nodes'
template_name = 'infrastructure/nodes/register.html'
success_url = reverse_lazy(
'horizon:infrastructure:nodes:index')
def get_data(self):
return []
def get_form(self, form_class):
return form_class(self.request.POST or None,
initial=self.get_data(),
prefix=self.form_prefix)
class DetailView(horizon_views.APIView):
template_name = 'infrastructure/nodes/details.html'
def get_data(self, request, context, *args, **kwargs):
node_uuid = kwargs.get('node_uuid')
try:
node = api.Node.get(request, node_uuid)
except Exception:
node = None
redirect = reverse_lazy('horizon:infrastructure:nodes:index')
msg = _('Unable to retrieve node with UUID "%s"') % node_uuid
exceptions.handle(request, msg, redirect=redirect)
context['node'] = node
return context