]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: add a new Action enum class
authorJohn Mulligan <jmulligan@redhat.com>
Tue, 10 Mar 2026 13:44:44 +0000 (09:44 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 26 Mar 2026 13:31:38 +0000 (09:31 -0400)
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 <jmulligan@redhat.com>
src/pybind/mgr/cephadm/utils.py

index 805ca953e918bd5796a76612745035c2a1f2c866..d6e063e20e52c6b942369bfcc0976dc0572a3804 100644 (file)
@@ -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)