]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/controllers/crush_rule.py
import ceph 16.2.7
[ceph.git] / ceph / src / pybind / mgr / dashboard / controllers / crush_rule.py
1
2 # -*- coding: utf-8 -*-
3 from __future__ import absolute_import
4
5 from cherrypy import NotFound
6
7 from .. import mgr
8 from ..security import Scope
9 from ..services.ceph_service import CephService
10 from . import APIDoc, APIRouter, Endpoint, EndpointDoc, ReadPermission, RESTController, UIRouter
11
12 LIST_SCHEMA = {
13 "rule_id": (int, 'Rule ID'),
14 "rule_name": (str, 'Rule Name'),
15 "ruleset": (int, 'RuleSet related to the rule'),
16 "type": (int, 'Type of Rule'),
17 "min_size": (int, 'Minimum size of Rule'),
18 "max_size": (int, 'Maximum size of Rule'),
19 'steps': ([{str}], 'Steps included in the rule')
20 }
21
22
23 @APIRouter('/crush_rule', Scope.POOL)
24 @APIDoc("Crush Rule Management API", "CrushRule")
25 class CrushRule(RESTController):
26 @EndpointDoc("List Crush Rule Configuration",
27 responses={200: LIST_SCHEMA})
28 def list(self):
29 return mgr.get('osd_map_crush')['rules']
30
31 def get(self, name):
32 rules = mgr.get('osd_map_crush')['rules']
33 for r in rules:
34 if r['rule_name'] == name:
35 return r
36 raise NotFound('No such crush rule')
37
38 def create(self, name, root, failure_domain, device_class=None):
39 rule = {
40 'name': name,
41 'root': root,
42 'type': failure_domain,
43 'class': device_class
44 }
45 CephService.send_command('mon', 'osd crush rule create-replicated', **rule)
46
47 def delete(self, name):
48 CephService.send_command('mon', 'osd crush rule rm', name=name)
49
50
51 @UIRouter('/crush_rule', Scope.POOL)
52 @APIDoc("Dashboard UI helper function; not part of the public API", "CrushRuleUi")
53 class CrushRuleUi(CrushRule):
54 @Endpoint()
55 @ReadPermission
56 def info(self):
57 '''Used for crush rule creation modal'''
58 osd_map = mgr.get_osdmap()
59 crush = osd_map.get_crush()
60 crush.dump()
61 return {
62 'names': [r['rule_name'] for r in mgr.get('osd_map_crush')['rules']],
63 'nodes': mgr.get('osd_map_tree')['nodes'],
64 'roots': crush.find_roots()
65 }