Skip to content

Commit 15e7c89

Browse files
authored
Merge pull request ceph#60749 from rhcs-dashboard/warn_feature_toggle
mgr/dashboard: add a custom warning message when enabling feature Reviewed-by: Afreen Misbah <[email protected]>
2 parents 00bae68 + 14855b3 commit 15e7c89

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/pybind/mgr/dashboard/plugins/feature_toggles.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# -*- coding: utf-8 -*-
22

33
from enum import Enum
4-
from typing import List, Optional, Set, no_type_check
4+
from typing import Dict, List, Optional, Set, no_type_check
55

66
import cherrypy
77
from mgr_module import CLICommand, Option
8+
from mgr_util import CLIWarning
89

910
from ..controllers.cephfs import CephFS
1011
from ..controllers.iscsi import Iscsi, IscsiTarget
@@ -27,6 +28,14 @@ class Features(Enum):
2728
NFS = 'nfs'
2829
DASHBOARD = 'dashboard'
2930

31+
# if we want to add any custom warning message when enabling a feature
32+
# we can add it here as key-value pair in warn_msg.
33+
# eg: Features.ISCSI.value: 'iscsi warning message'
34+
@property
35+
def warning(self):
36+
warn_msg: Dict[str, str] = {}
37+
return warn_msg.get(self.value, None)
38+
3039

3140
PREDISABLED_FEATURES = set() # type: Set[str]
3241

@@ -91,6 +100,8 @@ def cmd(mgr,
91100
mgr.set_module_option(
92101
self.OPTION_FMT.format(feature),
93102
action == Actions.ENABLE)
103+
if action == Actions.ENABLE and feature.warning:
104+
msg += [CLIWarning(feature.warning)]
94105
msg += ["Feature '{.value}': {}".format(
95106
feature,
96107
'enabled' if action == Actions.ENABLE else

src/pybind/mgr/mgr_util.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ class PortAlreadyInUse(Exception):
6767
pass
6868

6969

70+
# helper function for showing a warning text in
71+
# the terminal
72+
class CLIWarning(str):
73+
def __new__(cls, content: str) -> "CLIWarning":
74+
return super().__new__(cls, f"WARNING: {content}")
75+
76+
7077
class CephfsConnectionException(Exception):
7178
def __init__(self, error_code: int, error_message: str):
7279
self.errno = error_code

0 commit comments

Comments
 (0)