]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/controllers/cluster_configuration.py
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / controllers / cluster_configuration.py
1 # -*- coding: utf-8 -*-
2 from __future__ import absolute_import
3
4 import cherrypy
5
6 from . import ApiController, RESTController
7 from .. import mgr
8 from ..security import Scope
9 from ..services.ceph_service import CephService
10 from ..exceptions import DashboardException
11
12
13 @ApiController('/cluster_conf', Scope.CONFIG_OPT)
14 class ClusterConfiguration(RESTController):
15
16 def _append_config_option_values(self, options):
17 """
18 Appends values from the config database (if available) to the given options
19 :param options: list of config options
20 :return: list of config options extended by their current values
21 """
22 config_dump = CephService.send_command('mon', 'config dump')
23 for config_dump_entry in config_dump:
24 for i, elem in enumerate(options):
25 if config_dump_entry['name'] == elem['name']:
26 if 'value' not in elem:
27 options[i]['value'] = []
28 options[i]['source'] = 'mon'
29
30 options[i]['value'].append({'section': config_dump_entry['section'],
31 'value': config_dump_entry['value']})
32 return options
33
34 def list(self):
35 options = mgr.get('config_options')['options']
36 return self._append_config_option_values(options)
37
38 def get(self, name):
39 return self._get_config_option(name)
40
41 def create(self, name, value):
42 # Check if config option is updateable at runtime
43 self._updateable_at_runtime([name])
44
45 # Update config option
46 availSections = ['global', 'mon', 'mgr', 'osd', 'mds', 'client']
47
48 for section in availSections:
49 for entry in value:
50 if not entry['value']:
51 break
52
53 if entry['section'] == section:
54 CephService.send_command('mon', 'config set', who=section, name=name,
55 value=str(entry['value']))
56 break
57 else:
58 CephService.send_command('mon', 'config rm', who=section, name=name)
59
60 def bulk_set(self, options):
61 self._updateable_at_runtime(options.keys())
62
63 for name, value in options.items():
64 CephService.send_command('mon', 'config set', who=value['section'],
65 name=name, value=str(value['value']))
66
67 def _get_config_option(self, name):
68 for option in mgr.get('config_options')['options']:
69 if option['name'] == name:
70 return self._append_config_option_values([option])[0]
71
72 raise cherrypy.HTTPError(404)
73
74 def _updateable_at_runtime(self, config_option_names):
75 not_updateable = []
76
77 for name in config_option_names:
78 config_option = self._get_config_option(name)
79 if not config_option['can_update_at_runtime']:
80 not_updateable.append(name)
81
82 if not_updateable:
83 raise DashboardException(
84 msg='Config option {} is/are not updatable at runtime'.format(
85 ', '.join(not_updateable)),
86 code='config_option_not_updatable_at_runtime',
87 component='cluster_configuration')