From 4bb983724a2782d654979b8020f1684daa52fae5 Mon Sep 17 00:00:00 2001 From: Nizamudeen A Date: Fri, 15 Nov 2024 12:50:07 +0530 Subject: [PATCH] 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 (cherry picked from commit 14855b306c4e9fdb837c46f1d8d68f43cc9b07e1) --- src/pybind/mgr/dashboard/plugins/feature_toggles.py | 13 ++++++++++++- src/pybind/mgr/mgr_util.py | 7 +++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/dashboard/plugins/feature_toggles.py b/src/pybind/mgr/dashboard/plugins/feature_toggles.py index f16b2e68c4d..63b1d762c34 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 05ec6496682..8d71dd69128 100644 --- a/src/pybind/mgr/mgr_util.py +++ b/src/pybind/mgr/mgr_util.py @@ -59,6 +59,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 -- 2.39.5