Merge "Change 'Datasources' page layout"

This commit is contained in:
Jenkins 2017-05-24 20:52:11 +00:00 committed by Gerrit Code Review
commit 9ce12571a6
6 changed files with 91 additions and 58 deletions

View File

@ -14,7 +14,7 @@
from congressclient.v1 import client as congress_client from congressclient.v1 import client as congress_client
from django.conf import settings from django.conf import settings
import keystoneauth1.identity.v2 as v2 # import keystoneauth1.identity.v2 as v2
import keystoneauth1.identity.v3 as v3 import keystoneauth1.identity.v3 as v3
import keystoneauth1.session as kssession import keystoneauth1.session as kssession
from openstack_dashboard.api import base from openstack_dashboard.api import base
@ -88,12 +88,7 @@ def congressclient(request):
def get_keystone_session(auth_url, user): def get_keystone_session(auth_url, user):
if auth_url[-3:] == '/v3': auth = v3.Token(auth_url, user.token.id, project_id=user.tenant_id)
auth = v3.Token(auth_url, user.token.id, project_id=user.tenant_id)
else:
auth = v2.Token(auth_url, user.token.id, tenant_id=user.tenant_id,
tenant_name=user.tenant_name)
session = kssession.Session(auth=auth) session = kssession.Session(auth=auth)
return session return session
@ -302,3 +297,14 @@ def datasource_statuses_list(request):
wrapper.set_value(key, value) wrapper.set_value(key, value)
ds_status.append(wrapper) ds_status.append(wrapper)
return ds_status return ds_status
def datasource_status_list(request, datasource_name):
client = congressclient(request)
try:
status = client.list_datasource_status(datasource_name)
return status
except Exception:
LOG.exception("Failed to retrieve status for datasource %s",
datasource_name)
raise

View File

@ -26,10 +26,6 @@ def get_resource_url(obj):
class DataSourcesTablesTable(tables.DataTable): class DataSourcesTablesTable(tables.DataTable):
name = tables.Column("name", verbose_name=_("Table Name"), name = tables.Column("name", verbose_name=_("Table Name"),
link=get_resource_url) link=get_resource_url)
datasource_name = tables.Column("datasource_name",
verbose_name=_("Service"))
datasource_driver = tables.Column("datasource_driver",
verbose_name=_("Driver"))
class Meta(object): class Meta(object):
name = "datasources_tables" name = "datasources_tables"
@ -37,16 +33,6 @@ class DataSourcesTablesTable(tables.DataTable):
hidden_title = False hidden_title = False
def get_policy_link(datum):
return reverse('horizon:admin:policies:detail',
args=(datum['policy_name'],))
def get_policy_table_link(datum):
return reverse('horizon:admin:datasources:policy_table_detail',
args=(datum['policy_name'], datum['name']))
class DataSourceRowsTable(tables.DataTable): class DataSourceRowsTable(tables.DataTable):
class Meta(object): class Meta(object):
name = "datasource_rows" name = "datasource_rows"
@ -54,6 +40,22 @@ class DataSourceRowsTable(tables.DataTable):
hidden_title = False hidden_title = False
# TODO(ramineni): support create/delete datasource
class DataSourcesTable(tables.DataTable):
name = tables.Column("name", verbose_name=_("Data Source Name"),
link='horizon:admin:datasources:datasource_detail')
enabled = tables.Column("enabled", verbose_name=_("Enabled"))
driver = tables.Column("driver", verbose_name=_("Driver"))
# config = tables.Column("config", verbose_name=_("Config"))
class Meta(object):
name = "datasources_list"
verbose_name = _("Data Sources")
hidden_title = False
# table_actions = (CreateDatasource,)
# row_actions = (Disable,)
class DataSourceStatusesTable(tables.DataTable): class DataSourceStatusesTable(tables.DataTable):
datasource_name = tables.Column("service", datasource_name = tables.Column("service",
verbose_name=_("Service")) verbose_name=_("Service"))

View File

@ -1,9 +1,9 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% load i18n %} {% load i18n %}
{% block title %}{% trans "Datasource Overview" %}{% endblock %} {% block title %}{% trans "Data Source Overview" %}{% endblock %}
{% block page_header %} {% block page_header %}
{% include "horizon/common/_page_header.html" with title=_("Datasource Details: ")|add:datasource_name %} {% include "horizon/common/_page_header.html" with title=_("Data Source Details: ")|add:datasource_name %}
{% endblock page_header %} {% endblock page_header %}
{% block main %} {% block main %}
@ -11,5 +11,4 @@
<div id="datasources_tables"> <div id="datasources_tables">
{{ datasources_tables_table.render }} {{ datasources_tables_table.render }}
</div> </div>
{% endblock %} {% endblock %}

View File

@ -7,13 +7,10 @@
{% endblock page_header %} {% endblock page_header %}
{% block main %} {% block main %}
<div id="policies_tables"> <div id="datasources_list_tables">
{{ policies_tables_table.render }} {{ datasources_list_table.render }}
</div> </div>
<div id="service_status_tables"> <div id="service_status_tables">
{{ service_status_table.render }} {{ service_status_table.render }}
</div> </div>
<div id="service_tables">
{{ datasources_tables_table.render }}
</div>
{% endblock %} {% endblock %}

View File

@ -21,10 +21,14 @@ from congress_dashboard.datasources import views
SERVICES = ( SERVICES = (
r'^services/(?P<datasource_id>[^/]+)/(?P<service_table_name>[^/]+)/%s$') r'^services/(?P<datasource_id>[^/]+)/(?P<service_table_name>[^/]+)/%s$')
DATASOURCE = r'^(?P<datasource_id>[^/]+)/%s$'
urlpatterns = patterns( urlpatterns = patterns(
'', '',
url(r'^$', views.IndexView.as_view(), name='index'), url(r'^$', views.IndexView.as_view(), name='index'),
url(SERVICES % 'detail', views.DetailView.as_view(), url(SERVICES % 'detail', views.DetailView.as_view(),
name='datasource_table_detail'), name='datasource_table_detail'),
url(DATASOURCE % 'detail', views.DatasourceView.as_view(),
name='datasource_detail'),
) )

View File

@ -31,35 +31,41 @@ logger = logging.getLogger(__name__)
class IndexView(tables.MultiTableView): class IndexView(tables.MultiTableView):
"""List service and policy defined data.""" """List service and policy defined data."""
table_classes = (datasources_tables.DataSourcesTablesTable, table_classes = (datasources_tables.DataSourcesTable,
datasources_tables.DataSourceStatusesTable,) datasources_tables.DataSourceStatusesTable, )
template_name = 'admin/datasources/index.html' template_name = 'admin/datasources/index.html'
def get_datasources_tables_data(self): def get_datasources_list_data(self):
try: try:
datasources = congress.datasources_list(self.request) datasources = congress.datasources_list(self.request)
return datasources
except Exception as e: except Exception as e:
msg = _('Unable to get services list: %s') % str(e) msg = _('Unable to get data sources list: %s') % str(e)
messages.error(self.request, msg) messages.error(self.request, msg)
return [] return []
ds_temp = [] def get_service_status_data(self):
for ds in datasources: ds = []
ds_id = ds['id'] try:
try: ds = congress.datasource_statuses_list(self.request)
ds_tables = congress.datasource_tables_list(self.request, logger.debug("ds status : %s " % ds)
ds_id) except Exception as e:
except Exception as e: msg = _('Unable to get data source status list: %s') % str(e)
msg_args = {'ds_id': ds_id, 'error': str(e)} messages.error(self.request, msg)
msg = _('Unable to get tables list for service "%(ds_id)s": ' return ds
'%(error)s') % msg_args
messages.error(self.request, msg)
return []
class DatasourceView(tables.DataTableView):
template_name = 'admin/datasources/datasource_detail.html'
table_class = datasources_tables.DataSourcesTablesTable
def get_data(self):
ds_id = self.kwargs['datasource_id']
ds_temp = []
try:
ds_tables = congress.datasource_tables_list(self.request, ds_id)
for table in ds_tables: for table in ds_tables:
table.set_value('datasource_id', ds_id) table.set_value('datasource_id', ds_id)
table.set_value('datasource_name', ds['name'])
table.set_value('datasource_driver', ds['driver'])
table.set_id_as_name_if_empty() table.set_id_as_name_if_empty()
# Object ids within a Horizon table must be unique. Otherwise, # Object ids within a Horizon table must be unique. Otherwise,
# Horizon will cache the column values for the object by id and # Horizon will cache the column values for the object by id and
@ -68,18 +74,37 @@ class IndexView(tables.MultiTableView):
table.set_value('id', '%s-%s' % (ds_id, table['table_id'])) table.set_value('id', '%s-%s' % (ds_id, table['table_id']))
ds_temp.append(table) ds_temp.append(table)
logger.debug("ds_temp %s" % ds_temp) logger.debug("ds_temp %s" % ds_temp)
return ds_temp return ds_temp
def get_service_status_data(self):
ds = []
try:
ds = congress.datasource_statuses_list(self.request)
logger.debug("ds status : %s " % ds)
except Exception as e: except Exception as e:
msg = _('Unable to get datasource status list: %s') % str(e) msg_args = {'ds_id': ds_id, 'error': str(e)}
msg = _('Unable to get tables list for service "%(ds_id)s": '
'%(error)s') % msg_args
messages.error(self.request, msg) messages.error(self.request, msg)
return ds return []
def get_context_data(self, **kwargs):
context = super(DatasourceView, self).get_context_data(**kwargs)
datasource_id = self.kwargs['datasource_id']
try:
datasource = congress.datasource_get(self.request, datasource_id)
status = congress.datasource_status_list(self.request,
datasource['name'])
context['last_updated'] = status['last_updated']
context['subscribers'] = status['subscribers']
context['subscriptions'] = status['subscriptions']
context['last_error'] = status['last_error']
context['number_of_updates'] = status['number_of_updates']
context['datasource_name'] = datasource['name']
context['status'] = ('Active' if status['initialized']
else 'Not Active')
return context
except Exception as e:
msg_args = {'ds_id': datasource_id, 'error': str(e)}
msg = _('Unable to get status for data source "%(ds_id)s": '
'%(error)s') % msg_args
messages.error(self.request, msg)
return []
class DetailView(tables.DataTableView): class DetailView(tables.DataTableView):