]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/controllers/erasure_code_profile.py
ca63ba286a4b1a3c7bee597a21ff12d1e2e70b05
[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, RESTController, Endpoint, ReadPermission, UiApiController
7 from ..security import Scope
8 from ..services.ceph_service import CephService
9 from .. import mgr
10
11
12 @ApiController('/erasure_code_profile', Scope.POOL)
13 class ErasureCodeProfile(RESTController):
14 '''
15 create() supports additional key-value arguments that are passed to the
16 ECP plugin.
17 '''
18
19 def list(self):
20 return CephService.get_erasure_code_profiles()
21
22 def get(self, name):
23 profiles = CephService.get_erasure_code_profiles()
24 for p in profiles:
25 if p['name'] == name:
26 return p
27 raise NotFound('No such erasure code profile')
28
29 def create(self, name, **kwargs):
30 profile = ['{}={}'.format(key, value) for key, value in kwargs.items()]
31 CephService.send_command('mon', 'osd erasure-code-profile set', name=name,
32 profile=profile)
33
34 def delete(self, name):
35 CephService.send_command('mon', 'osd erasure-code-profile rm', name=name)
36
37
38 @UiApiController('/erasure_code_profile', Scope.POOL)
39 class ErasureCodeProfileUi(ErasureCodeProfile):
40 @Endpoint()
41 @ReadPermission
42 def info(self):
43 '''Used for profile creation and editing'''
44 config = mgr.get('config')
45 osd_map_crush = mgr.get('osd_map_crush')
46 return {
47 # Because 'shec' is experimental it's not included
48 'plugins': config['osd_erasure_code_plugins'].split() + ['shec'],
49 'directory': config['erasure_code_dir'],
50 'devices': list({device['class'] for device in osd_map_crush['devices']}),
51 'failure_domains': [domain['name'] for domain in osd_map_crush['types']],
52 'names': [name for name, _ in
53 mgr.get('osd_map').get('erasure_code_profiles', {}).items()]
54 }