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