diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/pybind/mgr/dashboard/controllers/erasure_code_profile.py | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/pybind/mgr/dashboard/controllers/erasure_code_profile.py')
-rw-r--r-- | src/pybind/mgr/dashboard/controllers/erasure_code_profile.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/pybind/mgr/dashboard/controllers/erasure_code_profile.py b/src/pybind/mgr/dashboard/controllers/erasure_code_profile.py new file mode 100644 index 00000000..34c9f651 --- /dev/null +++ b/src/pybind/mgr/dashboard/controllers/erasure_code_profile.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import + +from cherrypy import NotFound + +from . import ApiController, RESTController, Endpoint, ReadPermission +from ..security import Scope +from ..services.ceph_service import CephService +from .. import mgr + + +def _serialize_ecp(name, ecp): + def serialize_numbers(key): + value = ecp.get(key) + if value is not None: + ecp[key] = int(value) + + ecp['name'] = name + serialize_numbers('k') + serialize_numbers('m') + return ecp + + +@ApiController('/erasure_code_profile', Scope.POOL) +class ErasureCodeProfile(RESTController): + ''' + create() supports additional key-value arguments that are passed to the + ECP plugin. + ''' + + def list(self): + ret = [] + for name, ecp in mgr.get('osd_map').get('erasure_code_profiles', {}).items(): + ret.append(_serialize_ecp(name, ecp)) + return ret + + def get(self, name): + try: + ecp = mgr.get('osd_map')['erasure_code_profiles'][name] + return _serialize_ecp(name, ecp) + except KeyError: + raise NotFound('No such erasure code profile') + + def create(self, name, **kwargs): + profile = ['{}={}'.format(key, value) for key, value in kwargs.items()] + CephService.send_command('mon', 'osd erasure-code-profile set', name=name, + profile=profile) + + def delete(self, name): + CephService.send_command('mon', 'osd erasure-code-profile rm', name=name) + + @Endpoint() + @ReadPermission + def _info(self): + '''Used for profile creation and editing''' + config = mgr.get('config') + osd_map_crush = mgr.get('osd_map_crush') + return { + # Because 'shec' is experimental it's not included + 'plugins': config['osd_erasure_code_plugins'].split() + ['shec'], + 'directory': config['erasure_code_dir'], + 'devices': list({device['class'] for device in osd_map_crush['devices']}), + 'failure_domains': [domain['name'] for domain in osd_map_crush['types']], + 'names': [name for name, _ in + mgr.get('osd_map').get('erasure_code_profiles', {}).items()] + } |