]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/controllers/crush_rule.py
import 15.2.5
[ceph.git] / ceph / src / pybind / mgr / dashboard / controllers / crush_rule.py
CommitLineData
9f95a23c
TL
1# -*- coding: utf-8 -*-
2from __future__ import absolute_import
3
4from cherrypy import NotFound
5
f6b5b4d7
TL
6from . import ApiController, ControllerDoc, RESTController, Endpoint, ReadPermission, \
7 UiApiController
9f95a23c
TL
8from ..security import Scope
9from ..services.ceph_service import CephService
10from .. import mgr
11
12
13@ApiController('/crush_rule', Scope.POOL)
14class CrushRule(RESTController):
15 def list(self):
16 return mgr.get('osd_map_crush')['rules']
17
18 def get(self, name):
19 rules = mgr.get('osd_map_crush')['rules']
20 for r in rules:
21 if r['rule_name'] == name:
22 return r
23 raise NotFound('No such crush rule')
24
25 def create(self, name, root, failure_domain, device_class=None):
26 rule = {
27 'name': name,
28 'root': root,
29 'type': failure_domain,
30 'class': device_class
31 }
32 CephService.send_command('mon', 'osd crush rule create-replicated', **rule)
33
34 def delete(self, name):
35 CephService.send_command('mon', 'osd crush rule rm', name=name)
36
37
38@UiApiController('/crush_rule', Scope.POOL)
f6b5b4d7 39@ControllerDoc("Dashboard UI helper function; not part of the public API", "CrushRuleUi")
9f95a23c
TL
40class CrushRuleUi(CrushRule):
41 @Endpoint()
42 @ReadPermission
43 def info(self):
44 '''Used for crush rule creation modal'''
45 return {
46 'names': [r['rule_name'] for r in mgr.get('osd_map_crush')['rules']],
47 'nodes': mgr.get('osd_map_tree')['nodes']
48 }