Add clusters table

screenshots: http://pasteboard.co/ccXigbt.png

Partially implements blueprint add-cluster-panel

Change-Id: I714fa7a783b7c62a68a5ae71a79777547d464944
This commit is contained in:
Zhenguo Niu 2015-08-28 00:32:03 +08:00
parent 3f6f17b695
commit 7718fd4f19
7 changed files with 130 additions and 12 deletions

View File

@ -2,7 +2,7 @@ from senlin_dashboard import exceptions
DASHBOARD = 'cluster'
ADD_INSTALLED_APPS = [
'senlin_dashboard.senlin'
'senlin_dashboard.cluster'
]
DEFAULT = True

View File

@ -10,19 +10,27 @@
# License for the specific language governing permissions and limitations
# under the License.
from django.conf import settings
from horizon.utils import memoized
from openstack_dashboard.api import base
from senlinclient import client as senlin_client
from senlinclient.common import sdk
from senlinclient.v1 import models
USER_AGENT = 'python-senlinclient'
class Cluster(base.APIResourceWrapper):
_attrs = ['id', 'name', 'status', 'created_time', 'updated_time',
'profile_name', 'status_reason']
@memoized.memoized
def senlinclient(request, password=None):
def senlinclient(request):
api_version = "1"
kwargs = {
'auth_url': base.url_for(request, 'clustering'),
'auth_url': getattr(settings, 'OPENSTACK_KEYSTONE_URL'),
'token': request.user.token.id,
'project_id': request.user.tenant_id
}
@ -30,3 +38,10 @@ def senlinclient(request, password=None):
USER_AGENT, **kwargs)
return senlin_client.Client(api_version, conn.session)
def cluster_list(request):
"""Returns all clusters."""
clusters = senlinclient(request).list(models.Cluster)
return [Cluster(c) for c in clusters]

View File

@ -1,16 +1,17 @@
# 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
# 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
# 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.
# 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 senlin_dashboard.cluster import dashboard
@ -18,7 +19,7 @@ from senlin_dashboard.cluster import dashboard
class Clusters(horizon.Panel):
name = _("Clusters")
slug = "clusters"
slug = 'clusters'
dashboard.Cluster.register(Clusters)

View File

@ -0,0 +1,45 @@
# 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
from horizon.utils import filters
class ClustersTable(tables.DataTable):
name = tables.Column("name", verbose_name=_("Name"))
status = tables.Column("status", verbose_name=_("Status"))
status_reason = tables.Column("status_reason",
verbose_name=_("Status Reason"))
profile_name = tables.Column("profile_name",
verbose_name=_("Profile Name"))
created = tables.Column(
"created_time",
verbose_name=_("Created"),
filters=(
filters.parse_isotime,
filters.timesince_or_never
)
)
updated = tables.Column(
"updated_time",
verbose_name=_("Updated"),
filters=(
filters.parse_isotime,
filters.timesince_or_never
)
)
class Meta(object):
name = "clusters"
verbose_name = _("Clusters")

View File

@ -0,0 +1,11 @@
{% extends 'base.html' %}
{% load i18n %}
{% block title %}{% trans "Clusters" %}{% endblock %}
{% block page_header %}
{% include "horizon/common/_page_header.html" with title=_("Clusters") %}
{% endblock page_header %}
{% block main %}
{{ table.render }}
{% endblock %}

View File

@ -0,0 +1,22 @@
# 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 patterns # noqa
from django.conf.urls import url # noqa
from senlin_dashboard.cluster.clusters import views
urlpatterns = patterns(
'',
url(r'^$', views.IndexView.as_view(), name='index'),
)

View File

@ -0,0 +1,24 @@
# 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
from senlin_dashboard.api import senlin
from senlin_dashboard.cluster.clusters.tables import ClustersTable
class IndexView(tables.DataTableView):
table_class = ClustersTable
template_name = 'cluster/clusters/index.html'
def get_data(self):
return senlin.cluster_list(self.request)