]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: progress mgr module service
authorRicardo Dias <rdias@suse.com>
Mon, 15 Jul 2019 14:07:42 +0000 (15:07 +0100)
committerRicardo Dias <rdias@suse.com>
Wed, 17 Jul 2019 10:50:50 +0000 (11:50 +0100)
This service module implements helper methods to retrieve
tasks information from the progress mgr module.

Signed-off-by: Ricardo Dias <rdias@suse.com>
src/pybind/mgr/dashboard/services/progress.py [new file with mode: 0644]

diff --git a/src/pybind/mgr/dashboard/services/progress.py b/src/pybind/mgr/dashboard/services/progress.py
new file mode 100644 (file)
index 0000000..4bacc19
--- /dev/null
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+'''
+Progress Mgr Module Helper
+
+This python module implements helper methods to retrieve the
+executing and completed tasks tacked by the progress mgr module
+using the same structure of dashboard tasks
+'''
+
+from __future__ import absolute_import
+
+from datetime import datetime
+
+from .. import mgr, logger
+
+
+def get_progress_tasks():
+    executing_t = []
+    finished_t = []
+    progress_events = mgr.remote('progress', "_json")
+
+    for ev in progress_events['events']:
+        logger.debug("[Progress] event=%s", ev)
+        executing_t.append({
+            # we're prepending the "progress/" prefix to tag tasks that come
+            # from the progress module
+            'name': "progress/{}".format(ev['message']),
+            'metadata': dict(ev['refs']),
+            'begin_time': "{}Z".format(datetime.fromtimestamp(ev["started_at"])
+                                       .isoformat()),
+            'progress': int(100 * ev['progress'])
+        })
+
+    for ev in progress_events['completed']:
+        logger.debug("[Progress] finished event=%s", ev)
+        finished_t.append({
+            'name': "progress/{}".format(ev['message']),
+            'metadata': dict(ev['refs']),
+            'begin_time': "{}Z".format(datetime.fromtimestamp(ev["started_at"])
+                                       .isoformat()),
+            'end_time': "{}Z".format(datetime.fromtimestamp(ev['finished_at'])
+                                     .isoformat()),
+            'duration': ev['finished_at'] - ev['started_at'],
+            'progress': 100,
+            'success': True,
+            'ret_value': None,
+            'exception': None
+        })
+
+    return executing_t, finished_t