]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/rbd_ls.py
update sources to v12.1.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / rbd_ls.py
index 510a7777820368a9628b47588ab532219c340ec6..e03d78ed1ade8f0f23831779ee61e041e979057a 100644 (file)
@@ -1,8 +1,30 @@
 
-import rados
 import rbd
+import rados
+from types import OsdMap
 from remote_view_cache import RemoteViewCache
 
+class RbdPoolLs(RemoteViewCache):
+    def _get(self):
+        from mgr_module import ceph_state
+        ctx_capsule = ceph_state.get_context()
+
+        osd_map = self._module.get_sync_object(OsdMap).data
+        osd_pools = [pool['pool_name'] for pool in osd_map['pools']]
+
+        rbd_pools = []
+        for pool in osd_pools:
+            self.log.debug("Constructing IOCtx " + pool)
+            try:
+                ioctx = self._module.rados.open_ioctx(pool)
+                ioctx.stat("rbd_directory")
+                rbd_pools.append(pool)
+            except (rados.PermissionError, rados.ObjectNotFound):
+                self.log.debug("No RBD directory in " + pool)
+            except:
+                self.log.exception("Failed to open pool " + pool)
+
+        return rbd_pools
 
 class RbdLs(RemoteViewCache):
     def __init__(self, module_inst, pool):
@@ -14,16 +36,10 @@ class RbdLs(RemoteViewCache):
         self.rbd = None
 
     def _init(self):
-        from mgr_module import ceph_state
-        ctx_capsule = ceph_state.get_context()
-
-        self.log.info("Constructing Rados")
-        cluster = rados.Rados(context=ctx_capsule)
-        cluster.connect()
-        self.log.info("Constructing IOCtx")
-        self.ioctx = cluster.open_ioctx("rbd")
+        self.log.debug("Constructing IOCtx")
+        self.ioctx = self._module.rados.open_ioctx(self.pool)
 
-        self.log.info("Constructing RBD")
+        self.log.debug("Constructing RBD")
         self.rbd = rbd.RBD()
 
     def _get(self):
@@ -34,5 +50,14 @@ class RbdLs(RemoteViewCache):
             i = rbd.Image(self.ioctx, name)
             stat = i.stat()
             stat['name'] = name
+
+            try:
+                parent_info = i.parent_info()
+                parent = "{}@{}".format(parent_info[0], parent_info[1])
+                if parent_info[0] != self.pool:
+                    parent = "{}/{}".format(parent_info[0], parent)
+                stat['parent'] = parent
+            except rbd.ImageNotFound:
+                pass
             result.append(stat)
         return result