Add Servers table

Change-Id: Ib8cbe11a86efd5c38678aa2cb56a106f601ce5a8
This commit is contained in:
Zhenguo Niu 2017-05-05 11:20:34 +08:00
parent d60f86eff8
commit a8af4b2972
6 changed files with 82 additions and 6 deletions

View File

@ -12,7 +12,7 @@
from django.views import generic
from mogan_ui.api import client
from mogan_ui.api import mogan
from openstack_dashboard.api.rest import urls
from openstack_dashboard.api.rest import utils as rest_utils
@ -30,5 +30,5 @@ class Servers(generic.View):
:param request: HTTP request.
:return: servers.
"""
servers = client.server_list(request)
servers = mogan.server_list(request)
return {'servers': [s.to_dict() for s in servers]}

View File

@ -0,0 +1,34 @@
# Copyright 2017 Huawei Technologies Co.,LTD.
# All Rights Reserved.
#
# 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 ServersTable(tables.DataTable):
name = tables.WrappingColumn(
"name",
verbose_name=_("Name"))
status = tables.Column("status",
verbose_name=_("Status"))
def get_object_id(self, obj):
return obj.uuid
class Meta(object):
name = "servers"
verbose_name = _("Servers")

View File

@ -0,0 +1,7 @@
{% extends 'base.html' %}
{% load i18n %}
{% block title %}{% trans "Servers" %}{% endblock %}
{% block main %}
{{ table.render }}
{% endblock %}

View File

@ -14,10 +14,8 @@
# limitations under the License.
from django.conf.urls import url
from django.utils.translation import ugettext_lazy as _
from horizon.browsers import views
from mogan_ui.content.servers import views
title = _("Servers")
urlpatterns = [
url('', views.AngularIndexView.as_view(title=title), name='index'),
url(r'^$', views.IndexView.as_view(), name='index'),
]

View File

@ -0,0 +1,37 @@
# Copyright 2017 Huawei Technologies Co.,LTD.
# All Rights Reserved.
# 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 mogan_ui.api import mogan
from mogan_ui.content.servers.tables import ServersTable
from horizon import exceptions
from horizon import tables
class IndexView(tables.DataTableView):
table_class = ServersTable
template_name = 'project/servers/index.html'
page_title = _("Servers")
def get_data(self):
try:
servers = mogan.server_list(self.request)
except Exception:
servers = []
msg = _('Unable to retrieve servers.')
exceptions.handle(self.request, msg)
return servers