]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/controllers/erasure_code_profile.py
3c8ba61f9f8ab9387038d56a879d5e499d630a82
[ceph.git] / ceph / src / pybind / mgr / dashboard / controllers / erasure_code_profile.py
1 # -*- coding: utf-8 -*-
2 from __future__ import absolute_import
3
4 from cherrypy import NotFound
5
6 from . import ApiController, ControllerDoc, RESTController, Endpoint, ReadPermission, \
7 UiApiController
8 from ..security import Scope
9 from ..services.ceph_service import CephService
10 from .. import mgr
11
12
13 @ApiController('/erasure_code_profile', Scope.POOL)
14 class ErasureCodeProfile(RESTController):
15 """
16 create() supports additional key-value arguments that are passed to the
17 ECP plugin.
18 """
19
20 def list(self):
21 return CephService.get_erasure_code_profiles()
22
23 def get(self, name):
24 profiles = CephService.get_erasure_code_profiles()
25 for p in profiles:
26 if p['name'] == name:
27 return p
28 raise NotFound('No such erasure code profile')
29
30 def create(self, name, **kwargs):
31 profile = ['{}={}'.format(key, value) for key, value in kwargs.items()]
32 CephService.send_command('mon', 'osd erasure-code-profile set', name=name,
33 profile=profile)
34
35 def delete(self, name):
36 CephService.send_command('mon', 'osd erasure-code-profile rm', name=name)
37
38
39 @UiApiController('/erasure_code_profile', Scope.POOL)
40 @ControllerDoc("Dashboard UI helper function; not part of the public API", "ErasureCodeProfileUi")
41 class ErasureCodeProfileUi(ErasureCodeProfile):
42 @Endpoint()
43 @ReadPermission
44 def info(self):
45 """
46 Used for profile creation and editing
47 """
48 config = mgr.get('config')
49 return {
50 # Because 'shec' is experimental it's not included
51 'plugins': config['osd_erasure_code_plugins'].split() + ['shec'],
52 'directory': config['erasure_code_dir'],
53 'nodes': mgr.get('osd_map_tree')['nodes'],
54 'names': [name for name, _ in
55 mgr.get('osd_map').get('erasure_code_profiles', {}).items()]
56 }