]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | # -*- coding: utf-8 -*- |
2 | from __future__ import absolute_import | |
3 | ||
4 | from cherrypy import NotFound | |
5 | ||
9f95a23c | 6 | from . import ApiController, RESTController, Endpoint, ReadPermission, UiApiController |
11fdf7f2 TL |
7 | from ..security import Scope |
8 | from ..services.ceph_service import CephService | |
9 | from .. import mgr | |
10 | ||
11 | ||
11fdf7f2 TL |
12 | @ApiController('/erasure_code_profile', Scope.POOL) |
13 | class ErasureCodeProfile(RESTController): | |
e306af50 | 14 | """ |
11fdf7f2 TL |
15 | create() supports additional key-value arguments that are passed to the |
16 | ECP plugin. | |
e306af50 | 17 | """ |
11fdf7f2 TL |
18 | |
19 | def list(self): | |
9f95a23c | 20 | return CephService.get_erasure_code_profiles() |
11fdf7f2 TL |
21 | |
22 | def get(self, name): | |
9f95a23c TL |
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') | |
11fdf7f2 TL |
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 | ||
9f95a23c TL |
37 | |
38 | @UiApiController('/erasure_code_profile', Scope.POOL) | |
39 | class ErasureCodeProfileUi(ErasureCodeProfile): | |
11fdf7f2 TL |
40 | @Endpoint() |
41 | @ReadPermission | |
9f95a23c | 42 | def info(self): |
e306af50 TL |
43 | """ |
44 | Used for profile creation and editing | |
45 | """ | |
11fdf7f2 | 46 | config = mgr.get('config') |
11fdf7f2 TL |
47 | return { |
48 | # Because 'shec' is experimental it's not included | |
49 | 'plugins': config['osd_erasure_code_plugins'].split() + ['shec'], | |
50 | 'directory': config['erasure_code_dir'], | |
e306af50 | 51 | 'nodes': mgr.get('osd_map_tree')['nodes'], |
11fdf7f2 TL |
52 | 'names': [name for name, _ in |
53 | mgr.get('osd_map').get('erasure_code_profiles', {}).items()] | |
54 | } |