From: John Mulligan Date: Tue, 10 Mar 2026 13:44:44 +0000 (-0400) Subject: mgr/cephadm: add a new Action enum class X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=989dc2229e7ebacab58baa535cb2c1ac262e050b;p=ceph.git mgr/cephadm: add a new Action enum class Currently, the code base mostly uses strings to represent actions (like 'start', 'redeploy, 'reconfig', ...). Add a new Action class to utils.py to have a crisper typing-friendly representation for actions. This is added to support net new code. While I'd like to see this used more the goal is to prevent errors in the new approach and I don't plan on immediately going back through all of cephadm and finding and replacing all action strings right away. Signed-off-by: John Mulligan --- diff --git a/src/pybind/mgr/cephadm/utils.py b/src/pybind/mgr/cephadm/utils.py index 805ca953e918..d6e063e20e52 100644 --- a/src/pybind/mgr/cephadm/utils.py +++ b/src/pybind/mgr/cephadm/utils.py @@ -3,7 +3,17 @@ import json import socket from enum import Enum from functools import wraps -from typing import Optional, Callable, TypeVar, List, NewType, TYPE_CHECKING, Any, NamedTuple +from typing import ( + Any, + Callable, + List, + NamedTuple, + NewType, + Optional, + TYPE_CHECKING, + TypeVar, + Union, +) from orchestrator import OrchestratorError import hashlib @@ -63,6 +73,25 @@ class SpecialHostLabels(str, Enum): return self.value +class Action(str, Enum): + NO_ACTION = '' + RECONFIG = 'reconfig' + REDEPLOY = 'redeploy' + RESTART = 'restart' + ROTATE_KEY = 'rotate-key' + START = 'start' + STOP = 'stop' + + @classmethod + def create(cls, action: Union[str, 'Action', None]) -> 'Action': + if not action: + return cls.NO_ACTION + return cls(action) + + def __str__(self) -> str: + return self.value + + def name_to_config_section(name: str) -> ConfEntity: """ Map from daemon names to ceph entity names (as seen in config)