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