diff --git a/_50_senlin.py.example b/_50_senlin.py.example index a8aaf111..2953a171 100644 --- a/_50_senlin.py.example +++ b/_50_senlin.py.example @@ -2,7 +2,7 @@ from senlin_dashboard import exceptions DASHBOARD = 'cluster' ADD_INSTALLED_APPS = [ - 'senlin_dashboard.senlin' + 'senlin_dashboard.cluster' ] DEFAULT = True diff --git a/senlin_dashboard/api/senlin.py b/senlin_dashboard/api/senlin.py index b938f025..71b0d7af 100644 --- a/senlin_dashboard/api/senlin.py +++ b/senlin_dashboard/api/senlin.py @@ -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] diff --git a/senlin_dashboard/cluster/clusters/panel.py b/senlin_dashboard/cluster/clusters/panel.py index a62b6d12..8936e6f1 100644 --- a/senlin_dashboard/cluster/clusters/panel.py +++ b/senlin_dashboard/cluster/clusters/panel.py @@ -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) diff --git a/senlin_dashboard/cluster/clusters/tables.py b/senlin_dashboard/cluster/clusters/tables.py new file mode 100644 index 00000000..79199990 --- /dev/null +++ b/senlin_dashboard/cluster/clusters/tables.py @@ -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") diff --git a/senlin_dashboard/cluster/clusters/templates/clusters/index.html b/senlin_dashboard/cluster/clusters/templates/clusters/index.html new file mode 100644 index 00000000..c0212f01 --- /dev/null +++ b/senlin_dashboard/cluster/clusters/templates/clusters/index.html @@ -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 %} diff --git a/senlin_dashboard/cluster/clusters/urls.py b/senlin_dashboard/cluster/clusters/urls.py new file mode 100644 index 00000000..0963e05f --- /dev/null +++ b/senlin_dashboard/cluster/clusters/urls.py @@ -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'), +) diff --git a/senlin_dashboard/cluster/clusters/views.py b/senlin_dashboard/cluster/clusters/views.py new file mode 100644 index 00000000..ad340fd6 --- /dev/null +++ b/senlin_dashboard/cluster/clusters/views.py @@ -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)