1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2016 John Spray <john.spray@redhat.com>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #include "BaseMgrStandbyModule.h"
17 #include "StandbyPyModules.h"
20 #define dout_context g_ceph_context
21 #define dout_subsys ceph_subsys_mgr
25 StandbyPyModule *this_module;
26 } BaseMgrStandbyModule;
29 BaseMgrStandbyModule_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
31 BaseMgrStandbyModule *self;
33 self = (BaseMgrStandbyModule *)type->tp_alloc(type, 0);
35 return (PyObject *)self;
39 BaseMgrStandbyModule_init(BaseMgrStandbyModule *self, PyObject *args, PyObject *kwds)
41 PyObject *this_module_capsule = nullptr;
42 static const char *kwlist[] = {"this_module", NULL};
44 if (! PyArg_ParseTupleAndKeywords(args, kwds, "O",
45 const_cast<char**>(kwlist),
46 &this_module_capsule)) {
50 self->this_module = (StandbyPyModule*)PyCapsule_GetPointer(
51 this_module_capsule, nullptr);
52 assert(self->this_module);
58 ceph_get_mgr_id(BaseMgrStandbyModule *self, PyObject *args)
60 return PyString_FromString(g_conf->name.get_id().c_str());
64 ceph_config_get(BaseMgrStandbyModule *self, PyObject *args)
67 if (!PyArg_ParseTuple(args, "s:ceph_config_get", &what)) {
68 derr << "Invalid args!" << dendl;
73 bool found = self->this_module->get_config(what, &value);
75 dout(10) << "ceph_config_get " << what << " found: " << value.c_str() << dendl;
76 return PyString_FromString(value.c_str());
78 dout(4) << "ceph_config_get " << what << " not found " << dendl;
84 ceph_get_active_uri(BaseMgrStandbyModule *self, PyObject *args)
86 return PyString_FromString(self->this_module->get_active_uri().c_str());
90 ceph_log(BaseMgrStandbyModule *self, PyObject *args)
93 char *record = nullptr;
94 if (!PyArg_ParseTuple(args, "is:log", &level, &record)) {
98 assert(self->this_module);
100 self->this_module->log(level, record);
105 PyMethodDef BaseMgrStandbyModule_methods[] = {
107 {"_ceph_get_mgr_id", (PyCFunction)ceph_get_mgr_id, METH_NOARGS,
108 "Get the name of the Mgr daemon where we are running"},
110 {"_ceph_get_config", (PyCFunction)ceph_config_get, METH_VARARGS,
111 "Get a configuration value"},
113 {"_ceph_get_active_uri", (PyCFunction)ceph_get_active_uri, METH_NOARGS,
114 "Get the URI of the active instance of this module, if any"},
116 {"_ceph_log", (PyCFunction)ceph_log, METH_VARARGS,
117 "Emit a log message"},
119 {NULL, NULL, 0, NULL}
122 PyTypeObject BaseMgrStandbyModuleType = {
123 PyVarObject_HEAD_INIT(NULL, 0)
124 "ceph_module.BaseMgrStandbyModule", /* tp_name */
125 sizeof(BaseMgrStandbyModule), /* tp_basicsize */
133 0, /* tp_as_number */
134 0, /* tp_as_sequence */
135 0, /* tp_as_mapping */
141 0, /* tp_as_buffer */
142 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
143 "ceph-mgr Standby Python Plugin", /* tp_doc */
146 0, /* tp_richcompare */
147 0, /* tp_weaklistoffset */
150 BaseMgrStandbyModule_methods, /* tp_methods */
155 0, /* tp_descr_get */
156 0, /* tp_descr_set */
157 0, /* tp_dictoffset */
158 (initproc)BaseMgrStandbyModule_init, /* tp_init */
160 BaseMgrStandbyModule_new, /* tp_new */