return commands;
}
+std::map<std::string, std::string> Mgr::get_services() const
+{
+ Mutex::Locker l(lock);
+
+ return py_modules.get_services();
+}
+
void shutdown();
std::vector<MonCommand> get_command_set() const;
+ std::map<std::string, std::string> get_services() const;
};
#endif
int load_commands();
+ // Optional, URI exposed by plugins that implement serve()
+ std::string uri;
+
public:
MgrPyModule(const std::string &module_name, const std::string &sys_path, PyThreadState *main_ts);
~MgrPyModule();
health_checks = std::move(c);
}
void get_health_checks(health_check_map_t *checks);
+
+ void set_uri(const std::string &str)
+ {
+ uri = str;
+ }
+
+ std::string get_uri() const
+ {
+ return uri;
+ }
};
std::string handle_pyerror();
modules,
std::move(metadata));
- if (available && !available_in_map) {
- // We are informing the mon that we are done initializing: inform
- // it of our command set. This has to happen after init() because
- // it needs the python modules to have loaded.
- m->set_command_descs(active_mgr->get_command_set());
- dout(4) << "going active, including " << m->get_command_descs().size()
- << " commands in beacon" << dendl;
+ if (available) {
+ if (!available_in_map) {
+ // We are informing the mon that we are done initializing: inform
+ // it of our command set. This has to happen after init() because
+ // it needs the python modules to have loaded.
+ m->set_command_descs(active_mgr->get_command_set());
+ dout(4) << "going active, including " << m->get_command_descs().size()
+ << " commands in beacon" << dendl;
+ }
+
+ m->set_services(active_mgr->get_services());
}
monc.send_mon_message(m);
return result;
}
+
+std::map<std::string, std::string> PyModules::get_services() const
+{
+ std::map<std::string, std::string> result;
+ Mutex::Locker l(lock);
+ for (const auto& i : modules) {
+ const auto &module = i.second.get();
+ std::string svc_str = module->get_uri();
+ if (!svc_str.empty()) {
+ result[module->get_name()] = svc_str;
+ }
+ }
+
+ return result;
+}
+
void PyModules::insert_config(const std::map<std::string,
std::string> &new_config)
{
p.second->get_health_checks(checks);
}
}
+
+void PyModules::set_uri(const std::string& module_name,
+ const std::string &uri)
+{
+ Mutex::Locker l(lock);
+
+ dout(4) << " module " << module_name << " set URI '" << uri << "'" << dendl;
+
+ modules[module_name]->set_uri(uri);
+}
+
health_check_map_t&& checks);
void get_health_checks(health_check_map_t *checks);
+ void set_uri(const std::string& module_name, const std::string &uri);
+
void log(const std::string &module_name,
int level, const std::string &record);
void insert_config(const std::map<std::string, std::string> &new_config);
+ std::map<std::string, std::string> get_services() const;
+
// Public so that MonCommandCompletion can use it
// FIXME: for send_command completion notifications,
// send it to only the module that sent the command, not everyone
return self->py_modules->get_perf_schema_python(type_str, svc_id);
}
-
static PyObject *
ceph_get_osdmap(BaseMgrModule *self, PyObject *args)
{
return self->py_modules->get_osdmap();
}
+static PyObject*
+ceph_set_uri(BaseMgrModule *self, PyObject *args)
+{
+ char *svc_str = nullptr;
+ if (!PyArg_ParseTuple(args, "s:ceph_advertize_service",
+ &svc_str)) {
+ return nullptr;
+ }
+
+ // We call down into PyModules even though we have a MgrPyModule
+ // reference here, because MgrPyModule's fields are protected
+ // by PyModules' lock.
+ self->py_modules->set_uri(self->this_module->get_name(), svc_str);
+
+ Py_RETURN_NONE;
+}
PyMethodDef BaseMgrModule_methods[] = {
{"_ceph_get_osdmap", (PyCFunction)ceph_get_osdmap, METH_NOARGS,
"Get an OSDMap* in a python capsule"},
+ {"_ceph_set_uri", (PyCFunction)ceph_set_uri, METH_VARARGS,
+ "Advertize a service URI served by this module"},
+
{NULL, NULL, 0, NULL}
};
OSDMap.
:return: OSDMap
"""
- return OSDMap(ceph_state.get_osdmap())
+ return OSDMap(self._ceph_get_osdmap())
def get_all_perf_counters(self, prio_limit=PRIO_USEFUL):
"""
self.log.debug("returning {0} counter".format(len(result)))
return result
+
+ def set_uri(self, uri):
+ """
+ If the module exposes a service, then call this to publish the
+ address once it is available.
+
+ :return: a string
+ """
+ return self._ceph_set_uri(uri)