]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr: expose osdmap pg_to_up_acting_osds
authorJohn Spray <john.spray@redhat.com>
Mon, 9 Oct 2017 16:08:38 +0000 (17:08 +0100)
committerJohn Spray <john.spray@redhat.com>
Tue, 11 Sep 2018 10:21:35 +0000 (11:21 +0100)
It's not efficient to have python calling this
O(pg_num) times to find the pgs for an OSD, but
I'm just shooting for something functional for now.

Signed-off-by: John Spray <john.spray@redhat.com>
src/mgr/PyOSDMap.cc
src/pybind/mgr/mgr_module.py

index f2381dc2cf08451ea81f7b5d39fed80fe10ea872..4ec585d50fa34620c0a0d625e5f28a8f397a5471 100644 (file)
@@ -217,6 +217,42 @@ BasePyOSDMap_dealloc(BasePyOSDMap *self)
   Py_TYPE(self)->tp_free(self);
 }
 
+static PyObject *osdmap_pg_to_up_acting_osds(BasePyOSDMap *self, PyObject *args)
+{
+  int pool_id = 0;
+  int ps = 0;
+  if (!PyArg_ParseTuple(args, "ii:pg_to_up_acting_osds",
+                       &pool_id, &ps)) {
+    return nullptr;
+  }
+
+  std::vector<int> up;
+  int up_primary;
+  std::vector<int> acting;
+  int acting_primary;
+  pg_t pg_id(ps, pool_id);
+  self->osdmap->pg_to_up_acting_osds(pg_id,
+      &up, &up_primary,
+      &acting, &acting_primary);
+
+  // (Ab)use PyFormatter as a convenient way to generate a dict
+  PyFormatter f;
+  f.dump_int("up_primary", up_primary);
+  f.dump_int("acting_primary", acting_primary);
+  f.open_array_section("up");
+  for (const auto &i : up) {
+    f.dump_int("osd", i);
+  }
+  f.close_section();
+  f.open_array_section("acting");
+  for (const auto &i : acting) {
+    f.dump_int("osd", i);
+  }
+  f.close_section();
+
+  return f.get();
+}
+
 
 PyMethodDef BasePyOSDMap_methods[] = {
   {"_get_epoch", (PyCFunction)osdmap_get_epoch, METH_NOARGS, "Get OSDMap epoch"},
@@ -234,6 +270,8 @@ PyMethodDef BasePyOSDMap_methods[] = {
    "Calculate new pg-upmap values"},
   {"_map_pool_pgs_up", (PyCFunction)osdmap_map_pool_pgs_up, METH_VARARGS,
    "Calculate up set mappings for all PGs in a pool"},
+  {"_pg_to_up_acting_osds", (PyCFunction)osdmap_pg_to_up_acting_osds, METH_VARARGS,
+    "Calculate up+acting OSDs for a PG ID"},
   {NULL, NULL, 0, NULL}
 };
 
index fd427bd074047eb5bc409e99073e2cb56b6f676c..700f624d1ac5688a22aea9cd12c8683ba12000d8 100644 (file)
@@ -135,6 +135,10 @@ class OSDMap(ceph_module.BasePyOSDMap):
     def map_pool_pgs_up(self, poolid):
         return self._map_pool_pgs_up(poolid)
 
+    def pg_to_up_acting_osds(self, pool_id, ps):
+        return self._pg_to_up_acting_osds(self._handle, pool_id, ps)
+
+
 class OSDMapIncremental(ceph_module.BasePyOSDMapIncremental):
     def get_epoch(self):
         return self._get_epoch()