]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/rbd_ls.py
update sources to v12.1.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / rbd_ls.py
CommitLineData
31f18b77 1
31f18b77 2import rbd
224ce89b
WB
3import rados
4from types import OsdMap
31f18b77
FG
5from remote_view_cache import RemoteViewCache
6
224ce89b
WB
7class RbdPoolLs(RemoteViewCache):
8 def _get(self):
9 from mgr_module import ceph_state
10 ctx_capsule = ceph_state.get_context()
11
12 osd_map = self._module.get_sync_object(OsdMap).data
13 osd_pools = [pool['pool_name'] for pool in osd_map['pools']]
14
15 rbd_pools = []
16 for pool in osd_pools:
17 self.log.debug("Constructing IOCtx " + pool)
18 try:
19 ioctx = self._module.rados.open_ioctx(pool)
20 ioctx.stat("rbd_directory")
21 rbd_pools.append(pool)
22 except (rados.PermissionError, rados.ObjectNotFound):
23 self.log.debug("No RBD directory in " + pool)
24 except:
25 self.log.exception("Failed to open pool " + pool)
26
27 return rbd_pools
31f18b77
FG
28
29class RbdLs(RemoteViewCache):
30 def __init__(self, module_inst, pool):
31 super(RbdLs, self).__init__(module_inst)
32
33 self.pool = pool
34
35 self.ioctx = None
36 self.rbd = None
37
38 def _init(self):
224ce89b
WB
39 self.log.debug("Constructing IOCtx")
40 self.ioctx = self._module.rados.open_ioctx(self.pool)
31f18b77 41
224ce89b 42 self.log.debug("Constructing RBD")
31f18b77
FG
43 self.rbd = rbd.RBD()
44
45 def _get(self):
46 self.log.debug("rbd.list")
47 names = self.rbd.list(self.ioctx)
48 result = []
49 for name in names:
50 i = rbd.Image(self.ioctx, name)
51 stat = i.stat()
52 stat['name'] = name
224ce89b
WB
53
54 try:
55 parent_info = i.parent_info()
56 parent = "{}@{}".format(parent_info[0], parent_info[1])
57 if parent_info[0] != self.pool:
58 parent = "{}/{}".format(parent_info[0], parent)
59 stat['parent'] = parent
60 except rbd.ImageNotFound:
61 pass
31f18b77
FG
62 result.append(stat)
63 return result