diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/pybind/mgr/rbd_support/common.py | |
parent | Initial commit. (diff) | |
download | ceph-upstream/16.2.11+ds.tar.xz ceph-upstream/16.2.11+ds.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/pybind/mgr/rbd_support/common.py')
-rw-r--r-- | src/pybind/mgr/rbd_support/common.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/pybind/mgr/rbd_support/common.py b/src/pybind/mgr/rbd_support/common.py new file mode 100644 index 000000000..f6bac8f39 --- /dev/null +++ b/src/pybind/mgr/rbd_support/common.py @@ -0,0 +1,34 @@ +import re + +GLOBAL_POOL_KEY = (None, None) + +class NotAuthorizedError(Exception): + pass + + +def is_authorized(module, pool, namespace): + return module.is_authorized({"pool": pool or '', + "namespace": namespace or ''}) + + +def authorize_request(module, pool, namespace): + if not is_authorized(module, pool, namespace): + raise NotAuthorizedError("not authorized on pool={}, namespace={}".format( + pool, namespace)) + + +def extract_pool_key(pool_spec): + if not pool_spec: + return GLOBAL_POOL_KEY + + match = re.match(r'^([^/]+)(?:/([^/]+))?$', pool_spec) + if not match: + raise ValueError("Invalid pool spec: {}".format(pool_spec)) + return (match.group(1), match.group(2) or '') + + +def get_rbd_pools(module): + osd_map = module.get('osd_map') + return {pool['pool']: pool['pool_name'] for pool in osd_map['pools'] + if 'rbd' in pool.get('application_metadata', {})} + |