]>
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 @RESTController.Collection('GET', query_params
=['name'])
42 def filter(self
, names
=None):
46 for name
in names
.split(','):
48 config_options
.append(self
._get
_config
_option
(name
))
49 except cherrypy
.HTTPError
:
52 if not config_options
:
53 raise cherrypy
.HTTPError(404, 'Config options `{}` not found'.format(names
))
57 def create(self
, name
, value
):
58 # Check if config option is updateable at runtime
59 self
._updateable
_at
_runtime
([name
])
61 # Update config option
62 avail_sections
= ['global', 'mon', 'mgr', 'osd', 'mds', 'client']
64 for section
in avail_sections
:
66 if entry
['value'] is None:
69 if entry
['section'] == section
:
70 CephService
.send_command('mon', 'config set', who
=section
, name
=name
,
71 value
=str(entry
['value']))
74 CephService
.send_command('mon', 'config rm', who
=section
, name
=name
)
76 def delete(self
, name
, section
):
77 return CephService
.send_command('mon', 'config rm', who
=section
, name
=name
)
79 def bulk_set(self
, options
):
80 self
._updateable
_at
_runtime
(options
.keys())
82 for name
, value
in options
.items():
83 CephService
.send_command('mon', 'config set', who
=value
['section'],
84 name
=name
, value
=str(value
['value']))
86 def _get_config_option(self
, name
):
87 for option
in mgr
.get('config_options')['options']:
88 if option
['name'] == name
:
89 return self
._append
_config
_option
_values
([option
])[0]
91 raise cherrypy
.HTTPError(404)
93 def _updateable_at_runtime(self
, config_option_names
):
96 for name
in config_option_names
:
97 config_option
= self
._get
_config
_option
(name
)
98 if not config_option
['can_update_at_runtime']:
99 not_updateable
.append(name
)
102 raise DashboardException(
103 msg
='Config option {} is/are not updatable at runtime'.format(
104 ', '.join(not_updateable
)),
105 code
='config_option_not_updatable_at_runtime',
106 component
='cluster_configuration')