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