]>
Commit | Line | Data |
---|---|---|
31f18b77 FG |
1 | from pecan import expose, request |
2 | from pecan.rest import RestController | |
3 | ||
11fdf7f2 | 4 | from restful import common, context |
31f18b77 FG |
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 | """ | |
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 | ||
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 | """ | |
11fdf7f2 | 64 | return context.instance.get("config").get(self.key, None) |
31f18b77 FG |
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 | """ | |
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 | ||
84 | class Config(RestController): | |
85 | cluster = ConfigCluster() | |
86 | osd = ConfigOsd() |