]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/controllers/crush_rule.py
Import ceph 15.2.8
[ceph.git] / ceph / src / pybind / mgr / dashboard / controllers / crush_rule.py
1 # -*- coding: utf-8 -*-
2 from __future__ import absolute_import
3
4 from cherrypy import NotFound
5
6 from . import ApiController, ControllerDoc, RESTController, Endpoint, ReadPermission, \
7 UiApiController
8 from ..security import Scope
9 from ..services.ceph_service import CephService
10 from .. import mgr
11
12
13 @ApiController('/crush_rule', Scope.POOL)
14 class 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)
39 @ControllerDoc("Dashboard UI helper function; not part of the public API", "CrushRuleUi")
40 class 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 }