]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: add a custom warning message when enabling feature 60749/head
authorNizamudeen A <nia@redhat.com>
Fri, 15 Nov 2024 07:20:07 +0000 (12:50 +0530)
committerNizamudeen A <nia@redhat.com>
Wed, 11 Dec 2024 06:31:15 +0000 (12:01 +0530)
would be helpful if we want to notify user about certain issues when
enabling something.

```
[root@ceph ceph]# ceph dashboard feature enable iscsi

WARNING: iscsi warning message
Feature 'iscsi': enabled
```

Fixes: https://tracker.ceph.com/issues/68969
Signed-off-by: Nizamudeen A <nia@redhat.com>
src/pybind/mgr/dashboard/plugins/feature_toggles.py
src/pybind/mgr/mgr_util.py

index f16b2e68c4d692c3b06f7d97d97105251ebd2de8..63b1d762c3417b1421dcfab150b4c381bd9af585 100644 (file)
@@ -1,10 +1,11 @@
 # -*- coding: utf-8 -*-
 
 from enum import Enum
-from typing import List, Optional, Set, no_type_check
+from typing import Dict, List, Optional, Set, no_type_check
 
 import cherrypy
 from mgr_module import CLICommand, Option
+from mgr_util import CLIWarning
 
 from ..controllers.cephfs import CephFS
 from ..controllers.iscsi import Iscsi, IscsiTarget
@@ -27,6 +28,14 @@ class Features(Enum):
     NFS = 'nfs'
     DASHBOARD = 'dashboard'
 
+    # if we want to add any custom warning message when enabling a feature
+    # we can add it here as key-value pair in warn_msg.
+    # eg: Features.ISCSI.value: 'iscsi warning message'
+    @property
+    def warning(self):
+        warn_msg: Dict[str, str] = {}
+        return warn_msg.get(self.value, None)
+
 
 PREDISABLED_FEATURES = set()  # type: Set[str]
 
@@ -91,6 +100,8 @@ class FeatureToggles(I.CanMgr, I.Setupable, I.HasOptions,
                         mgr.set_module_option(
                             self.OPTION_FMT.format(feature),
                             action == Actions.ENABLE)
+                        if action == Actions.ENABLE and feature.warning:
+                            msg += [CLIWarning(feature.warning)]
                         msg += ["Feature '{.value}': {}".format(
                             feature,
                             'enabled' if action == Actions.ENABLE else
index 5d37d478de7b1ed7b89d8769b3009612321a130d..162946f998dfcca3e5ff84b2bb9d5bd1f1c0a4ab 100644 (file)
@@ -67,6 +67,13 @@ class PortAlreadyInUse(Exception):
     pass
 
 
+# helper function for showing a warning text in
+# the terminal
+class CLIWarning(str):
+    def __new__(cls, content: str) -> "CLIWarning":
+        return super().__new__(cls, f"WARNING: {content}")
+
+
 class CephfsConnectionException(Exception):
     def __init__(self, error_code: int, error_message: str):
         self.errno = error_code