Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / pybind / mgr / restful / api / config.py
1 from pecan import expose, request
2 from pecan.rest import RestController
3
4 from restful import common, module
5 from restful.decorators import auth
6
7
8 class ConfigOsd(RestController):
9     @expose(template='json')
10     @auth
11     def get(self, **kwargs):
12         """
13         Show OSD configuration options
14         """
15         flags = module.instance.get("osd_map")['flags']
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         """
27         Modify OSD configration options
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:
36             module.instance.log.warn("%s not valid to set/unset" % invalid_flags)
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
49         return module.instance.submit_request([commands], **kwargs)
50
51
52
53 class 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         """
64         return module.instance.get("config").get(self.key, None)
65
66
67
68 class ConfigCluster(RestController):
69     @expose(template='json')
70     @auth
71     def get(self, **kwargs):
72         """
73         Show all cluster configuration options
74         """
75         return module.instance.get("config")
76
77
78     @expose()
79     def _lookup(self, key, *remainder):
80         return ConfigClusterKey(key), remainder
81
82
83
84 class Config(RestController):
85     cluster = ConfigCluster()
86     osd = ConfigOsd()