]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
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('/crush_rule', Scope.POOL) | |
13 | class CrushRule(RESTController): | |
14 | def list(self): | |
15 | return mgr.get('osd_map_crush')['rules'] | |
16 | ||
17 | def get(self, name): | |
18 | rules = mgr.get('osd_map_crush')['rules'] | |
19 | for r in rules: | |
20 | if r['rule_name'] == name: | |
21 | return r | |
22 | raise NotFound('No such crush rule') | |
23 | ||
24 | def create(self, name, root, failure_domain, device_class=None): | |
25 | rule = { | |
26 | 'name': name, | |
27 | 'root': root, | |
28 | 'type': failure_domain, | |
29 | 'class': device_class | |
30 | } | |
31 | CephService.send_command('mon', 'osd crush rule create-replicated', **rule) | |
32 | ||
33 | def delete(self, name): | |
34 | CephService.send_command('mon', 'osd crush rule rm', name=name) | |
35 | ||
36 | ||
37 | @UiApiController('/crush_rule', Scope.POOL) | |
38 | class CrushRuleUi(CrushRule): | |
39 | @Endpoint() | |
40 | @ReadPermission | |
41 | def info(self): | |
42 | '''Used for crush rule creation modal''' | |
43 | return { | |
44 | 'names': [r['rule_name'] for r in mgr.get('osd_map_crush')['rules']], | |
45 | 'nodes': mgr.get('osd_map_tree')['nodes'] | |
46 | } |