]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/restful/api/config.py
import 15.2.4
[ceph.git] / ceph / src / pybind / mgr / restful / api / config.py
CommitLineData
31f18b77
FG
1from pecan import expose, request
2from pecan.rest import RestController
3
11fdf7f2 4from restful import common, context
31f18b77
FG
5from restful.decorators import auth
6
7
8class ConfigOsd(RestController):
9 @expose(template='json')
10 @auth
11 def get(self, **kwargs):
12 """
13 Show OSD configuration options
14 """
11fdf7f2 15 flags = context.instance.get("osd_map")['flags']
31f18b77
FG
16
17 # pause is a valid osd config command that sets pauserd,pausewr
18 flags = flags.replace('pauserd,pausewr', 'pause')
19
20 return flags.split(',')
21
22
23 @expose(template='json')
24 @auth
25 def patch(self, **kwargs):
26 """
11fdf7f2 27 Modify OSD configuration options
31f18b77
FG
28 """
29 args = request.json
30
31 commands = []
32
33 valid_flags = set(args.keys()) & set(common.OSD_FLAGS)
34 invalid_flags = list(set(args.keys()) - valid_flags)
35 if invalid_flags:
e306af50 36 context.instance.log.warning("%s not valid to set/unset", invalid_flags)
31f18b77
FG
37
38 for flag in list(valid_flags):
39 if args[flag]:
40 mode = 'set'
41 else:
42 mode = 'unset'
43
44 commands.append({
45 'prefix': 'osd ' + mode,
46 'key': flag,
47 })
48
11fdf7f2 49 return context.instance.submit_request([commands], **kwargs)
31f18b77
FG
50
51
52
53class ConfigClusterKey(RestController):
54 def __init__(self, key):
55 self.key = key
56
57
58 @expose(template='json')
59 @auth
60 def get(self, **kwargs):
61 """
62 Show specific configuration option
63 """
11fdf7f2 64 return context.instance.get("config").get(self.key, None)
31f18b77
FG
65
66
67
68class ConfigCluster(RestController):
69 @expose(template='json')
70 @auth
71 def get(self, **kwargs):
72 """
73 Show all cluster configuration options
74 """
11fdf7f2 75 return context.instance.get("config")
31f18b77
FG
76
77
78 @expose()
79 def _lookup(self, key, *remainder):
80 return ConfigClusterKey(key), remainder
81
82
83
84class Config(RestController):
85 cluster = ConfigCluster()
86 osd = ConfigOsd()