}
}
+void ActivePyModules::update_progress_event(
+ const std::string& evid,
+ const std::string& desc,
+ float progress)
+{
+ std::lock_guard l(lock);
+ auto& pe = progress_events[evid];
+ pe.message = desc;
+ pe.progress = progress;
+}
+
+void ActivePyModules::complete_progress_event(const std::string& evid)
+{
+ std::lock_guard l(lock);
+ progress_events.erase(evid);
+}
+
+void ActivePyModules::clear_all_progress_events()
+{
+ std::lock_guard l(lock);
+ progress_events.clear();
+}
+
+void ActivePyModules::get_progress_events(std::map<std::string,ProgressEvent> *events)
+{
+ std::lock_guard l(lock);
+ *events = progress_events;
+}
+
void ActivePyModules::config_notify()
{
std::lock_guard l(lock);
#include "common/LogClient.h"
#include "mon/MgrMap.h"
#include "mon/MonCommand.h"
+#include "mon/mon_types.h"
#include "DaemonState.h"
#include "ClusterState.h"
DaemonServer &server;
PyModuleRegistry &py_module_registry;
+ map<std::string,ProgressEvent> progress_events;
mutable Mutex lock{"ActivePyModules::lock"};
health_check_map_t&& checks);
void get_health_checks(health_check_map_t *checks);
+ void update_progress_event(const std::string& evid,
+ const std::string& desc,
+ float progress);
+ void complete_progress_event(const std::string& evid);
+ void clear_all_progress_events();
+ void get_progress_events(std::map<std::string,ProgressEvent>* events);
+
void config_notify();
void set_uri(const std::string& module_name, const std::string &uri);
}
}
+static PyObject*
+ceph_update_progress_event(BaseMgrModule *self, PyObject *args)
+{
+ char *evid = nullptr;
+ char *desc = nullptr;
+ float progress = 0.0;
+ if (!PyArg_ParseTuple(args, "ssf:ceph_update_progress_event",
+ &evid, &desc, &progress)) {
+ return nullptr;
+ }
+
+ PyThreadState *tstate = PyEval_SaveThread();
+ self->py_modules->update_progress_event(evid, desc, progress);
+ PyEval_RestoreThread(tstate);
+
+ Py_RETURN_NONE;
+}
+
+static PyObject*
+ceph_complete_progress_event(BaseMgrModule *self, PyObject *args)
+{
+ char *evid = nullptr;
+ if (!PyArg_ParseTuple(args, "s:ceph_complete_progress_event",
+ &evid)) {
+ return nullptr;
+ }
+
+ PyThreadState *tstate = PyEval_SaveThread();
+ self->py_modules->complete_progress_event(evid);
+ PyEval_RestoreThread(tstate);
+
+ Py_RETURN_NONE;
+}
+
+static PyObject*
+ceph_clear_all_progress_events(BaseMgrModule *self, PyObject *args)
+{
+ PyThreadState *tstate = PyEval_SaveThread();
+ self->py_modules->clear_all_progress_events();
+ PyEval_RestoreThread(tstate);
+
+ Py_RETURN_NONE;
+}
+
+
+
static PyObject *
ceph_dispatch_remote(BaseMgrModule *self, PyObject *args)
{
METH_NOARGS, "Find out whether this mgr daemon currently has "
"a connection to a monitor"},
+ {"_ceph_update_progress_event", (PyCFunction)ceph_update_progress_event,
+ METH_VARARGS, "Update status of a progress event"},
+ {"_ceph_complete_progress_event", (PyCFunction)ceph_complete_progress_event,
+ METH_VARARGS, "Complete a progress event"},
+ {"_ceph_clear_all_progress_events", (PyCFunction)ceph_clear_all_progress_events,
+ METH_NOARGS, "Clear all progress events"},
+
{"_ceph_dispatch_remote", (PyCFunction)ceph_dispatch_remote,
METH_VARARGS, "Dispatch a call to another module"},
return out;
}
+
+struct ProgressEvent {
+ string message; ///< event description
+ float progress; ///< [0..1]
+
+ void encode(bufferlist& bl) const {
+ ENCODE_START(1, 1, bl);
+ encode(message, bl);
+ encode(progress, bl);
+ ENCODE_FINISH(bl);
+ }
+ void decode(bufferlist::const_iterator& p) {
+ DECODE_START(1, p);
+ decode(message, p);
+ decode(progress, p);
+ DECODE_FINISH(p);
+ }
+ void dump(Formatter *f) const {
+ f->dump_string("message", message);
+ f->dump_float("progress", progress);
+ }
+};
+WRITE_CLASS_ENCODER(ProgressEvent)
+
#endif
return self._ceph_have_mon_connection()
+ def update_progress_event(self, evid, desc, progress):
+ return self._ceph_update_progress_event(str(evid), str(desc), float(progress))
+
+ def complete_progress_event(self, evid):
+ return self._ceph_complete_progress_event(str(evid))
+
+ def clear_all_progress_events(self):
+ return self._ceph_clear_all_progress_events()
+
@property
def rados(self):
"""