]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/controllers/erasure_code_profile.py
update source to Ceph Pacific 16.2.2
[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 mgr
7 from ..security import Scope
8 from ..services.ceph_service import CephService
9 from . import ApiController, ControllerDoc, Endpoint, EndpointDoc, \
10 ReadPermission, RESTController, UiApiController
11
12 LIST_CODE__SCHEMA = {
13 "crush-failure-domain": (str, ''),
14 "k": (int, 'Number of data chunks'),
15 "m": (int, 'Number of coding chunks'),
16 "plugin": (str, 'Plugin Info'),
17 "technique": (str, ''),
18 "name": (str, 'Name of the profile')
19 }
20
21
22 @ApiController('/erasure_code_profile', Scope.POOL)
23 @ControllerDoc("Erasure Code Profile Management API", "ErasureCodeProfile")
24 class ErasureCodeProfile(RESTController):
25 """
26 create() supports additional key-value arguments that are passed to the
27 ECP plugin.
28 """
29 @EndpointDoc("List Erasure Code Profile Information",
30 responses={'200': [LIST_CODE__SCHEMA]})
31 def list(self):
32 return CephService.get_erasure_code_profiles()
33
34 def get(self, name):
35 profiles = CephService.get_erasure_code_profiles()
36 for p in profiles:
37 if p['name'] == name:
38 return p
39 raise NotFound('No such erasure code profile')
40
41 def create(self, name, **kwargs):
42 profile = ['{}={}'.format(key, value) for key, value in kwargs.items()]
43 CephService.send_command('mon', 'osd erasure-code-profile set', name=name,
44 profile=profile)
45
46 def delete(self, name):
47 CephService.send_command('mon', 'osd erasure-code-profile rm', name=name)
48
49
50 @UiApiController('/erasure_code_profile', Scope.POOL)
51 @ControllerDoc("Dashboard UI helper function; not part of the public API", "ErasureCodeProfileUi")
52 class ErasureCodeProfileUi(ErasureCodeProfile):
53 @Endpoint()
54 @ReadPermission
55 def info(self):
56 """
57 Used for profile creation and editing
58 """
59 config = mgr.get('config')
60 return {
61 # Because 'shec' and 'clay' are experimental they're not included
62 'plugins': config['osd_erasure_code_plugins'].split() + ['shec', 'clay'],
63 'directory': config['erasure_code_dir'],
64 'nodes': mgr.get('osd_map_tree')['nodes'],
65 'names': [name for name, _ in
66 mgr.get('osd_map').get('erasure_code_profiles', {}).items()]
67 }