4 from types
import OsdMap
5 from remote_view_cache
import RemoteViewCache
7 class RbdPoolLs(RemoteViewCache
):
9 from mgr_module
import ceph_state
10 ctx_capsule
= ceph_state
.get_context()
12 osd_map
= self
._module
.get_sync_object(OsdMap
).data
13 osd_pools
= [pool
['pool_name'] for pool
in osd_map
['pools']]
16 for pool
in osd_pools
:
17 self
.log
.debug("Constructing IOCtx " + pool
)
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
)
25 self
.log
.exception("Failed to open pool " + pool
)
29 class RbdLs(RemoteViewCache
):
30 def __init__(self
, module_inst
, pool
):
31 super(RbdLs
, self
).__init
__(module_inst
)
39 self
.log
.debug("Constructing IOCtx")
40 self
.ioctx
= self
._module
.rados
.open_ioctx(self
.pool
)
42 self
.log
.debug("Constructing RBD")
46 self
.log
.debug("rbd.list")
47 names
= self
.rbd
.list(self
.ioctx
)
50 i
= rbd
.Image(self
.ioctx
, name
)
53 features
= i
.features()
54 stat
['features'] = features
55 stat
['features_name'] = self
._format
_bitmask
(features
)
58 parent_info
= i
.parent_info()
59 parent
= "{}@{}".format(parent_info
[0], parent_info
[1])
60 if parent_info
[0] != self
.pool
:
61 parent
= "{}/{}".format(parent_info
[0], parent
)
62 stat
['parent'] = parent
63 except rbd
.ImageNotFound
:
68 def _format_bitmask(self
, features
):
70 RBD_FEATURES_NAME_MAPPING
= {
71 rbd
.RBD_FEATURE_LAYERING
: "layering",
72 rbd
.RBD_FEATURE_STRIPINGV2
: "striping",
73 rbd
.RBD_FEATURE_EXCLUSIVE_LOCK
: "exclusive-lock",
74 rbd
.RBD_FEATURE_OBJECT_MAP
: "object-map",
75 rbd
.RBD_FEATURE_FAST_DIFF
: "fast-diff",
76 rbd
.RBD_FEATURE_DEEP_FLATTEN
: "deep-flatten",
77 rbd
.RBD_FEATURE_JOURNALING
: "journaling",
78 rbd
.RBD_FEATURE_DATA_POOL
: "data-pool",
81 for key
in RBD_FEATURES_NAME_MAPPING
.keys():
82 if (key
& features
== 0):
87 names
= names
+ RBD_FEATURES_NAME_MAPPING
.get(key
)