]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/controllers/cluster_configuration.py
1 # -*- coding: utf-8 -*-
2 from __future__
import absolute_import
6 from . import ApiController
, RESTController
8 from ..security
import Scope
9 from ..services
.ceph_service
import CephService
10 from ..exceptions
import DashboardException
13 @ApiController('/cluster_conf', Scope
.CONFIG_OPT
)
14 class ClusterConfiguration(RESTController
):
16 def _append_config_option_values(self
, options
):
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
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'
30 options
[i
]['value'].append({'section': config_dump_entry
['section'],
31 'value': config_dump_entry
['value']})
35 options
= mgr
.get('config_options')['options']
36 return self
._append
_config
_option
_values
(options
)
39 return self
._get
_config
_option
(name
)
41 def create(self
, name
, value
):
42 # Check if config option is updateable at runtime
43 self
._updateable
_at
_runtime
([name
])
45 # Update config option
46 availSections
= ['global', 'mon', 'mgr', 'osd', 'mds', 'client']
48 for section
in availSections
:
50 if not entry
['value']:
53 if entry
['section'] == section
:
54 CephService
.send_command('mon', 'config set', who
=section
, name
=name
,
55 value
=str(entry
['value']))
58 CephService
.send_command('mon', 'config rm', who
=section
, name
=name
)
60 def bulk_set(self
, options
):
61 self
._updateable
_at
_runtime
(options
.keys())
63 for name
, value
in options
.items():
64 CephService
.send_command('mon', 'config set', who
=value
['section'],
65 name
=name
, value
=str(value
['value']))
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]
72 raise cherrypy
.HTTPError(404)
74 def _updateable_at_runtime(self
, config_option_names
):
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
)
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')