]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Added instructions on how to add config settings to HACKING 20743/head
authorRicardo Dias <rdias@suse.com>
Tue, 30 Jan 2018 10:13:55 +0000 (10:13 +0000)
committerRicardo Dias <rdias@suse.com>
Wed, 7 Mar 2018 16:29:55 +0000 (16:29 +0000)
Signed-off-by: Ricardo Dias <rdias@suse.com>
src/pybind/mgr/dashboard_v2/HACKING.rst

index 498c83c99b9cb2d95567528576555f4c8ee92672..610e117ba12bce1a97c973c1d0ecac7f0ae00790 100644 (file)
@@ -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.
+