mirror of
https://github.com/ceph/ceph
synced 2025-04-01 00:26:47 +00:00
mgr/dashboard: Added instructions on how to add config settings to HACKING
Signed-off-by: Ricardo Dias <rdias@suse.com>
This commit is contained in:
parent
f681b23280
commit
17cfac2b68
@ -463,3 +463,48 @@ The unit test code will look like the following::
|
||||
rbd_list_mock.return_value = ['img1', 'img2']
|
||||
self._get('/api/rbdimages')
|
||||
self.assertJsonBody([{'name': 'img1'}, {'name': 'img2'}])
|
||||
|
||||
|
||||
|
||||
How to add a new configuration setting?
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
If you need to store some configuration setting for a new feature, we already
|
||||
provide an easy mechanism for you to specify/use the new config setting.
|
||||
|
||||
For instance, if you want to add a new configuration setting to hold the
|
||||
email address of the dashboard admin, just add a setting name as a class
|
||||
attribute to the ``Options`` class in the ``settings.py`` file::
|
||||
|
||||
# ...
|
||||
class Options(object):
|
||||
# ...
|
||||
|
||||
ADMIN_EMAIL_ADDRESS = ('admin@admin.com', str)
|
||||
|
||||
The value of the class attribute is a pair composed by the default value for that
|
||||
setting, and the python type of the value.
|
||||
|
||||
By declaring the ``ADMIN_EMAIL_ADDRESS`` class attribute, when you restart the
|
||||
dashboard plugin, you will atomatically gain two additional CLI commands to
|
||||
get and set that setting::
|
||||
|
||||
$ ceph dashboard get-admin-email-address
|
||||
$ ceph dashboard set-admin-email-address <value>
|
||||
|
||||
To access, or modify the config setting value from your Python code, either
|
||||
inside a controller or anywhere else, you just need to import the ``Settings``
|
||||
class and access it like this::
|
||||
|
||||
from settings import Settings
|
||||
|
||||
# ...
|
||||
tmp_var = Settings.ADMIN_EMAIL_ADDRESS
|
||||
|
||||
# ....
|
||||
Settings.ADMIN_EMAIL_ADDRESS = 'myemail@admin.com'
|
||||
|
||||
The settings management implementation will make sure that if you change a
|
||||
setting value from the Python code you will see that change when accessing
|
||||
that setting from the CLI and vice-versa.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user