From: Nizamudeen A Date: Fri, 15 Nov 2024 07:20:07 +0000 (+0530) Subject: mgr/dashboard: add a custom warning message when enabling feature X-Git-Tag: v20.0.0~560^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=14855b306c4e9fdb837c46f1d8d68f43cc9b07e1;p=ceph.git mgr/dashboard: add a custom warning message when enabling feature 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 --- diff --git a/src/pybind/mgr/dashboard/plugins/feature_toggles.py b/src/pybind/mgr/dashboard/plugins/feature_toggles.py index f16b2e68c4d69..63b1d762c3417 100644 --- a/src/pybind/mgr/dashboard/plugins/feature_toggles.py +++ b/src/pybind/mgr/dashboard/plugins/feature_toggles.py @@ -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 diff --git a/src/pybind/mgr/mgr_util.py b/src/pybind/mgr/mgr_util.py index 5d37d478de7b1..162946f998dfc 100644 --- a/src/pybind/mgr/mgr_util.py +++ b/src/pybind/mgr/mgr_util.py @@ -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