From eacc9021459b31e42232bb958536d594d03b07b3 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 26 Sep 2017 18:35:29 -0400 Subject: [PATCH] mgr/PyOSDMap: add CRUSH get_item_weight Signed-off-by: Sage Weil --- src/mgr/PyOSDMap.cc | 17 +++++++++++++++++ src/pybind/mgr/mgr_module.py | 3 +++ 2 files changed, 20 insertions(+) diff --git a/src/mgr/PyOSDMap.cc b/src/mgr/PyOSDMap.cc index e630cadef3779..121bf80651df8 100644 --- a/src/mgr/PyOSDMap.cc +++ b/src/mgr/PyOSDMap.cc @@ -331,6 +331,22 @@ static PyObject *crush_get_item_name(PyObject *self, PyObject *args) return PyString_FromString(crush->get_item_name(item)); } +static PyObject *crush_get_item_weight(PyObject *self, PyObject *args) +{ + PyObject *obj; + int item; + if (!PyArg_ParseTuple(args, "Oi:get_item_weight", + &obj, &item)) { + return nullptr; + } + CrushWrapper *crush = static_cast( + PyCapsule_GetPointer(obj, nullptr)); + if (!crush->item_exists(item)) { + Py_RETURN_NONE; + } + return PyFloat_FromDouble(crush->get_item_weightf(item)); +} + static PyObject *crush_find_takes(PyObject *self, PyObject *obj) { CrushWrapper *crush = static_cast( @@ -372,6 +388,7 @@ static PyObject *crush_get_take_weight_osd_map(PyObject *self, PyObject *args) PyMethodDef CRUSHMapMethods[] = { {"dump", crush_dump, METH_O, "Dump map"}, {"get_item_name", crush_get_item_name, METH_VARARGS, "Get item name"}, + {"get_item_weight", crush_get_item_weight, METH_VARARGS, "Get item weight"}, {"find_takes", crush_find_takes, METH_O, "Find distinct TAKE roots"}, {"get_take_weight_osd_map", crush_get_take_weight_osd_map, METH_VARARGS, "Get OSD weight map for a given TAKE root node"}, diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 83fc75ae2cf14..0c2cd5d174978 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -144,6 +144,9 @@ class CRUSHMap(object): def dump(self): return ceph_crushmap.dump(self._handle) + def get_item_weight(self, item): + return ceph_crushmap.get_item_weight(self._handle, item) + def get_item_name(self, item): return ceph_crushmap.get_item_name(self._handle, item) -- 2.39.5