]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard: disallow editing read-only config options
authorTatjana Dehler <tdehler@suse.com>
Wed, 6 Feb 2019 15:32:23 +0000 (16:32 +0100)
committerTatjana Dehler <tdehler@suse.com>
Wed, 13 Feb 2019 15:39:40 +0000 (16:39 +0100)
Fixes: https://tracker.ceph.com/issues/34528
Signed-off-by: Tatjana Dehler <tdehler@suse.com>
src/pybind/mgr/dashboard/controllers/cluster_configuration.py
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration-details/configuration-details.component.html
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/configuration/configuration.component.ts
src/pybind/mgr/dashboard/frontend/src/locale/messages.xlf

index 2d93b51ea4f13ed5add36b0e79b59e9f8c6883ed..d6314024444c78a6c48c67b5b0a7c94e12573f65 100644 (file)
@@ -7,6 +7,7 @@ from . import ApiController, RESTController
 from .. import mgr
 from ..security import Scope
 from ..services.ceph_service import CephService
+from ..exceptions import DashboardException
 
 
 @ApiController('/cluster_conf', Scope.CONFIG_OPT)
@@ -31,17 +32,22 @@ class ClusterConfiguration(RESTController):
         return options
 
     def list(self):
-        options = mgr.get("config_options")['options']
+        options = mgr.get('config_options')['options']
         return self._append_config_option_values(options)
 
     def get(self, name):
-        for option in mgr.get('config_options')['options']:
-            if option['name'] == name:
-                return self._append_config_option_values([option])[0]
-
-        raise cherrypy.HTTPError(404)
+        return self._get_config_option(name)
 
     def create(self, name, value):
+        # Check if config option is updateable at runtime
+        config_option = self._get_config_option(name)
+        if not config_option['can_update_at_runtime']:
+            raise DashboardException(
+                msg='Config option {} is not updatable at runtime'.format(name),
+                code='config_option_not_updatable_at_runtime',
+                component='cluster_configuration')
+
+        # Update config option
         availSections = ['global', 'mon', 'mgr', 'osd', 'mds', 'client']
 
         for section in availSections:
@@ -60,3 +66,10 @@ class ClusterConfiguration(RESTController):
         for name, value in options.items():
             CephService.send_command('mon', 'config set', who=value['section'],
                                      name=name, value=str(value['value']))
+
+    def _get_config_option(self, name):
+        for option in mgr.get('config_options')['options']:
+            if option['name'] == name:
+                return self._append_config_option_values([option])[0]
+
+        raise cherrypy.HTTPError(404)
index 35e47e0d610f006ed987f60c3b3648896fcd051e..b8d6037ca0007f611aad0c5fd17baa52ab7eeed6 100755 (executable)
@@ -84,7 +84,7 @@
         </tr>
         <tr>
           <td i18n
-              class="bold col-sm-1">Can be updated at runtime</td>
+              class="bold col-sm-1">Can be updated at runtime (editable)</td>
           <td class="col-sm-3">{{ selectedItem.can_update_at_runtime }}</td>
         </tr>
         <tr>
index 9c056bcb602f418521170fe2d50c8a6b043f1955..f7b7787a29bc4630733a561728df5f06eb3af8df 100644 (file)
@@ -3,6 +3,7 @@ import { Component, OnInit, TemplateRef, ViewChild } from '@angular/core';
 import { I18n } from '@ngx-translate/i18n-polyfill';
 
 import { ConfigurationService } from '../../../shared/api/configuration.service';
+import { CellTemplate } from '../../../shared/enum/cell-template.enum';
 import { CdTableAction } from '../../../shared/models/cd-table-action';
 import { CdTableColumn } from '../../../shared/models/cd-table-column';
 import { CdTableFetchDataContext } from '../../../shared/models/cd-table-fetch-data-context';
@@ -91,7 +92,8 @@ export class ConfigurationComponent implements OnInit {
       permission: 'update',
       icon: 'fa-pencil',
       routerLink: () => `/configuration/edit/${getConfigOptUri()}`,
-      name: this.i18n('Edit')
+      name: this.i18n('Edit'),
+      disable: () => !this.isEditable(this.selection)
     };
     this.tableActions = [editAction];
   }
@@ -106,7 +108,14 @@ export class ConfigurationComponent implements OnInit {
         cellClass: 'wrap',
         cellTemplate: this.confValTpl
       },
-      { prop: 'default', name: this.i18n('Default'), cellClass: 'wrap' }
+      { prop: 'default', name: this.i18n('Default'), cellClass: 'wrap' },
+      {
+        prop: 'can_update_at_runtime',
+        name: this.i18n('Editable'),
+        cellTransformation: CellTemplate.checkIcon,
+        flexGrow: 0.4,
+        cellClass: 'text-center'
+      }
     ];
   }
 
@@ -135,4 +144,12 @@ export class ConfigurationComponent implements OnInit {
     });
     this.data = [...this.data];
   }
+
+  isEditable(selection: CdTableSelection): boolean {
+    if (selection.selected.length !== 1) {
+      return false;
+    }
+
+    return selection.selected[0].can_update_at_runtime;
+  }
 }
index c3c1ad3115d87d5477dad70fa6ff0c6e1ae4b620..d0d30e7049460bf24c668c4d38fa25d57b9021ec 100644 (file)
           <context context-type="sourcefile">app/ceph/cluster/configuration/configuration-details/configuration-details.component.html</context>
           <context context-type="linenumber">82</context>
         </context-group>
-      </trans-unit><trans-unit id="4180e8c1a344da14bdef061df596a4457bbb8d6c" datatype="html">
-        <source>Can be updated at runtime</source>
+      </trans-unit><trans-unit id="39f2fb094e9b2eda13163fa3f3a31594cf9c1307" datatype="html">
+        <source>Can be updated at runtime (editable)</source>
         <context-group purpose="location">
           <context context-type="sourcefile">app/ceph/cluster/configuration/configuration-details/configuration-details.component.html</context>
           <context context-type="linenumber">87</context>
           <context context-type="linenumber">1</context>
         </context-group>
       </trans-unit>
+      <trans-unit id="4a01c175f90dd92b432f4a4a199d2c7bb9d997ff" datatype="html">
+        <source>Editable</source>
+        <context-group purpose="location">
+          <context context-type="sourcefile">src/app/ceph/cluster/configuration/configuration.component.ts</context>
+          <context context-type="linenumber">1</context>
+        </context-group>
+      </trans-unit>
       <trans-unit id="7099a8878af7a0a26fe5663c4f46cfe87142b75d" datatype="html">
         <source>Public Address</source>
         <context-group purpose="location">