Render progress details for notification
Added a new tab "Progress Details" on notification details page to display status of the notification. Depends-On: I9ba787bc8ef9528a7cff5b4c1411dffa454b66d2 Change-Id: I9807bfe3c61f455bf4d34d9da49b0f4945ca9d5a
This commit is contained in:
parent
d3b34063a1
commit
58989c3f41
|
@ -22,21 +22,26 @@ from horizon.utils import functions as utils
|
|||
from horizon.utils import memoized
|
||||
from keystoneauth1.identity.generic import token
|
||||
from keystoneauth1 import session as ks_session
|
||||
from masakariclient import api_versions
|
||||
from masakariclient import plugin
|
||||
from openstack import connection
|
||||
from openstack_dashboard.api import nova as nova_api
|
||||
|
||||
from masakaridashboard.handle_errors import handle_errors
|
||||
|
||||
MICROVERSION_FEATURES = {"recovery_workflow_details": ["1.1"]}
|
||||
|
||||
|
||||
@memoized.memoized
|
||||
def openstack_connection(request):
|
||||
def openstack_connection(request, version=None):
|
||||
auth = token.Token(
|
||||
auth_url=getattr(settings, 'OPENSTACK_KEYSTONE_URL'),
|
||||
token=request.user.token.id,
|
||||
project_name=request.user.project_name,
|
||||
project_id=request.user.tenant_id)
|
||||
session = ks_session.Session(auth=auth)
|
||||
conn = connection.Connection(session=session)
|
||||
conn = connection.Connection(session=session,
|
||||
ha_api_version=version)
|
||||
|
||||
return conn.instance_ha
|
||||
|
||||
|
@ -181,3 +186,48 @@ def notification_list(request, filters=None, marker='', paginate=False):
|
|||
def get_notification(request, notification_id):
|
||||
"""return single notifications"""
|
||||
return openstack_connection(request).get_notification(notification_id)
|
||||
|
||||
|
||||
def get_requested_versions(features):
|
||||
if not features:
|
||||
return None
|
||||
# Convert a single feature string into a list for backward compatibility.
|
||||
if isinstance(features, str):
|
||||
features = [features]
|
||||
service_features = MICROVERSION_FEATURES
|
||||
feature_versions = set(service_features[features[0]])
|
||||
for feature in features[1:]:
|
||||
feature_versions &= set(service_features[feature])
|
||||
if not feature_versions:
|
||||
return None
|
||||
# Sort version candidates from larger versins
|
||||
feature_versions = sorted(feature_versions, reverse=True,
|
||||
key=lambda v: [int(i) for i in v.split('.')])
|
||||
return feature_versions
|
||||
|
||||
|
||||
def get_microversion_for_features(features, wrapper_class, min_ver, max_ver):
|
||||
"""Retrieves that highest known functional microversion for features"""
|
||||
feature_versions = get_requested_versions(features)
|
||||
if not feature_versions:
|
||||
return None
|
||||
for version in feature_versions:
|
||||
microversion = wrapper_class(version)
|
||||
if microversion.matches(min_ver, max_ver):
|
||||
return microversion
|
||||
return None
|
||||
|
||||
|
||||
@memoized.memoized
|
||||
def get_microversion(features):
|
||||
min_ver = api_versions.APIVersion(plugin.SUPPORTED_VERSIONS[1])
|
||||
max_ver = api_versions.APIVersion(plugin.SUPPORTED_VERSIONS[-1])
|
||||
return (get_microversion_for_features(
|
||||
features, api_versions.APIVersion, min_ver, max_ver))
|
||||
|
||||
|
||||
def get_notification_with_progress_details(request, notification_id):
|
||||
microversion = get_microversion("recovery_workflow_details")
|
||||
return openstack_connection(
|
||||
request, version=microversion.get_string()).get_notification(
|
||||
notification_id)
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from horizon import tables
|
||||
from horizon.utils import filters
|
||||
|
||||
|
||||
NOTIFICATION_FILTER_CHOICES = (
|
||||
|
@ -30,6 +31,15 @@ class NotificationFilterAction(tables.FilterAction):
|
|||
filter_choices = NOTIFICATION_FILTER_CHOICES
|
||||
|
||||
|
||||
class ProgressDetailsItem(object):
|
||||
def __init__(self, id, action, timestamp, message):
|
||||
|
||||
self.id = id
|
||||
self.action = action
|
||||
self.timestamp = timestamp
|
||||
self.message = message
|
||||
|
||||
|
||||
class NotificationsTable(tables.DataTable):
|
||||
|
||||
source_host_uuid = tables.Column(
|
||||
|
@ -49,3 +59,16 @@ class NotificationsTable(tables.DataTable):
|
|||
name = "notifications"
|
||||
verbose_name = _("Notifications")
|
||||
table_actions = (NotificationFilterAction,)
|
||||
|
||||
|
||||
class NotificationProgressDetailsTable(tables.DataTable):
|
||||
|
||||
action = tables.Column('action', verbose_name=_('Action'))
|
||||
timestamp = tables.Column('timestamp', verbose_name=_('Timestamp'),
|
||||
filters=[filters.parse_isotime])
|
||||
message = tables.Column('message', verbose_name=_('Message'))
|
||||
id = tables.Column('id', verbose_name=_('ID'), hidden=True)
|
||||
|
||||
class Meta(object):
|
||||
name = "notification_progress_details"
|
||||
verbose_name = _("NotificationProgressDetails")
|
||||
|
|
|
@ -14,7 +14,13 @@
|
|||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from horizon import exceptions
|
||||
from horizon import tabs
|
||||
from masakariclient import api_versions
|
||||
from masakariclient import plugin
|
||||
|
||||
from masakaridashboard.api import api
|
||||
from masakaridashboard.notifications import tables as notification_tab
|
||||
|
||||
|
||||
class OverviewTab(tabs.Tab):
|
||||
|
@ -26,6 +32,48 @@ class OverviewTab(tabs.Tab):
|
|||
return {"notification": self.tab_group.kwargs['notification']}
|
||||
|
||||
|
||||
class NotificationProgressDetailsTab(tabs.TableTab):
|
||||
table_classes = (notification_tab.NotificationProgressDetailsTable,)
|
||||
name = _("Progress Details")
|
||||
slug = "notification_progress_details"
|
||||
template_name = "masakaridashboard/notifications/_progress_detail.html"
|
||||
preload = False
|
||||
|
||||
def get_notification_progress_details_data(self):
|
||||
try:
|
||||
id = 0
|
||||
notification = self.tab_group.kwargs['notification']
|
||||
notification_obj = \
|
||||
api.get_notification_with_progress_details(
|
||||
self.request, notification.notification_uuid)
|
||||
progress_detail_list = []
|
||||
for progress_detail in notification_obj.recovery_workflow_details:
|
||||
# Retrieve progress name from detailed name.
|
||||
action = progress_detail['name']
|
||||
for task in progress_detail['progress_details']:
|
||||
id = id + 1
|
||||
progress_obj = notification_tab.ProgressDetailsItem(
|
||||
id,
|
||||
action,
|
||||
task['timestamp'],
|
||||
task['message']
|
||||
)
|
||||
progress_detail_list.append(progress_obj)
|
||||
return progress_detail_list
|
||||
except Exception as e:
|
||||
error_message = _("Failed to get progress details"
|
||||
" for notification '%(notification)', Reason: "
|
||||
"%(reason)") % (
|
||||
{'notification': notification.notification_uuid, 'reason': e})
|
||||
|
||||
exceptions.handle(self.request, error_message)
|
||||
return []
|
||||
|
||||
|
||||
class NotificationDetailTabs(tabs.DetailTabsGroup):
|
||||
slug = "notification_details"
|
||||
tabs = (OverviewTab,)
|
||||
if api_versions.APIVersion(
|
||||
plugin.DEFAULT_HA_API_VERSION) >= api_versions.APIVersion("1.1"):
|
||||
tabs = (OverviewTab, NotificationProgressDetailsTab)
|
||||
else:
|
||||
tabs = (OverviewTab,)
|
||||
|
|
|
@ -21,4 +21,3 @@
|
|||
<dd>{{ notification.payload }}</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{{ table.render }}
|
|
@ -11,5 +11,6 @@ pbr!=2.1.0,>=2.0.0 # Apache-2.0
|
|||
|
||||
# Horizon Core Requirements
|
||||
horizon>=14.0.0.0b3 # Apache-2.0
|
||||
openstacksdk>=0.13.0
|
||||
openstacksdk>=0.26.0
|
||||
python-masakariclient>=5.4.0
|
||||
PyYAML>=3.12 # MIT
|
||||
|
|
Loading…
Reference in New Issue