]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/PyOSDMap: add CRUSH get_item_weight
authorSage Weil <sage@redhat.com>
Tue, 26 Sep 2017 22:35:29 +0000 (18:35 -0400)
committerJohn Spray <john.spray@redhat.com>
Wed, 1 Nov 2017 23:03:29 +0000 (23:03 +0000)
Signed-off-by: Sage Weil <sage@redhat.com>
(cherry picked from commit eacc9021459b31e42232bb958536d594d03b07b3)

src/mgr/PyOSDMap.cc
src/pybind/mgr/mgr_module.py

index e630cadef3779e4e41753035df46b7c49dc630d3..121bf80651df8f836054a88f31c0b5fa1697bbe3 100644 (file)
@@ -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<CrushWrapper*>(
+    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<CrushWrapper*>(
@@ -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"},
index 83fc75ae2cf1446887bfa4df6ebf6a5cf2e64f88..0c2cd5d17497845063e546b9e41d9049d87494d8 100644 (file)
@@ -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)